dry-monads icon indicating copy to clipboard operation
dry-monads copied to clipboard

Task#then alias for #bind conflicts with Kernel#then

Open cllns opened this issue 2 years ago • 2 comments

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.)

cllns avatar Jan 18 '22 21:01 cllns

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.

flash-gordon avatar Jan 19 '22 03:01 flash-gordon

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.

cllns avatar Jan 24 '22 14:01 cllns

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.

hi-tech-jazz avatar Oct 03 '22 12:10 hi-tech-jazz