0.2.3 • Published 5 years ago

std-fns v0.2.3

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

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.

Kind: global function

ParamType
leftFnfunction
rightFnfunction
pPromise.<(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

ParamType
fnfunction
pPromise.<(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

ParamType
fnfunction
pPromise.<(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

ParamType
fnfunction
pPromise.<(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

ParamType
fnfunction
pPromise.<T>

always(val) ⇒ function

Creates a function which always returns the same value.

Kind: global function

ParamType
val*

and(...args) ⇒ *

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

Kind: global function

ParamType
...argsArray.<mixed>

compose(...fns) ⇒ function

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

Kind: global function

ParamTypeDescription
...fnsfunctionComma separated list of functions

composeRight(...fns) ⇒ function

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

Kind: global function

ParamType
...fnsfunction

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

ParamTypeDescription
fnfunction
...initialArgsArray.<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

ParamTypeDescription
fnfunction
...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

ParamType
valT

inst(methodName, val) ⇒ any | null

Call instance method of an object.

Kind: global function

ParamType
methodNameString
valObject

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

ParamType
fnfunction

not(val) ⇒ boolean

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

Kind: global function

ParamType
val*

or(...args) ⇒ *

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

Kind: global function

ParamType
...args$ReadOnlyArray.<mixed>

partial(fn, ...args) ⇒ function

Partially apply arguments to a function from left to right.

Kind: global function

ParamTypeDescription
fnfunction
...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

ParamTypeDescription
fnfunction
...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

ParamType
numnumber

inc(num) ⇒ number

Increment a number by one.

Kind: global function

ParamType
numnumber

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

ParamTypeDescription
...numbersArray.<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

ParamTypeDescription
...numbersArray.<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.
0.2.3

5 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago

1.0.0

6 years ago