prelude-js logoprelude-js

preludejs/Func API

Complete API reference for preludejs/Func

preludejs/Func API Reference

Core

apply ƒ

Returns the application of the supplied list as arguments to the supplied function.

function apply<A extends readonly unknown[], R>(fn: (...args: A) => R, args: A): R

Parameters

ParameterTypeDescription
fn(...args: A) => R
argsA

Example

apply((a: number, b: number) => a + b, [2, 3]) //=> 5

compose ƒ

Performs right-to-left function composition. The rightmost function may have any arity; the remaining functions must be unary.

function compose<Fns extends readonly AnyFn[]>(...fns: Fns): Compose<Fns>

Parameters

ParameterTypeDescription
fnsFns

Example

compose((x: number) => x + 1, (x: number) => -x)(3) //=> -2

const ƒ

Returns the first supplied value and ignores the second.

function const<A>(value: A): <B>(_ignored: B) => A
function const<A, B>(value: A, _ignored: B): A

Parameters

ParameterTypeDescription
valueA

Example

constant('hello')('world') //=> 'hello'
constant('hello', 'world') //=> 'hello'

curry ƒ

Returns a curried version of the supplied function.

function curry<A extends readonly unknown[], R>(fn: (...args: A) => R): Curried<A, R>

Parameters

ParameterTypeDescription
fn(...args: A) => R

Example

curry((a: number, b: number) => a + b)(1)(2) //=> 3

deny ƒ

Denies the result of a predicate function.

function deny<A extends readonly unknown[], R>(fn: (...args: A) => R): (...args: A) => boolean

Parameters

ParameterTypeDescription
fn(...args: A) => R

Example

deny((x: number) => x > 2)(2) //=> true

fix ƒ

Fix-point function for anonymous recursion, implemented with the https://en.wikipedia.org/wiki/Fixed-point_combinator#Y_combinator Y combinator.

function fix<A extends readonly unknown[], R>(fn: (recur: (...args: A) => R) => (...args: A) => R): (...args: A) => R

Parameters

ParameterTypeDescription
fn(recur: (...args: A) => R) => (...args: A) => R

Example

fix<[number], number>((recur) => (n) => (n <= 1 ? 1 : recur(n - 1) + recur(n - 2)))(9) //=> 55

flip ƒ

Returns a function with the first two arguments flipped.

function flip<A extends readonly unknown[], R>(fn: (...args: A) => R): (...args: Reverse<A>) => R

Parameters

ParameterTypeDescription
fn(...args: A) => R

Example

flip(Math.pow)(2, 3) //=> 9

memoize ƒ

Caches computed results, speeding up later calls with the same arguments.

function memoize<A extends readonly unknown[], R>(fn: (...args: A) => R): (...args: A) => R

Parameters

ParameterTypeDescription
fn(...args: A) => R

Example

memoize((n: number) => n * 2)(2) //=> 4

uncurry ƒ

Applies an array of arguments to a function, which is especially handy for curried functions.

function uncurry<A extends readonly unknown[], R>(fn: (...args: A) => R, args: A): R
function uncurry<A extends readonly unknown[], R>(fn: (...args: A) => R): (args: A) => R

Parameters

ParameterTypeDescription
fn(...args: A) => R
argsA

Example

uncurry(curry((a: number, b: number) => a + b), [2, 3]) //=> 5

On this page