Methods
add(a, b) → {Number}
Returns the sum of the 2 arguments
- Since:
- v1.0.2
- Source:
Parameters:
Name | Type | Description |
---|---|---|
a |
Number
|
|
b |
Number
|
Returns:
- Type:
-
Number
addIndex(f, g, a) → {Array}
Adds a specified index to iterate a collection
Adds a specified index to iterate a collection
- Since:
- 1.0.2
- Source:
Parameters:
Name | Type | Description |
---|---|---|
f |
function
|
Iterator function |
g |
function
|
Function to which to add the index |
a |
Array
|
The array on which to work |
Returns:
- Type:
-
Array
Example
const array = [1, 2, 3, 4]
addIndex(map, (v, i) => v + i, array) // [1, 3, 5, 7]
adjust(fn, i, a) → {Array}
Modifies an item in an array using the provided function
Parameters:
Name | Type | Description |
---|---|---|
fn |
function
|
to modify the item at the specified index |
i |
Number
|
The index at which to modify the array, accepts postitive and negative indexes |
a |
Array
|
Array with data |
Returns:
- Type:
-
Array
Array with the adjusted item
Example
adjust(add(1), -3, [0, 1, 2, 3]) // [0, 2, 2, 3]
const addTen = add(10)
adjust(addTen, 2, [2, 3, 4, 5, 6]) // [2, 3, 14, 5, 6]
adjustWith(fn, pred, aopt) → {Iterable}
Modifies an item in an array using the provided function
- Since:
- v1.0.2
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fn |
function
|
to modify the item at the specified index | |
pred |
function
|
The predicate that returns the indexes if found | |
a |
Iterable
|
<optional> |
Returns:
- Type:
-
Iterable
[a]
all(cb, a) → {Boolean}
Returns true if all items in the enumerable match the predicate
Parameters:
Name | Type | Description |
---|---|---|
cb |
function
|
|
a |
Iterable
|
Returns:
- Type:
-
Boolean
allPass(predicates) → {function}
Applies a list of predicates to the data and returns true if all pass
- Since:
- v1.0.2
- Source:
Parameters:
Name | Type | Description |
---|---|---|
predicates |
Array
|
An array of predicates to check |
Returns:
- Type:
-
function
The combined predicate
always(a) → {function}
Returns a function with the initial value provided
Parameters:
Name | Type | Description |
---|---|---|
a |
*
|
Returns:
- Type:
-
function
and(x, y) → {boolean}
Checks if both predicates are true
Parameters:
Name | Type | Description |
---|---|---|
x |
*
|
A predicate |
y |
*
|
A predicate |
Returns:
- Type:
-
boolean
any(cb, a) → {Boolean}
Returns true if at least on of the items in the enumerable match the predicate
Parameters:
Name | Type | Description |
---|---|---|
cb |
function
|
|
a |
Iterable
|
Returns:
- Type:
-
Boolean
anyPass(predicates) → {function}
Applies a list of predicates to the data and returns true if one passes
- Since:
- v1.0.2
- Source:
Parameters:
Name | Type | Description |
---|---|---|
predicates |
Array
|
An array of predicates to check |
Returns:
- Type:
-
function
The combined predicate
ap(fns, vals) → {Iterable}
Applies a list of functions to a list of values and returns a combined result array
Parameters:
Name | Type | Description |
---|---|---|
fns |
Array.<function()>
|
function
|
Applicative
|
An array of functions or a function or an applicative |
vals |
Array
|
An array of values |
Returns:
- Type:
-
Iterable
[a]
aperture(n, arr) → {*}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
n |
||
arr |
Returns:
- Type:
-
*
append(el, list) → {Array}
Append an elment to a list
Parameters:
Name | Type | Description |
---|---|---|
el |
*
|
Element to add to a list |
list |
Array
|
List to which to add the element |
Returns:
- Type:
-
Array
Example
const l = [0, 1]
append('a', l) // reutnr [0, 1, 'a']
apply(fn, args) → {*}
The apply() method calls a function with the given arguments provided as an array, and the function as context.
Parameters:
Name | Type | Description |
---|---|---|
fn |
||
args |
Returns:
- Type:
-
*
Example
var a = apply(function () {
return [].slice.call(arguments).map(x => x * 2)
})
a([1, 2, 3])
// [2, 4, 6]
arrayConcat(a1, a2) → {Array.<T>}
Autocurried concatenation function using native concat
- Source:
Parameters:
Name | Type | Description |
---|---|---|
a1 |
Array
|
Left side of the concatenation |
a2 |
Array
|
Right side of the concatenation |
Returns:
- Type:
-
Array.<T>
Example
const startsWithZero = concat([0])
const OneTwoThree = startsWithZero([1, 2, 3])
// [0, 1, 2, 3]
arrayFilter(fn, a) → {Array}
Autocurried function to filter an array
- Source:
Parameters:
Name | Type | Description |
---|---|---|
fn |
function
|
Predicate function |
a |
Array
|
Array to filter |
Returns:
- Type:
-
Array
binary(cb) → {function}
Parameters:
Name | Type | Description |
---|---|---|
cb |
Returns:
- Type:
-
function
bind(fn, context) → {*}
Bind a function to a context
Parameters:
Name | Type | Description |
---|---|---|
fn |
function
|
|
context |
*
|
Returns:
- Type:
-
*
complement(A) → {function}
Lifts a predicate function and returns the complement
- Since:
- v1.0.2
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
A |
function
|
predicate function |
Returns:
- Type:
-
function
Example
const isNotEmpty = complement(isEmpty)
isNotEmpty([]) // false
isNotEmpty({'a' : 1}) // true
complement(Maybe.of(false)) // true
complement(Maybe.of(true)) // false
concat(a, b) → {a}
Concatenates 2 items together
Parameters:
Name | Type | Description |
---|---|---|
a |
a
|
Left side of the concatenation |
b |
a
|
right side of the concatenation |
Returns:
- Type:
-
a
Concatenated item
cond(conds) → {function}
Parameters:
Name | Type | Description |
---|---|---|
conds |
Returns:
- Type:
-
function
defaultTo(default, val) → {*}
Returns true if all items in the enumerable match the predicate
- Since:
- v1.0.2
- Source:
Parameters:
Name | Type | Description |
---|---|---|
default |
a
|
The default value. |
val |
b
|
`val` will be returned instead of `default` unless `val` is `null`, `undefined` or `NaN`. |
Returns:
- Type:
-
*
The second value if it is not `null`, `undefined` or `NaN`, otherwise the default value
diffDate(start, end) → {number}
Returns the difference between 2 dates in millisecond
- Source:
Parameters:
Name | Type | Description |
---|---|---|
start |
Date
|
Start date |
end |
Date
|
End date |
Returns:
- Type:
-
number
REturn the difference in milliseconds
divide(a, b) → {Number}
Returns the division of the 2 arguments
- Since:
- v1.0.2
- Source:
Parameters:
Name | Type | Description |
---|---|---|
a |
Number
|
|
b |
Number
|
Returns:
- Type:
-
Number
equals(x, y) → {boolean}
Autocurried function that checks for equality of 2 items
Parameters:
Name | Type | Description |
---|---|---|
x |
*
|
Left side of the equality check |
y |
*
|
Right side of the equality check |
Returns:
- Type:
-
boolean
Example
const nan = Number.NaN
equal(nan, nan) // returns true
const arr1 = [0, 1, 2, 3]
const arr2 = [null, 1, 2, 3]
equals(arr1, arr2) // returns false
equals(new Object({'a': 0, 'b': 1}), {'a': 0, 'b': 1}) // true
equals(x, y) → {boolean}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
x |
Object
|
|
y |
Object
|
Returns:
- Type:
-
boolean
equalsArray(x, y) → {boolean}
Autocurried function for deep comparison of arrays
- Source:
Parameters:
Name | Type | Description |
---|---|---|
x |
a
|
Object to compare of type a |
y |
a
|
Object x to compare with object x |
Returns:
- Type:
-
boolean
exists(x)
Validates if a value is not null or undefined
Parameters:
Name | Type | Description |
---|---|---|
x |
*
|
any valid Javascript value |
Example
exists(null) // false
exists([] // true
F(a) → {function}
Always returns a function with a False boolean
- Since:
- v1.0.2
- Source:
Parameters:
Name | Type | Description |
---|---|---|
a |
*
|
Returns:
- Type:
-
function
findIndex(Predicate, An) → {number}
Find the index matching a predicate
- Since:
- v1.0.2
- Source:
Parameters:
Name | Type | Description |
---|---|---|
Predicate |
function
|
function returns a boolean |
An |
Array
|
array like object |
Returns:
- Type:
-
number
first(aopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
a |
<optional> |
Returns:
a | undefined
Example
const arr = [1, 2, 4]
first([1, 2, 4]) // returns 1
fold(cb, init, a) → {*}
Autocurried function which returns a single item by mapping over the provided array and calls an iterator function
- Since:
- 1.0.2
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
cb |
cbFunction
|
Callback function to modify the item |
init |
*
|
Initial value |
a |
Array
|
Array with items to modify by the cb function |
Returns:
- Type:
-
*
Example
const result = fold(add, 0, [1,1,1])
// result = 3
fold(cb, init, a) → {*}
Autocurried function which returns a single item by mapping over the provided string and calls an iterator function
- Since:
- 1.0.5
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
cb |
cbFunction
|
Callback function to modify the item |
init |
*
|
Initial value |
a |
String
|
Array with items to modify by the cb function |
Returns:
- Type:
-
*
Example
const result = fold(filterA, 0, "abc")
// result = "bc"
fold(cb, init, a) → {*}
Returns a single item by iterating over an array like object and call a function on each item
Parameters:
Name | Type | Description |
---|---|---|
cb |
function
|
receives 4 values: the accumulator, the item, the index, and the initial value. |
init |
*
|
the the initial value |
a |
Array
|
Object
|
the array like item to iterate over |
Returns:
- Type:
-
*
The accumulated value
formatDateTime(format, date) → {string}
Formats a date object using a format string
- Source:
Parameters:
Name | Type | Description |
---|---|---|
format |
string
|
Format date string |
date |
date
|
Date object to format |
Returns:
- Type:
-
string
Example
const formattedDate = formatDateTime('DD-MM-YYYY', new Date('1999-12-31'))
console.log(formattedDate) // 31-12-1999
getWeek(d) → {Array.<number>}
Returns the week number based on a given date
- Source:
Parameters:
Name | Type | Description |
---|---|---|
d |
Returns:
- Type:
-
Array.<number>
isArray(Object) → {boolean}
Function Checks if the provided object is an array
- Since:
- 1.0.2
- Source:
Parameters:
Name | Type | Description |
---|---|---|
Object |
*
|
to verifiy |
Returns:
- Type:
-
boolean
Example
const result = isArray([1,1,1])
// result = true
isIterator(iter) → {boolean}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
iter |
iterator
|
Accepts an iterator which can be an array, map or any other custo, implemented iterator |
Returns:
- Type:
-
boolean
isObject() → {boolean}
- Source:
Parameters:
Type | Description |
---|---|
*
|
Returns:
- Type:
-
boolean
keys(obj) → {Iterable}
Autocurried function which returns the keys of the provided object or iterator
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object
|
Obj from zhich to take the keys |
Returns:
- Type:
-
Iterable
last(aopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
a |
<optional> |
Returns:
a | undefined
lift()
"lifts" a function of arity > 1 so that it may "map over" a list, Function
lt(a, b) → {boolean}
Returns a Boolean indicating one value is larger than the other
Parameters:
Name | Type | Description |
---|---|---|
a |
*
|
Any valid Javascript value |
b |
*
|
Any valid Javascript value |
Returns:
- Type:
-
boolean
Example
lt(0, 10) // true
const lt0 = lt(0)
lt0(10) // false
lte(a, b) → {boolean}
Returns a Boolean indicating one value is larger than or equal to the other
Parameters:
Name | Type | Description |
---|---|---|
a |
*
|
Any valid Javascript value |
b |
*
|
Any valid Javascript value |
Returns:
- Type:
-
boolean
Example
lte(0, 10) // true
const lte0 = lte(0)
lt0(10) // false
lt0(0) // true
map(cb, a) → {Iterable}
Maps over an array and applies a function
- Since:
- v1.0.2
- Source:
Parameters:
Name | Type | Description |
---|---|---|
cb |
function
|
|
a |
Iterable
|
Returns:
- Type:
-
Iterable
Example
const result = map(identity, [0,2,3])
// result = [0,2,3]
const add2 = add(2)
const result = map(add2, [0,2,3])
// result = [2,4,5]
map(cb, a) → {Iterable}
Autocurried function which maps over an iterable.
Parameters:
Name | Type | Description |
---|---|---|
cb |
function
|
|
a |
Iterable
|
Returns:
- Type:
-
Iterable
max(a, b) → {*}
Returns the largest of the 2 arguments provided
Parameters:
Name | Type | Description |
---|---|---|
a |
*
|
|
b |
*
|
Returns:
- Type:
-
*
min(a, b) → {*}
Returns the smallest of the 2 arguments provided
Parameters:
Name | Type | Description |
---|---|---|
a |
*
|
|
b |
*
|
Returns:
- Type:
-
*
objectMerge(objL, objR) → {boolean}
Recursively merges 2 objects
- Source:
Parameters:
Name | Type | Description |
---|---|---|
objL |
Object
|
|
objR |
Object
|
Returns:
- Type:
-
boolean
omit(obj, names)
Removes one ore more properties from an object by name of the key
- Source:
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object
|
The object form which to remove the key value pair |
names |
Array.<string>
|
an array of keys to be removed from the object |
path(path, An)
Returns the value of a property identified by a number of nested key values
- Source:
Parameters:
Name | Type | Description |
---|---|---|
path |
Array
|
Array of key values |
An |
Object
|
Array
|
object or an array from which to retrieve the keys |
Example
let t = {
a: {
b : [0, 1]
},
b : 1
}
const v = path(['a', 'b', 0], t)
v === 0
pick(props, obj) → {Object}
returns a new bject with only the props that are provided
- Source:
Parameters:
Name | Type | Description |
---|---|---|
props |
Array
|
Array of property names |
obj |
Object
|
The object from which to take the properties |
Returns:
- Type:
-
Object
prop()
- Source:
reduce(cb, a) → {*}
Returns a single item by iterating over an array like object and call a function on each item, starting from the first item in the iterator
Parameters:
Name | Type | Description |
---|---|---|
cb |
function
|
receives 4 values: the accumulator, the item, the index, and the initial value. |
a |
Array
|
The iterator to apply the function |
Returns:
- Type:
-
*
sort(comp, a) → {Array}
Returns a copy of the list, sorted according to the function.
Parameters:
Name | Type | Description |
---|---|---|
comp |
function
|
A sorting function |
a |
Array
|
The list to sort |
Returns:
- Type:
-
Array
a new array with its elements sorted by the comp function.
Example
const diff = function(a, b) { return a - b; };
sort(diff, [4,2,7,5]); //=> [2, 4, 5, 7]
T(a) → {function}
Always returns a function with a False boolean
- Since:
- v1.0.2
- Source:
Parameters:
Name | Type | Description |
---|---|---|
a |
*
|
Returns:
- Type:
-
function
toArray(x) → {Array}
Converts the input to an array
- Since:
- 1.0.2
- Source:
Parameters:
Name | Type | Description |
---|---|---|
x |
ArrayLike
|
Object to convert to an array |
Returns:
- Type:
-
Array
Example
const result = toArray("string")
// result = ['s','t','r','i','n','g']
function () {
const args = toArray(arguments)
console.log(typeof args) // Array
}
truthy(x)
Validates if a value exists and is not false
Parameters:
Name | Type | Description |
---|---|---|
x |
*
|
Any valid javascript value |
Example
truthy([]) // true
truthy(0) // true
truthy(-1) // true
truthy(false) // false
truthy(null) // false
truthy(undefined) // false
type(a) → {Boolean}
Returns the type of the passed value
Parameters:
Name | Type | Description |
---|---|---|
a |
*
|
Any valid javascript value |
Returns:
- Type:
-
Boolean
Example
const isArray = (arr) => type(arr) === 'Array'
isArray([]) // true
unionArray(aL, aR) → {Array}
Merges 2 arrays
- Since:
- 1.0.2
- Source:
Parameters:
Name | Type | Description |
---|---|---|
aL |
Array
|
Array to merge |
aR |
Array
|
Array to merge |
Returns:
- Type:
-
Array
Example
const result = unionArray([0,1,2], [3,4,5])
// result = [0.1.2.3.4.5]
values() → {Array}
REturns a list of values taken from an objects own properties
- Source:
Parameters:
Type | Description |
---|---|
Object
|
obj The object from which to take the values |
Returns:
- Type:
-
Array
zip(a, b) → {Array}
Autocurried function that zips 2 arrays into an Array of pairs
Parameters:
Name | Type | Description |
---|---|---|
a |
Array
|
Array to zip |
b |
Array
|
Array to zip |
Returns:
- Type:
-
Array
Example
const a = [1, 2, 3]
const b = [100, 200, 300]
zip(a, b) // [[100, 1], [200, 2], [300, 3]]
zipObj(a, b) → {Object}
Autocurried function that zips 2 Arrays into 1 Object
Parameters:
Name | Type | Description |
---|---|---|
a |
Array
|
Array containing the keys of the returned object |
b |
Array
|
Array containing the values of the returned object |
Returns:
- Type:
-
Object
Example
const keys = ['a', 'b', 'c']
const values = [0, 1, 2]
zipObj(keys, values // {'a': 0, 'b': 1, 'c': 2}
zipWith(cb, a, b) → {Array}
Combines the values of 2 arrays into 1 array using a callback function
- Source:
Parameters:
Name | Type | Description |
---|---|---|
cb |
function
|
Callback function accepting 2 parameters |
a |
Array
|
Array to zip |
b |
Array
|
Array to zip |
Returns:
- Type:
-
Array
Example
const a = [1, 2, 3]
const b = [100, 200, 300]
zipWith(add, a, b) // [101, 202, 303]
Type Definitions
cbFunction(r, item, index, a) → {*}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
r |
*
|
Accumulator which accumulates the callback's return values |
item |
*
|
the current element being processed |
index |
number
|
the indey of the item being processed |
a |
Array
|
The initial array |
Returns:
- Type:
-
*
cbFunction(r, item, index, a) → {*}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
r |
*
|
Accumulator which accumulates the callback's return values |
item |
*
|
the current element being processed |
index |
number
|
the indey of the item being processed |
a |
String
|
The initial string |
Returns:
- Type:
-
*