Alias Dry::Monads::Result as Dry::Operation::Result #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This change would completely abstract away the implementation detail of using dry-monads. Monads are often intimidating to Ruby programmers, so it'd be nice if we could hide it from them. Then we can position dry-operation as a thin API and "just pattern matching" on the result, instead of thinking they need to understand what a monad before using it.
My primary interest here is for Hanami 2.2 users, who will get dry-operation included in their apps. A reference here is from Evan Czaplicki's talk "Let's be mainstream!" where he talks about avoiding using "monad" at all, which is what Elm does.
Details
Instead of
Dry::Monads[:result]
, users will includeDry::Operation::Result::Mixin
. Since we're just aliasing the constant, people can include the result from Dry::Monads and it'll work as desired. This might be nice if people are including several monads.We could change this to something like
Dry::Operation[:result]
if we want to extend this, but I just wanted to open this PR to get the conversation started.Tradeoff
This does add some indirection, since we're adding an alias. I think it's worth it since it lowers the bar to entry for new users of dry-monads, and it only adds a small amount of added complexity for people working on dry-operation.