-
Notifications
You must be signed in to change notification settings - Fork 20
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
Folding #113
Comments
Hey @puffnfresh. I'm having trouble wrapping my head around use cases of it for a few reasons. Do you have any in mind that you can share? Where I'm getting hung up is it seems delay(1000, 'delayed').fold(a => true, b => false) == undefined That seems to imply that folks would often find themselves wanting to call Creed promises aren't lazy, since one of the original design goals was to be ES-Promise compatible while also implementing Fantasy Land. So, Is that what you have in mind? |
Yes, I wasn't thinking right - it should always return undefined. I just want to use this for performing side-effects. |
No, a promise has more than two states. It's not
I still don't see your use case. Why not simply use |
Thanks @puffnfresh. I think @bergus's question about Thinking about it myself, I can imagine a few potentially interesting things about
Any thoughts on those? |
@briancavalier yeah, those are pretty much my thoughts. Particularly the first one, if I want to do side-effects, I don't want to have a value. |
It looks like there's some precedent for an operation named So, maybe we actually want 2 operations here: Map either side of the promise to a new fulfilled promise: Promise e a ~> (e -> b) -> (a -> b) -> Promise e b Consume either side of the promise and perform side effects: Promise e a ~> (e -> b) -> (a -> b) -> undefined Any thoughts on those two, and why we'd favor the name |
FWIW, I'm still in favor of at least the "perform side effects and return undefined" function. I'm possibly in favor of the "map error or value to fulfilled" function, but seems harder to envision use cases for it. |
Here's a proposal: when :: Promise e a ~> (e -> f) -> (a -> b) -> undefined fulfill(x).when(e => console.error(e), x => console.log(x)) === undefined // logs x
reject(e).when(e => console.error(e), x => console.log(x)) === undefined // logs e
never().when(e => console.error(e), x => console.log(x)) === undefined // doesn't log, ever when():
|
From the Bifunctor, it seems a Promise has two states:
I would like to "run" a Promise and act on each state:
The text was updated successfully, but these errors were encountered: