Fn

monoid. Fn

new Fn()

The Fn monoid. Fn can be used to combine multiple functions

Version:
  • 3.0.0
Source:
Example
const {Fn} = require('futils').monoid;

Fn((a) => a); // -> Fn(a -> a)

Fn((a) => a).value;  // -> (a -> a)
Fn((a) => a).run(1); // -> 1

Extends

  • module:generics/Show
  • module:generics/Eq

Methods

(static) empty() → {Fn}

Monoid implementation for Fn. Returns a Fn of the id function (a -> a)

Source:
Returns:
Type:
Fn

The empty Fn

Example
const {Fn} = require('futils').monoid;

Fn.empty(); // -> Fn(a -> a)

(static) of(a) → {Fn}

Lifts a value into a Fn. Returns the empty Fn for values which are no functions

Source:
Parameters:
Name Type Description
a any

The value to lift

Returns:
Type:
Fn

A new Fn

Example
const {Fn} = require('futils').monoid;

Fn.of((a) => a * 2);    // -> Fn(a -> a * 2)
Fn.of(null);            // -> Fn(a -> a)
Fn.of({});              // -> Fn(a -> a)

concat(a) → {Fn}

Concatenates a Fn with another using function composition

Source:
Parameters:
Name Type Description
a Fn

The Fn instance to concatenate with

Returns:
Type:
Fn

A new Fn

Example
const {Fn} = require('futils').monoid;

const fn = Fn((a) => a * 2);

fn.concat(Fn((a) => a * 3)); // -> Fn(a -> a * 2 * 3)