kleisli
kleisli copied to clipboard
Add #success? and #failure? to Either, Try, and Maybe
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.