You return a (representation of a) side effect rather than execute a side effect.
Example
import{log}from'fp-ts/lib/Console'import{IO,io}from'fp-ts/lib/IO'import{chain,fold,none,Option,some}from'fp-ts/lib/Option'import{pipe}from'fp-ts/lib/pipeable'functiongetCharactersA(s:string):Option<string>{returns.length>3?some(s.substring(3)):none}functionprogram(input:string):IO<void>{returnpipe(some(input),chain(getCharactersA),// return my side effect only if there is a valuefold(()=>io.of(undefined),log))}program('foo')()// no outputprogram('barbaz')()// outputs "baz" to the console
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))