Options
All
  • Public
  • Public/Protected
  • All
Menu

funfix-effect

Sub-project of Funfix defining monadic data types for dealing with laziness and side effects.

Contents

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

Usage

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
  ))

Modules: UMD and ES 2015

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.

Index

Type aliases

EvalTypes

EvalTypes: Monad<"funfix/eval">

Type enumerating the type classes implemented by Eval.

IOOptions

IOOptions: object

Set of options for customizing IO's behavior.

param

should be set to true in case you want flatMap driven loops to be auto-cancelable. Defaults to false because of safety concerns.

Type declaration

  • autoCancelableRunLoops: boolean

IORegister

IORegister: function

Type alias representing registration callbacks for tasks created with asyncUnsafe, that are going to get executed when the asynchronous task gets evaluated.

Type declaration

    • (context: IOContext, callback: function): void
    • Parameters

      • context: IOContext
      • callback: function
          • (result: Try<A>): void
          • Parameters

            • result: Try<A>

            Returns void

      Returns void

IOTypes

IOTypes: Monad<"funfix/io">

Type enumerating the type classes implemented by Io.

Variables

Private Const evalUnitRef

evalUnitRef: Now<void> = new Now(undefined)

Reusable reference, to use in Eval.unit.

Private Const ioUnitRef

ioUnitRef: IOPure<void> = new IOPure(Try.unit())

Reusable reference, to use in IO.unit.

Object literals

Const EvalModule

EvalModule: object

Type-class implementations, compatible with the static-land specification.

of

of: pure = Eval.pure

ap

chain

  • chain<A, B>(f: function, fa: Eval<A>): Eval<B>
  • Type parameters

    • A

    • B

    Parameters

    • f: function
        • Parameters

          • a: A

          Returns Eval<B>

    • fa: Eval<A>

    Returns Eval<B>

chainRec

  • chainRec<A, B>(f: function, a: A): Eval<B>
  • Type parameters

    • A

    • B

    Parameters

    • f: function
        • <C>(next: function, done: function, a: A): Eval<C>
        • Type parameters

          • C

          Parameters

          • next: function
              • (a: A): C
              • Parameters

                • a: A

                Returns C

          • done: function
              • (b: B): C
              • Parameters

                • b: B

                Returns C

          • a: A

          Returns Eval<C>

    • a: A

    Returns Eval<B>

map

  • map<A, B>(f: function, fa: Eval<A>): Eval<B>
  • Type parameters

    • A

    • B

    Parameters

    • f: function
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • fa: Eval<A>

    Returns Eval<B>

Const IOModule

IOModule: object

Type-class implementations, compatible with the static-land specification.

of

of: pure = IO.pure

ap

  • ap<A, B>(ff: IO<function>, fa: IO<A>): IO<B>
  • Type parameters

    • A

    • B

    Parameters

    • ff: IO<function>
    • fa: IO<A>

    Returns IO<B>

chain

  • chain<A, B>(f: function, fa: IO<A>): IO<B>
  • Type parameters

    • A

    • B

    Parameters

    • f: function
        • (a: A): IO<B>
        • Parameters

          • a: A

          Returns IO<B>

    • fa: IO<A>

    Returns IO<B>

chainRec

  • chainRec<A, B>(f: function, a: A): IO<B>
  • Type parameters

    • A

    • B

    Parameters

    • f: function
        • <C>(next: function, done: function, a: A): IO<C>
        • Type parameters

          • C

          Parameters

          • next: function
              • (a: A): C
              • Parameters

                • a: A

                Returns C

          • done: function
              • (b: B): C
              • Parameters

                • b: B

                Returns C

          • a: A

          Returns IO<C>

    • a: A

    Returns IO<B>

map

  • map<A, B>(f: function, fa: IO<A>): IO<B>
  • Type parameters

    • A

    • B

    Parameters

    • f: function
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • fa: IO<A>

    Returns IO<B>

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc