Sub-project of Funfix defining monadic data types for dealing with laziness and side effects.
Eval | lawful, lazy, monadic data type, that can control evaluation, inspired by the Eval type in Typelevel Cats and by the Coeval type in Monix, a more simple IO -like type that can only handle immediate execution, no async boundaries, no error handling, not being meant for suspending side effects. |
IO | lawful, lazy, monadic data type, capable of expressing and composing side effectful actions, including asynchronous, being the most potent and capable alternative to JavaScript's Promise , inspired by Haskell's IO and by the Monix Task |
You can depend on the whole funfix
library, by adding it to
package.json
:
npm install --save funfix
In this case imports are like:
import { Eval, IO } from "funfix"
Or for finer grained dependency management, the project can depend
only on funfix-effect
:
npm install --save funfix-effect
In this case imports are like:
import { Eval, IO } from "funfix-effect"
Usage sample:
import { IO } from "funfix"
const f1 = IO.of(() => "hello")
const f2 = IO.of(() => "world")
const greeting = IO.map2(f1, f2, (a, b) => a + " " + b)
greeting.run().onComplete(result =>
result.fold(
console.error,
console.info
))
The library has been compiled using UMD (Universal Module Definition), so it should work with CommonJS and AMD.
But it also provides a module
definition in package.json
, thus
providing compatibility with
ECMAScript 2015 modules, for usage when used with a modern JS engine,
or when bundling with a tool chain that understands ES2015 modules,
like Rollup or Webpack.
Type alias representing registration callbacks for tasks
created with asyncUnsafe
, that are going to get executed
when the asynchronous task gets evaluated.
Generated using TypeDoc
Set of options for customizing IO's behavior.
should be set to
true
in case you wantflatMap
driven loops to be auto-cancelable. Defaults tofalse
because of safety concerns.