static field
A shortcut of M.$n(1)
static field
A shortcut of M.$n(2)
static field
A shortcut of M.$n(3)
static field
A shortcut of M.$n(4)
static method
The placeholder of argument.
$F((x, y, z) => x + y + z)(M.$n(1), "6", M.$n(2))("7")("5"); // outputs "765"
static method
Monad 'unit' function.
This method is equivalent to M.Right(x).
static method
creates a function which can curry and compose.
First argument is a function to wrap and second argument is arity of the function.
If second argument is omitted, arity is equals to length of the first argument.
M.F((x, y, z) => x + y + z)(7)(6)(5); // outputs 18
method
returns arity of this function.
method
This method is equivalent to 'pipe'.
method
concatenates this function and the given function.
Arity of the given function must be 1.
The concatenated function can be curried.
M.F((x, y, z) => x + y + z).pipe(x => x + 2)(7)(6)(5); // outputs 20
static method
An identity function (I combinator).
M.F.I is an alias of this method.
method
unwraps this function.
static method
creates an identity monad with the given value.
method
Monad 'bind' function.
This method simply apply the element to the given function.
M.Identity(4).bind(x => M.Identity(x + 2)); // outputs M.Identity(6)
method
This method is equivalent to 'bind'.
method
returns the string representation of the holding value.
static method
Monad 'unit' function.
This method is equivalent to M.Identity.
method
returns the element.
static method
creates new Maybe Just monad with the given value.
method
Monad 'bind' function.
This method returns the result applying the wrapped value to the given function a → M.Maybe a.
M.Just(3).bind(x => M.Just(x * x)); // outputs M.Just(9)
method
always returns false.
method
This method is equivalent to 'bind'.
method
returns this monad.
M.Just(3).or(M.Just(4)); // output M.Just(3)
method
returns a wrapped value.
M.Just(3).value(); // outputs 3
static method
creates a list from the given arguments.
M.L(3, 4, 6).at(1); // outputs 4
method
gets an element at the specified index.
M.L.N(1).at(10); // outputs 10
method
Monad 'bind' function.
The first argument is a function whose input is element of list and output is M.L.
M.L(2, 7).bind(x => M.L(x + 2, x + 3)); // outputs M.L(4, 5, 9, 10)
static method
returns a list which consists of k-combination of the array given by first argument.
Every element of the list is a tuple.
The number k is given by second argument.
M.L.combination(["a", "b", "c"], 2); // outputs M.L(M.T("a", "b"), M.T("a", "c"), ...)
method
concatenates the given list to this list.
M.L(3, 4).concat(M.L(6)); // outputs M.L(3, 4, 6)
static method
creates new list whose first value is the first arguement and rest value is the result of a thunk (a function with no arguments) given by second argument.
function succ(n) {
return M.L.create(n, function() { return succ(n + 1); });
}
succ(1); // outputs M.L(1, 2, 3, 4, 5, ...)
method
returns false if it exists that the element of this list applies to the function
given by the first argument is falsy.
Notice: This method may not stop if elements of the list is infinity.
M.L(3, 4, 6).every(x => x % 2 === 0); // outputs false
method
returns new list which pass the test which is given the first argument.
This method is available when the list has infinity elements.
M.L.N(1).filter(x => x % 2 === 0); // outputs M.L(2, 4, 6, ...)
method
returns true if this list is empty.
method
returns new list with the result of calling the function given by the argument
on every element of this list.
This method is available when the list has infinite elements.
M.L.N(1).map(x => x * 2); // outputs M.L(2, 4, 6, ...)
static method
returns new list with the result of
calling the function given by the argument on every element of the lists.
This method is available when the list has infinite elements.
M.L.map((x, y, z) => x + y + z, M.L(1, 2, 3), M.L(3, 4, 5), M.L(6, 7)); // outputs M.L(10, 13)
method
This method is equivalent to 'bind'.
static method
returns an infinite list of natural number.
The first argument is first number.
M.L.N(0); // outputs M.L(0, 1, 2, ...)
static method
returns a list which consist of k-permutation of the array given by first argument.
Every element of the list is a tuple.
The number k is given by second argument.
If k is not given, k is the length of the given array.
M.L.permutation(["a", "b", "c"], 2); // outputs M.L(M.T("a", "b"), M.T("a", "c"), ...)
static method
returns nth power list of the list given by first argument.
The number n is given by second argument.
A infinite list can give as an operand.
// outputs M.L(M.T("a", "a"), M.T("a", "b"), M.T("b", "a"), M.T("b", "b"))
M.L.power(M.L("a", "b"), 2);
static method
returns new list of cross product of the given lists.
A infinite list can give as an operand.
// outputs M.L(M.T(2, 3), M.T(4, 3), M.T(2, 6), M.T(6, 3), M.T(4, 6), M.T(6, 6))
M.L.product(M.L(2, 4, 6), M.L(3, 6));
static method
A list of integers which starts with first argument(inclusive) and ends with second argument(inclusive).
method
gets rest of this list.
M.L(3, 4, 6).rest(); // outputs M.L(4, 6)
method
returns true if it exists that the element of this list applies to the function
given by the first argument is truthy.
Notice: This method may not stop if elements of the list is infinity.
M.L(3, 4, 6).some(x => x % 2 === 0); // outputs true
method
returns an array of first n elements.
If the argument is not given, returns an array of all elements.
Notice: This method may not stop if elements of the list is infinity.
M.L.N(2).take(5)); // outputs [2, 3, 4, 5, 6]
static method
Monad 'unit' (or 'return') function.
The method returns new list which contains only the given element.
M.L.unit(9); // outputs M.L(9)
method
gets first element.
M.L(3, 4, 6).value(); // outputs 3
static field
A infinite list of integer.
static method
returns new list with the tuples of the given lists.
M.L.zip(M.L(1, 2, 3), M.L(3, 4, 5), M.L(6, 7)); // outputs M.L(M.T(1, 3, 6), M.T(2, 4, 7))
method
Monad 'bind' function.
This method returns this monad.
M.Left(3).bind(x => M.Right(x * x)); // outputs M.Left(3)
method
apply the holded value to function given by first argument.
M.Left(3).either(x => x + 2, x => x * 2); // outputs 5
method
This method is equivalent to 'bind'.
method
returns the Either monad given by the first argument.
M.Left(3).or(M.Right(2)); // outputs M.Right(3)
static method
Monad 'unit' function.
This method is equivalent to M.Just(x).
static field
An empty list.
static field
A Maybe Nothing monad.
method
Monad 'bind' function.
returns this monad.
M.Nothing.bind(x => M.Just(x * x)); // outputs M.Nothing
method
always returns true.
method
This method is equivalent to 'bind'.
method
returns the given argument.
M.Nothing.or(M.Just(4)); // outputs M.Just(4)
method
always throws an error.
static method
A Right monad of Either.
method
Monad 'bind' function.
This method returns the result applying the wrapped value to the given function a → M.Either a.
M.Right(3).bind(x => M.Right(x * x)); // outputs M.Right(9)
method
apply the wrapped value to function given by second argument.
M.Right(3).either(x => x + 2, x => x * 2); // outputs 6
method
This method is equivalent to 'bind'.
method
returns this monad.
M.Right(3).or(M.Left(2)); // outputs M.Right(3)
static method
creates new state monad.
method
Monad 'bind' function.
method
returns the result value by executing this monad.
method
returns the state by executing this monad.
static field
A state monad which copies the state to the value.
static method
creates new state monad which replaces the state to the result of calling the given function.
method
This method is equivalent to 'bind'.
static method
creates new state monad which replaces the state to the given value.
method
returns a tuple of the result and state by executing this monad.
static method
Monad 'unit' function.
This method creates a state monad whose value is the given value.
static method
creates new state monad transformer.
This method has two curried arguments.
First argument is constructor of monad m, and second argument is a function a → m (v, s).
method
Monad 'bind' function.
field
A state monad transformer which copies the state to the value.
method
lifts the given monad to state monad transformer.
method
creates new state monad transformer which replaces the state to the result of calling the given function.
method
This method is equivalent to 'bind'.
method
creates new state monad transformer which replaces the state to the given value.
method
returns a tuple of the result and state by executing this monad.
method
Monad 'unit' function.
This method creates a state monad transformer whose value is the given value.
static method
creates new tuple of the given elements.
M.T(1, 2, 3); // outputs a tuple (1, 2, 3)
static method
returns true is the given object is a tuple.
method
converts this tuple to an array.
M.T(1, 2, 3).toArray() // outputs [1, 2, 3]
static field
The 'do' notation.
M.tu($L(1, 2),
x => $L(x * 2, x * 3),
x => $L(x + 2, x + 3),
x => $L(x * 2)).take(); // outputs [8, 10, 10, 12, 12, 14, 16, 18]