kleisli icon indicating copy to clipboard operation
kleisli copied to clipboard

Add #success? and #failure? to Either, Try, and Maybe

Open dropofwill opened this issue 7 years ago • 0 comments

My use case was aggregating a bunch of API calls that came back as an array of Lefts and Rights, and I wanted to explicitly deal with both. Using #is_a? Left works, but these helper methods make the code read better. If there is a more idiomatic/monadic way to handle this case I'm interested to hear it.

For example:

lefts, rights = [Right(20), Left('10 is too small'), Right(11)].partition(&:failure?)

I added them to Try and Maybe as well for consistency.

dropofwill avatar Nov 08 '16 20:11 dropofwill