dry-monads
dry-monads copied to clipboard
Task#then alias for #bind conflicts with Kernel#then
Dry::Monads::Task
has an alias for its bind
method as then
.
Ruby 2.6 itself added Kernel#then
as an alias to Kernel#yield_self
(first note) ~11 months after dry-monads
added its alias.
dry-monads
's then
takes precedence, but conflicting with Kernel
methods is something we generally avoid.
Since it's just a helpful alias, and bind
is already used a lot in dry-monads
, I think it could be OK to just remove this alias, though that's technically a breaking change (or could wait for a 2.0 release, since this is pretty low stakes.)
I think we can add a deprecation warning and cut a release. I would like to push 2.0 sometime soon anyway. .then
is a common name for chaning promises/futures/etc but I agree we shouldn't shadow Kernel
here.
In Elm this is called andThen
(it's also what they call it for Result
and Maybe
too), so and_then
could be another option.
But, might be simpler to just stick to bind
especially since and_then
and then
are quite different.
I really like the concept of and_then
and or_else
used in the Upgrow project. For example, then you could do:
operation.call(input)
.and_then do |value|
# handle success
end
.or_else do |errors|
# handle failure
end
https://github.com/szTheory/upgrow/blob/main/lib/upgrow/result.rb
Could that be interesting in this project?
Edit: On the Result
monad, rather than Task
.