Operators::Service - a lightweight implementation of Service Object based on Either Monad

Service Object based on Either Monad

I can see myself using the Either monad in Haskell, because you can pattern match and thereby ease the reading of the code with it. In Ruby however, we don’t have pattern matching, so I feel this is a bit forced. Are you using it in some more advanced cases than the example on the Github page?

I’ll use monads in ruby sometimes. maps and binds aren’t a bad fit for ruby with blocks.

  .map { |good| do_something(good} }
  .and_then { |good| do_something_else_that_may_fail(good) }
  .or_else { |bad| handle_error(bad) }
  .with_default("I'm returned if things go bad")

Particularly with a Result / Either monad, it allows you to convey more about why a computation isn’t returning a value then just a nil might.

1 Like