Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cllns opened this issue Jan 18, 2022 · 3 comments
Closed

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

cllns opened this issue Jan 18, 2022 · 3 comments

Comments

@cllns
Copy link
Member

cllns commented Jan 18, 2022

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

@flash-gordon flash-gordon added this to the 2.0 milestone Jan 19, 2022
@flash-gordon
Copy link
Member

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.

@cllns
Copy link
Member Author

cllns commented Jan 24, 2022

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.

@hi-tech-jazz
Copy link

hi-tech-jazz commented Oct 3, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants