In fp-ts a synchronous effectful computation is represented by the IO type, which is basically a thunk, i.e. a function with the following signatur...
For further actions, you may consider blocking this person and/or reporting abuse
Fantastic article, as always.
I'm pretty new to FP concepts, and I still need to learn how some simple imperative code translates to functional code.
How can I execute a side effect in a chain? EG:
EDIT: I'm used to the
tap
operator of RxJSThank you!
You return a (representation of a) side effect rather than execute a side effect.
Example
Or fold(io.of(constVoid))
I like it but didn't' understand much.
The point of IO is to defer execution (making it lazy).
Deferring execution allows us to make pure functions from impure functions.
We prefer pure functions because they are easier to reason about.
The impure function has dependencies which are "tricky" because they are not deterministic.
It means, the impure function has side-effects and may return a different value or affects other functions.
Dangerous stuff better to avoid.
IO helps us to move a burden to the caller.
In Haskell like pure functional application, IO functions are only in composition root aka main.
Everything else (our app) is pure.
Watch this youtube.com/watch?v=cxs7oLGrxQ4&t=...
"IO helps us to move a burden to the caller."
This is weird. Why we need move a burden to caller. I mean this is different from the DI in OO programing: If we just use a thunk to wrap the "side effect", the side effect is just there, when caller call the function in main, every side effect just executes. i don't know what problems do IO solve.
DI in OO makes functions/class methods easy to be tested at least
Great project! I was able to follow this IO tutorial and created a sample project that loads a file (synchronously) and parses the resulting YAML (github.com/anotherhale/fp-ts_sync-...). I am struggling with Tasks, dependent tasks specifically, that attempts the same file loading and parsing YAML but asynchronously (github.com/anotherhale/fp-ts_async...). Can anyone provide any feedback?
Excellent articles, I have been following along since the beginning (tcomb types articles) and FP-TS is groovy.
One thing I was curious about was what motivated you go into the direction of TS being the language of choice in comparison to some other compile to JS such as purescript, clojurescript, etc ? Just wondering about the origins.
TypeScript allows me to reach for more people, my very goal is to spread fp concepts. TS is only a means, not an end.
What is the difference between writing to the localStorage and writing to the DOM? Could you think a reasonably simple example where the effect is to activate reactjs to create some components into the DOM and listen to user input provided through them?
Do you think it is possible to construct a realistically useable FP-powered engine to handle interactions with the DOM without having to create a huge cathedral like the elm runtime? (which sometimes reminds me more of a prison than of a cathedral ;-)
I'd like to add just one thing: writing to localStorage CAN in fact throw a QuotaExceededError, so it is probably a better example for the use case for IOEither.
love to hear about edge cases! thanks.
I would love to see a reactive example with mouse click events.
This is a great intro! I'm really excited to see async!
Hi there,
I'm learning fp with this library and I'm wondering, is there a way to
chain
3 or moreIOEither
s?It seems like
chain
is statically typed to only allow 2IOEithers
Thanks
You can use pipe (frok fp-ts/pipeable)