/std-fns

Functional JavaScript Library

Primary LanguageJavaScript

std-fns

Standard Functions is a library aimed to fill in the gaps in the JS standard library. The library follows, or aims to follow, functional programming methodologies. Even though stable it is not very useful at the moment, so use at your own risk.

Documentation

Functions

bimap(leftFn, rightFn, p)Promise.<(R|never)>

Map over the success or error of a promise.

fmap(fn, p)Promise.<(T|never)>

Map over the value of a promise. The function provided should return another Promise.

lmap(fn, p)Promise.<(T|never)>

Short for left map, map over the error, or catch, of a promise. The function will only be called if the promise provided has fail.

map(fn, p)Promise.<(T|never)>

Map over the value of a promise. The map function will only be called if the promise is resolved.

tap(fn, p)Promise.<T>

Create a side effect from the value of a promise. The tap function is only called if the promise is resolved.

always(val)function

Creates a function which always returns the same value.

and(...args)*

Evaluates all arguments passed and returns the first falsey or last truthy value. It works like && operator.

compose(...fns)function

Compose a function from all functions passed as arguments from left to right.

composeRight(...fns)function

Compose a function from all functions passed as arguments from right to left.

curry(fn, ...initialArgs)function

Curry a function taking arguments from left to right. The constructor function accepts multiple value arguments. Returned functions also accept multiple arguments.

curryRight(fn, ...initialArgs)function

Curry a function taking arguments from right to left. The constructor function accepts multiple value arguments. Returned functions also accept multiple arguments.

identity(val)T

Pass a value to a function which returns said value.

inst(methodName, val)any | null

Call instance method of an object.

negate(fn)function

Creates a function which negates the value of the result. Works like the ! operator on the result of the function provided

not(val)boolean

Negates a argument to a boolean value like the ! operator.

or(...args)*

Evaluates all arguments passed and returns the first truthy or last falsey value. It works like || operator.

partial(fn, ...args)function

Partially apply arguments to a function from left to right.

partialRight(fn, ...outerArgs)function

Partially apply arguments to a function from right to left.

trim(val)string

Trims a string. Works like the string trim method.

dec(num)number

Decrement a number by one.

inc(num)number

Increment a number by one.

subtract(...numbers)number

Subtract all numbers passed into the function. It will subtract from left to right, first argument minus the second and then the product minus the next argument and so on.

sum(...numbers)number

Sum all numbers passed into the function. It will sum from left to right, first argument plus the second and then the product plus the next argument and so on.

bimap(leftFn, rightFn, p) ⇒ Promise.<(R|never)>

Map over the success or error of a promise.

Kind: global function

Param Type
leftFn function
rightFn function
p Promise.<(T|never)>

fmap(fn, p) ⇒ Promise.<(T|never)>

Map over the value of a promise. The function provided should return another Promise.

Kind: global function

Param Type
fn function
p Promise.<(T|never)>

lmap(fn, p) ⇒ Promise.<(T|never)>

Short for left map, map over the error, or catch, of a promise. The function will only be called if the promise provided has fail.

Kind: global function

Param Type
fn function
p Promise.<(T|never)>

map(fn, p) ⇒ Promise.<(T|never)>

Map over the value of a promise. The map function will only be called if the promise is resolved.

Kind: global function

Param Type
fn function
p Promise.<(T|never)>

tap(fn, p) ⇒ Promise.<T>

Create a side effect from the value of a promise. The tap function is only called if the promise is resolved.

Kind: global function

Param Type
fn function
p Promise.<T>

always(val) ⇒ function

Creates a function which always returns the same value.

Kind: global function

Param Type
val *

and(...args) ⇒ *

Evaluates all arguments passed and returns the first falsey or last truthy value. It works like && operator.

Kind: global function

Param Type
...args Array.<mixed>

compose(...fns) ⇒ function

Compose a function from all functions passed as arguments from left to right.

Kind: global function

Param Type Description
...fns function Comma separated list of functions

composeRight(...fns) ⇒ function

Compose a function from all functions passed as arguments from right to left.

Kind: global function

Param Type
...fns function

curry(fn, ...initialArgs) ⇒ function

Curry a function taking arguments from left to right. The constructor function accepts multiple value arguments. Returned functions also accept multiple arguments.

Kind: global function

Param Type Description
fn function
...initialArgs Array.<mixed> Comma separated list of arguments. Can be undefined.

curryRight(fn, ...initialArgs) ⇒ function

Curry a function taking arguments from right to left. The constructor function accepts multiple value arguments. Returned functions also accept multiple arguments.

Kind: global function

Param Type Description
fn function
...initialArgs $ReadOnlyArray.<mixed> Comma separated list of arguments. Can be undefined.

identity(val) ⇒ T

Pass a value to a function which returns said value.

Kind: global function

Param Type
val T

inst(methodName, val) ⇒ any | null

Call instance method of an object.

Kind: global function

Param Type
methodName String
val Object

negate(fn) ⇒ function

Creates a function which negates the value of the result. Works like the ! operator on the result of the function provided

Kind: global function

Param Type
fn function

not(val) ⇒ boolean

Negates a argument to a boolean value like the ! operator.

Kind: global function

Param Type
val *

or(...args) ⇒ *

Evaluates all arguments passed and returns the first truthy or last falsey value. It works like || operator.

Kind: global function

Param Type
...args $ReadOnlyArray.<mixed>

partial(fn, ...args) ⇒ function

Partially apply arguments to a function from left to right.

Kind: global function

Param Type Description
fn function
...args $ReadOnlyArray.<mixed> Comma separated list of values.

partialRight(fn, ...outerArgs) ⇒ function

Partially apply arguments to a function from right to left.

Kind: global function

Param Type Description
fn function
...outerArgs $ReadOnlyArray.<mixed> Comma separated list of values.

trim(val) ⇒ string

Trims a string. Works like the string trim method.

Kind: global function

Param
val

dec(num) ⇒ number

Decrement a number by one.

Kind: global function

Param Type
num number

inc(num) ⇒ number

Increment a number by one.

Kind: global function

Param Type
num number

subtract(...numbers) ⇒ number

Subtract all numbers passed into the function. It will subtract from left to right, first argument minus the second and then the product minus the next argument and so on.

Kind: global function

Param Type Description
...numbers Array.<number> Comma separated list of values.

sum(...numbers) ⇒ number

Sum all numbers passed into the function. It will sum from left to right, first argument plus the second and then the product plus the next argument and so on.

Kind: global function

Param Type Description
...numbers Array.<number> Comma separated list of values.

Todo

  • Add more function.
  • Add data structures.
  • Add algebraic types.
  • Add Flow library definition to the flow-typed project.