Global

Methods

allEqual(val, list) → {Boolean}

Composition of all and equals. Returns true if all the values in the given list are equal to the value to test against.

Parameters:
Name Type Description
val *

The value to test equality against.

list List

The list we wish to check.

Source:
See:
Example
allEqual( 1, [1, 1, 1] );              //=> true
allEqual( 1, [] );                     //=> true
allEqual( true, [true, false, true] ); //=> false

assocTrans(prop, fn, obj) → {Object}

Makes a shallow clone of the target object, setting or overriding the specified property with the result of the given function over the target object. Note that this copies and flattens prototype properties onto the new object as well. All non-primitive properties are copied by reference.

Parameters:
Name Type Description
prop String

The property name to set.

fn function

The transformation function to apply to obj. The result of the evaluation of this function will be the value of prop.

obj Object

The object to clone.

Source:
See:
Example
const getMean = pipe( prop( "earnings" ), mean );
assocTrans( "mean", getMean, { earnings: [1, 2, 3], trimester: 1 } );    //=> { earnings: [1, 2, 3], trimester: 1, mean: 2 };

compact(list) → {List}

Returns a copy of the array with all falsy and empty values removed.

Parameters:
Name Type Description
list List

The list to compact.

Source:
Example
compact( [0, 1, false, 2, '', 3, [], {}] );  //=> [1, 2, 3]

delay(ms, fn, data) → {Promise}

Waits ms milliseconds and then executes the given function with the given data.

Parameters:
Name Type Description
ms Number

The amount of milliseconds to wait.

fn function

The function to execute after ms milliseconds have passed.

data *

The data to be passed to fn for it to execute.

Source:
Example
const double = x => x * 2;
const waitAndDouble = delay( 1000, double );

waitAndDouble( 2 ).then( console.log );      //=> prints 4 after 1 second 

isArray(val) → {Boolean}

Returns true of the given value is an Array, false otherwise.

Parameters:
Name Type Description
val *

The value to test if it is an Array.

Source:
See:
Example
isArray( console.log ); //=> false
isArray( 1 );           //=> false
isArray( "" );          //=> false
isArray( [] );          //=> true
isArray( new Map() );   //=> false

isFunction(val) → {Boolean}

Returns true of the given value is a Function, false otherwise.

Parameters:
Name Type Description
val *

The value to test if it is a Function.

Source:
See:
Example
isFunction( console.log );   //=> true
isFunction( 1 );             //=> false
isFunction( "" );            //=> false
isFunction( [] );            //=> false
isFunction( new Map() );     //=> false

isMap(val) → {Boolean}

Returns true of the given value is a Map, false otherwise.

Parameters:
Name Type Description
val *

The value to test if it is a Map.

Source:
See:
Example
isMap( console.log ); //=> false
isMap( 1 );           //=> false
isMap( "" );          //=> false
isMap( [] );          //=> false
isMap( new Map() );   //=> true

isNumber(val) → {Boolean}

Returns true of the given value is a Number, false otherwise.

Parameters:
Name Type Description
val *

The value to test if it is a Number.

Source:
See:
Example
isNumber( console.log ); //=> false
isNumber( 1 );           //=> true
isNumber( "" );          //=> false
isNumber( [] );          //=> false
isNumber( new Map() );   //=> false

isString(val) → {Boolean}

Returns true of the given value is a String, false otherwise.

Parameters:
Name Type Description
val *

The value to test if it is a String.

Source:
See:
Example
isString( console.log ); //=> false
isString( 1 );           //=> false
isString( "" );          //=> true
isString( [] );          //=> false
isString( new Map() );   //=> false

mapAsyncFn(fn, list) → {Promise}

Applies fn concurrently to each element of list. Unlike mapToSequentialPromises the execution of Promise N+1 will not wait for the resolution of Promise N. Finishes once all the Promises are done via use of Promise.all.

Parameters:
Name Type Description
fn function

The function to apply to each element of list.

list List

The list to be iterated over concurrently.

Source:
Example
const double = x => x * 2;
const waitAndDouble = delay( 1000, double );
mapAsyncFn( waitAndDouble, [1, 2, 3] ).then( console.log );               //=> 2, 4, 6 ( all at the same time, 1 second after `mapAsyncFn` is executed )  

mapToSequentialPromises(fn, list) → {List}

Applies fn sequentially to each element of list. If fn is async and returns a Promise, then each Promise will be executed only when the previous Promise has resolved. If fn does not return a Promise, then its result is lifted into one.

Parameters:
Name Type Description
fn function

The function to apply to each element of list.

list List

The list to be iterated over sequentially.

Source:
Example
const waitAndPrint = delay( 1000, console.log );
mapToSequentialPromises( waitAndPrint, [1, 2, 3] );                              //=> 1, 2, 3 ( each with 1000ms of delay between )

notEmpty(val) → {Boolean}

Complement of isEmpty. Returns false if the given value is its type's empty value; true otherwise.

Parameters:
Name Type Description
val *

The value to test.

Source:
See:
Example
notEmpty( [1, 2, 3] );   //=> true
notEmpty( [] );          //=> false
notEmpty( "" );          //=> false
notEmpty( null );        //=> true
notEmpty( {} );          //=> false
notEmpty( {length: 0} ); //=> true

notNil(val) → {Boolean}

Complement of isNil. Returns true if the given value is not null or undefined, false otherwise.

Parameters:
Name Type Description
val *

The value to test.

Source:
See:
Example
notNil( null );          //=> false
notNil( undefined );     //=> false
notNil( 0 );             //=> true
notNil( [] );            //=> true

promiseAll(pList) → {Promise}

Alias for Promise.all. Receives a list of promises and waits for all of them to complete or for one to reject. Returns a single Promise.

Parameters:
Name Type Description
pList List

The list of promises.

Source:
See:
Example
promiseAll( [ Promise.resolve(1), Promise.resolve(2) ] ).then( console.log );    //=> [1, 2]

renameProp(oldPropName, newPropName, obj) → {Object}

Makes a shallow clone of the target object, renaming the given property. Note that this copies and flattens prototype properties onto the new object as well. All non-primitive properties are copied by reference.

Parameters:
Name Type Description
oldPropName String

The property to be renamed.

newPropName String

The new name of the property.

obj Object

The object to clone.

Source:
Example
renameProp( "tree", "plant", { tree: "sunflower" } );    //=> { plant: "sunflower" };

seedlessReduce(fn, list) → {*}

Reduce transformation using the head of the given list as initial input.

Parameters:
Name Type Description
fn function

The reduce function.

list List

List of values to reduce.

Source:
Example
const add = ( x, y ) => x + y;
seedlessReduce( add, [ 1, 2, 3 ] );  //=> returns 6

then(fn, promise) → {Promise}

Executes the given function after promise finishes resolving.

Parameters:
Name Type Description
fn function

The function to execute after promise.

promise Promise

The promise to run.

Source:
Example
then( () => console.log("hello"), wait(1000) );      //=> Prints 'hello' after 1 second

wait(ms) → {Promise}

Equivalent of setTimeout but in Promise format.

Parameters:
Name Type Description
ms Number

The amount of milliseconds to wait.

Source:
Example
const sayHello = ( ) => console.log( "hello" );
wait( 1000 ).then( sayHello );                   //=> print 'hello' after 1 second