String representation for Maybe monad

Currently, Dry::Monads::Maybe's #to_s returns whether Some ("the value") or None.

This makes things complicated when you want to render it through a template system like tilt.

What do you think about implementing one of the two following options?

  • Doing something different for #to_s and #inspect. Make #to_s work like a template system would expect (returning "the value" or ""), and keep #inspect as it is now.
  • Provide another method #render, or something like that, so that it can be used in decorators for view systems.

Normally, serialization is not a library concern. We have a monkey patch for JSON serialization/deserialization but this is opt-in behavior and it’s more or less fine because JSON dumping/loading has an established interface. to_s is an introspection method and isn’t meant to be used as a serialization means, so no, I’m not going to change this. What comes to render, I’m not sure about the name but we can add it via an extension (backed by the extension mechanism from dry-core).

I also prefer to use a separate method #render, or whatever name` for that. I would explore then the option about doing the extension.