-
Notifications
You must be signed in to change notification settings - Fork 18
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
Theory: Task is good not only for async, but also for composing sync side effects in a pure fashion #8
Comments
Could you not use IO https://github.com/fantasyland/fantasy-io for a synchronous way to perform effects? |
Yea, IO is the monad that usually used for this. And IO can be used for async as well I think. So I was thinking maybe Task could also be a universal monad for async/impure stuff. In this case we could write pure programs in JS expressed as Tasks compositions. We would need to wrap all impure APIs in Task based APIs for this. Currently I don't know whether this will work and whether this is a good idea. I'm going to try to build some examples. |
I've been using Futures to this effect, in combination with The advantages of this approach, I find, are:
However, I believe there is a severe disadvantage, which is something I have been thinking about lately. One benefit of using monads, is that you are explicit about effects. If you unwrap a structure of
In the case of Futures/Tasks, all of this explicit information is lost. Futures are essentially
Though in practice this is not often a problem, I did run into a situation where I had to maintain a |
Flow can help with this one. // empty type, we can't create a value of this type
type Empty = void & null
const myTask: Task<string, Empty> = Task.create((succ, fail) => {
// can't call fail() because can't create a value that could be passed to it
}) Also Flow can show type of any variable (with a good editor plugin), so if we see that some variable is of type See in action: https://github.com/rpominov/fun-task/blob/master/examples/io/1.js Update: empty type might be added to Flow facebook/flow#2225 |
Another example based on this idea: https://jsfiddle.net/eh93ry0o/9/ Update: for the record couple more examples and thoughts are in this twitter thread https://twitter.com/rpominov/status/788853797175042049 |
Just an area I'm going to explore. Nothing in particular to write about just yet.
The text was updated successfully, but these errors were encountered: