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

Skip to content

Conversation

@Fristi
Copy link
Contributor

@Fristi Fristi commented Apr 19, 2020

I had some functions already which were doing this already, would be nice if we can lift these boxes inside a ZIO effect without too much folding and such :)

@adamgfraser
Copy link
Contributor

Thanks for contributing!

I think several of these are very similar to existing combinators. In particular:

  • fromEitherM(v) <-> v.absolve
  • ofEither(v, ifLeft) <-> fromEither(v).mapError(ifLeft)
  • ofEitherM(v, ifLeft) <-> v.flatMap(fromEither(_).mapError(ifLeft))
  • ofOption(v, ifEmpty) <-> fromOption(v).orElseFail(ifEmpty)
  • ofOptionM(v, ifEmpty) <-> v.someOrFail(ifEmpty)

I think most of these are pretty straightforward and at most take two method calls when you essentially want to do two things: lifting a value into an effect an transform the error value. The one that is not quite as nice is the replacement for your ofEitherM method. rightOrFail almost does what we need but not quite because it just lets us specify a new error value and not transform the existing error value. Maybe we add a rightOrFailWith variant for that?

@adamgfraser
Copy link
Contributor

@Fristi Are you interested in working on the leftOrFailWith and rightOrFailWith variants?

@Fristi
Copy link
Contributor Author

Fristi commented Jun 3, 2020

Yes, let's see if I can squeeze some time on it this week

@adamgfraser
Copy link
Contributor

Sounds good. Let me know if there is anything I can do to help.

@Fristi Fristi force-pushed the add-from-either-option branch from 38c321b to cb28a66 Compare June 8, 2020 10:48
@Fristi Fristi changed the title Add fromEitherM, ofEither, ofEitherM, ofOption and ofOptionM Add rightOrFaiWith and leftOrFailWith and error transform docs Jun 8, 2020
@Fristi
Copy link
Contributor Author

Fristi commented Jun 8, 2020

I added those combinators and some helpful documentation I think :) Let me know what you think

@Fristi Fristi changed the title Add rightOrFaiWith and leftOrFailWith and error transform docs Add rightOrFailWith and leftOrFailWith and error transform docs Jun 8, 2020
Copy link
Contributor

@adamgfraser adamgfraser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for adding!

@Fristi
Copy link
Contributor Author

Fristi commented Jun 11, 2020

Great! Looking forward to have it in the next release

@adamgfraser adamgfraser merged commit 291aba8 into zio:master Jun 15, 2020
@adamgfraser
Copy link
Contributor

@Fristi Thanks for your contribution on this!

@Fristi Fristi deleted the add-from-either-option branch June 15, 2020 14:12
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.

2 participants