Open puffnfresh opened 6 years ago
Yeah, that was removed in the new version :)
I should update the documentation to note that here though.
@puffnfresh it differs a little bit from bimap in that this fold always returns a "resolved" task. You could use the following to convert a Task a b
to Task c (Either a b)
, for example:
task.fold(Left, Right)
Another way to view fold
is (I believe) that it's similar to a proper fold
, except that we cannot force the asynchronous operation to return synchronously, therefore we must return in a new Task.
And for the sake of clarity, let's view the signatures side-by-side:
fold :: Future a b ~> (a -> c, b -> c) -> Future d c
bimap :: Future a b ~> (a -> c, b -> d) -> Future c d
@Avaq I missed that detail, thank you. It's still not fold, but it's also not bimap.
It's still not fold
I know. :(
It's what I was referring to when I said similar to a proper fold
. I'm open to rename the function in Fluture for the sake of correctness, but I do find that fold
captures the idea of the function quite nicely.
If Fantasy Land were to adopt a spec that uses the fold
name, I will definitely do the rename, just to avoid confusion.
fold :: Future a b ~> (a -> c, b -> c) -> Future d c
if I'm allowed to ask an unrelated question, what is d
in this signature? A unit, I suppose?
Folktale 2's task only has willMatchWith
. No way of writing fold
without deep coroutines/fibers or threads :(
@raqystyle an arbitrary type variable. There it just means it's not the same type as a
, but it doesn't have any equivalent runtime set of values (it's not really unit
or null
). In that sense, it's closer to TypeScript's never
.
@robotlolita thank you for the explanation!
I got a question about
fold
, so I took a look at the signature:This is not a fold, this is bimap.