Utility functions for functions.
npm install go-fnsUtility functions for functions.
!codecov.io Code Coverage


* version: 1.0.0
* license: GNU LGPLv3
``javascript`
npm i go-fns
or
`javascript`
yarn add go-fns
`javascript
import { not } from 'go-fns'
[1, 2, 3.1].filter(not(Number.isInteger)); // => [3.1]
`
`javascript
const { not } = require('go-fns');
[1, 2, 3.1].filter(not(Number.isInteger)); // => [3.1]
`
`javascript
`
#### Table of Contents
* Utility
* pipe
* Parameters
* Examples
* spread
* Parameters
* Examples
* attempt
* Parameters
* Examples
* repeat
* Parameters
* Examples
* delay
* Parameters
* Examples
* Logic
* and
* Parameters
* Examples
* or
* Parameters
* Examples
* xor
* Parameters
* Examples
* nor
* Parameters
* Examples
* not
* Parameters
* Examples
#### pipe
Creates a function that executes a series of functions in the order provided.
First it passes the parameters to the first function and then the output
is used as the input for the next function in the sequence,
and so on until it reaches the end and finally it returns the output of the last function.
##### Parameters
* fns ...Function The functions to execute sequentially.
##### Examples
`javascript
pipe(Math.floor)(4.5); // => 4
pipe(Math.floor, Math.sqrt)(4.5); // => 2
`
* Throws TypeError if any of the given values is not a function, null or undefined.
Returns Function The new function that sequentially executes the given functions.
Meta
* since: 1.0.0
#### spread
* See: Spread operator
* See: Function.prototype.apply
Creates a function that takes an array of values and passes the values to the given function as individual parameters.
##### Parameters
* fn Function The function to execute with individual parameters.
##### Examples
`javascript
function sum(a, b) {
return a + b;
}
spread(sum)([1, 2]); // => 3
`
* Throws TypeError if fn is not a function.
Returns Function The new function that passes an array of values to the given function as individual parameters.
Meta
* since: 1.0.0
#### attempt
Attempts to execute a function and returns the result or if there was an error, the error object caught.
##### Parameters
* fn Function The function to attempt.args
* ...any? The arguments for the function.
##### Examples
`javascript
attempt(JSON.parse, "1"); // => 1
attempt(JSON.parse, ""); // => SyntaxError
`
* Throws TypeError if fn is not a function.
Returns (any | Error) The result of executing the function or the error object caught if there was an error.
Meta
* since: 1.0.0
#### repeat
Executes a function for a specified number of times and returns the results in a new array.
##### Parameters
* fn Function The function to execute.count
* number The number of times to execute. (optional, default 0)args
* ...any? The arguments for the function.
##### Examples
`javascript`
repeat(Math.floor, 3, 1.5); // => [1, 1, 1]
* Throws TypeError if fn is not a function.
Returns Array The new array containing the results.
Meta
* since: 1.0.0
#### delay
* See: setTimeout
Executes a function after a specified number of milliseconds with the arguments provided.
##### Parameters
* fn Function The function to execute after a delay.delay
* number The number of milliseconds to wait before executing the function. (optional, default 0)args
* ...any? The arguments for the function.
##### Examples
`javascript`
delay(log, 1000, "hi"); // => prints "hi" after 1 second.
* Throws TypeError if fn is not a function.
Returns number The timer id.
Meta
* since: 1.0.0
Propositional logic connectives
#### and
Creates a function that tests if all the given functions return a truthy value.
The parameters you pass when invoking the created function will be passed down to the given functions
with the this binding of the respective function.
##### Parameters
* fns ...Function The functions to test.
##### Examples
`javascript
and(isString, isPrimitive)("abc"); // => true
and(isString, isPrimitive)(new String("abc")); // => false
`
* Throws TypeError if any of the given values is not a function, null or undefined.
Returns Function The new function that tests if all the given functions return a truthy value.
Meta
* since: 1.0.0
#### or
Creates a function that tests if any of the given functions return a truthy value.
The parameters you pass when invoking the created function will be passed down to the given functions
with the this binding of the respective function.
##### Parameters
* fns ...Function The functions to test.
##### Examples
`javascript
or(isString, isNumber)("abc"); // => true
or(isString, isNumber)(true); // => false
`
* Throws TypeError if any of the given values is not a function, null or undefined.
Returns Function The new function that tests if any of the functions return a truthy value.
Meta
* since: 1.0.0
#### xor
Creates a function that tests if exactly one of the given functions returns a truthy value.
The parameters you pass when invoking the created function will be passed down to the given functions
with the this binding of the respective function.
##### Parameters
* fns ...Function The functions to test.
##### Examples
`javascript
xor(isString, isNumber)("abc"); // => true
xor(isString, isNumber)(1); // => true
xor(isString, isNumber)(true); // => false
`
* Throws TypeError if any of the given values is not a function, null or undefined.
Returns Function The new function that tests if exactly one of the given functions return a truthy value.
Meta
* since: 1.0.0
#### nor
Creates a function that tests if all the given functions return a falsy value.
The parameters you pass when invoking the created function will be passed down to the given functions
with the this binding of the respective function.
##### Parameters
* fns ...Function The functions to test.
##### Examples
`javascript
nor(isString, isNumber)(true); // => true
nor(isString, isNumber)("abc"); // => false
`
* Throws TypeError if any of the given values is not a function, null or undefined.
Returns Function The new function that tests if all the given functions return a falsy value.
Meta
* since: 1.0.0
#### not
Creates a function that negates the result of the given function.
The parameters you pass when invoking the created function will be passed down to the given function
with the this binding of the given function.
##### Parameters
* fn Function The function to negate.
##### Examples
`javascript
not(isString)(1); // => true
not(isString)("abc"); // => false
``
* Throws TypeError if the given value is not a function.
Returns Function The new function that negates the result of the given function.
Meta
* since: 1.0.0