Sequence is a library javascript(vanilla/pure) to functional programming
Sequence is a library javascript(vanilla/pure) that provides a "wrapper" for axillary in creating applications using functional programming techniques.
Sequence came not to reinvent the wheel or subistituir what already exists. The purpose of the Sequence is complete the default JavaScript library (which is ambudante), putting new features commonly used in functional programming.
returns true if the array is empty
[1, 2, 3].isEmpty()
false
[].isEmpty()
truereturns the first or the n elements of an array
[1, 2, 3].first() /* or [1, 2, 3].head() */
1
[1, 2, 3].first(2) /* or [1, 2, 3].head(2) */
[1, 2]returns the last or the n elements of an array
[1, 2, 3].last()
3
[1, 2, 3].last(2)
[2, 3]returns all elements except the first element
[1, 2, 3].tail()
[2, 3]remove specific element of array
[1, 2, 3].drop(2)
[1, 3]return unique values of an unsorted array
[1, 2, 1, 3, 1, 4].unique()
[1, 2, 3, 4]return values of intersection array
[1, 1, 2, 3].intersection([2, 3, 4])
[2, 3]returns the values of difference between arrays
[1, 2, 3].diff([2, 3, 4])
[1]range with a single positive argument generates an array of elements(0, 1, 2, ..., n-1)
seq.range(3)
[0, 1, 2]
seq.range(1, 3)
[1, 2]
seq.range(0, 6, 2)
[0, 2, 4]return values max of array
[2, 4, 5, 1, 3].max()
5return values min of array
[2, 4, 5, 1, 3].min()
1return average of array
[1, 2].average()
1.5return median of array
[1, 2, 3, 4, 5].median()
3return sum of array
seq.range(101).sum()
5050return product of array
[1, 2, 3, 4].product()
24return object with counter of array
["a", "a", "a", "b", "c", "b"].counter()
Object {a: 3, b: 2, c: 1}return new array flattened
[[1,2],[3,4],[5,6]].flatten()
[1, 2, 3, 4, 5, 6]zipped together arrays of different lengths
[30, 40, 50].zip(['moe', 'larry', 'curly'])
[['moe', 30], ['larry', 40], ['curly', 50]]return object with group of a specific feature
['one', 'two', 'three'].groupBy('length')
Object {3: ['one', 'two'], 5: ['three']}
[{name: 'moe', age: 40}, {name: 'larry', age: 50}, {name: 'curly', age: 60}].groupBy('age')
Object {'40': [{'name':'moe', 'age':40}],'50': [{'name':'larry', 'age':50}],'60': [{'name':'curly', 'age':60}]}return values that not filter
[-1, 1, -2, 2].filterNot(function(x){
return x > 0;
})
[-1, -2]return result of function that the transform the expression in an anonymous function
"(2 + 4) * 2".lambda()
12
"(_ + 4) * 2".lambda()(2)
12
"x -> (x + 4) * 2".lambda()(2)
12
"x -> y -> (x + y) * x".lambda()(2)(4)
12This project is licensed under the MIT License. This means you can use and modify it for free in private or commercial projects.
It is required node.js and npm
-
$ git clone https://github.com/Wellington475/SequenceJs
$ npm install
$ npm test