Methods

inner

either(mainFn, failOver) → function()

Will evaluate the first function, if it throws any exception will evaluate the second one.

Examples

const jsonOr = either(parse.JSON,value => `Cannot parse ${value} as json`)
jsonOr(null) // -> "Cannot parse null as json"
const jsonOr = either(parse.JSON,33)
jsonOr(null) // -> 33
jsonOr('{"a":1}') // -> {a:1}

Parameters

Name Type Optional Description

mainFn

function()

 

function to be executed.

failOver

(function() or any type)

 

function or value to fail over if first one fails.

Returns

function() 

excepting to receive fn arguments.

inner

fnOrValue(fnOrVal) → any type

Given a value that can be a function if it's a function we call it passing the data to it if not we just return it

Example

fnOrValue(3,4) // -> 3
fnOrValue(4,null) // -> 4
fnOrValue(x => x+1,4) // -> 5
fnOrValue(x => x*2,4) // -> 8

Parameter

Name Type Optional Description

fnOrVal

(function() or any type)

 

a function or any value

Returns

any type 

inner

identity(x) → any type

Function that returns the passed value

Example

[1,2].map(identity) // -> [1,2]

Parameter

Name Type Optional Description

x

any type

 

any value

Returns

any type 

any value

inner

not(fn) → Boolean

Function that negates any passed function value

Example

const isNumber = not(isNaN)
isNumber(33) // -> true

Parameter

Name Type Optional Description

fn

function()

 

function to be negated

Returns

Boolean 

negated boolean value