Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@vladimirkl
Copy link
Contributor

This PR adds new someOrElseM method to ZIO, ZManaged and ZSTM - similar to someOrElse but with effect as default. I found this helper quite useful when working with some / asSomeError / optional combinators. Of course this can be achieved with flatMap doing pattern matching or folding, but new helper looks cleaner.

@vladimirkl vladimirkl force-pushed the zio-some-or-else-m branch from 77be8a2 to 9207f35 Compare June 21, 2020 08:16
@ghostdogpr
Copy link
Member

Can't you do .some orElse already?

@vladimirkl
Copy link
Contributor Author

Unfortunately some.orElse won't help because it runs orElse effect either on None value or error. someOrElseM is similar to someOrElse - so it runs default effect only is value is None and doesn't hide error.

For example, given the following effects:
def f1: IO[String, Option[String]] = IO.fail("err1")
def f2: IO[String, String] = IO.succeed("val1")

f1.some.orElse(f2) will return "val1" but f1.someOrElseM(f2) will fail with "err1".

@ghostdogpr
Copy link
Member

You’re right 👍

@vladimirkl
Copy link
Contributor Author

@ghostdogpr Would you mind to approve this PR? Some CI checks still fail but this is not related to PR.

@ghostdogpr
Copy link
Member

Can you rebase to the latest master? I believe the flaky tests have been fixed. Thanks!

@vladimirkl vladimirkl force-pushed the zio-some-or-else-m branch from 9207f35 to 2428857 Compare June 27, 2020 13:48
@adamgfraser adamgfraser merged commit 9eb11e4 into zio:master Jun 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants