adjust(a -> a) -> Number -> [a] -> [a]src
Returns a new iterable with the given function applied to the value at the given index
adjust(x => 10 * x, 1, range(1, Infinity)) // => (1 20 3 4 5 6 7 8 9 10...)
ap[a → b] → [a] → [b]src
Applies an iterable of functions to an iterable of values
ap(of(x => x * 2, x => x + 3), oneTwoThree) // => (2 4 6 4 5 6)
appenda -> [a] -> [a]src
Returns a new iterable of the given iterable followed by the given value
append(4, [1, 2, 3]) // => (1 2 3 4)
assocNumber -> a -> [a] -> [a]src
Returns a new iterable identical to the supplied iterable except with the value at the given index replaced by the given value
assoc(2, 42, range(1, Infinity)) // => (1 2 42 4 5 6 7 8 9 10...)
concat[a] -> [a] -> [a]src
Returns a new iterable of the first given iterable followed by the second given iterable
concat([100, 200], range(1, Infinity)) // => (100 200 1 2 3 4 5 6 7 8...)
dropNumber -> [a] -> [a]src
Returns a new iterable of the given iterable without the first n elements
drop(2, range(1, Infinity)) // => (3 4 5 6 7 8 9 10 11 12...)
dropWhile(a -> Boolean) -> [a] -> [a]src
Returns a new iterable by applying the given function to each value in the given iterable only yielding values when false is returned
dropWhile(x => x <= 2, [1, 2, 3, 4, 3, 2, 1]) // => (3 4 3 2 1)
equalsa -> b -> Booleansrc
Returns true
if arguments are equivalent and false
otherwise. Equality of iterable values is determined element by element recursively and equality of non-iterable values is checked via lodash.equals
equals(range(1, 3), range(1, 3)) // => true
equals(range(1, 3), [1, 2, 3]) // => true
equals([[1, 2], 3], [[1, 2], 3]) // => true
equals([1, [2, {a: 5, b: 6}]], [1, [2, {a: 5, b: 6}]]) // => true
equals([1, [2, {a: 5, b: 6}]], [1, [2, {a: 5}]]) // => false
equals(range(1, 3), [1, 2]) // => false
every(a -> Boolean) -> [a] -> Booleansrc
Applies the given function to each value in the given iterable until that function returns falsy, in which case false is returned. If the iterable is completely traversed and falsy is never returned by the given function then true is returned
every(x => x <= 20, [1, 2, 3, 4]) // => true
every(x => x <= 2, [1, 2, 3, 4]) // => false
filter(a -> Boolean) -> [a] -> [a]src
Returns a new iterable containing only values from the given iterable where the given function applied to that value returns truthy
filter(x => x % 2 === 0, range(1, Infinity)) // => (2 4 6 8 10 12 14 16 18 20...)
See also reject
find(a -> Boolean) -> [a] -> a | undefinedsrc
Applies the given function to each value in the given iterable. If truthy is returned then find returns the value from the iterable and if the end of the iterable is reached with truthy never returned then find returns undefined
find(x => x % 2 === 0, range(1, Infinity)) // => 2
find(x => x === 0, [1, 2, 3, 4, 5, 6]) // => undefined
findIndex(a -> Boolean) -> [a] -> Numbersrc
Applies the given function to each value in the given iterable. If truthy is returned then findIndex returns the index from the iterable and if the end of the iterable is reached with truthy never returned then findIndex returns undefined
findIndex(x => x % 2 === 0, range(1, Infinity) // => 1
findIndex(x => x === 0, [1, 2, 3]) // => undefined
flatten[a] -> [b]src
Takes an iterable and recursively unnests any values which are iterables
flatten([1, [2, [3, [[4]]]], [range(1, Infinity)]) // => (1 2 4 4 1 2 3 4 5 6...)
includesa -> [a] -> Booleansrc
Checks whether the supplied iterable contains the supplied value. Equality is checked using the equals
function defined by this library
includes(10, range(1, Infinity)) // => true
includes(10, range(1, 9)) // => false
inita -> [a] -> [a]src
Returns a new iterable of all but the last element of the given iterable
init(range(1, 5)) // => (1 2 3 4)
insertNumber -> a -> [a] -> [a]src
Returns a new iterable with the given value inserted at the given index in the given iterable
insert(1, 42, range(1, Infinity)) // => (1 42 2 3 4 5 6 7 8 9...)
insertAllNumber -> [a] -> [a] -> [a]src
Returns a new iterable with the values in the first given iterable inserted at the given index in the last given iterable
insertAll(1, [42, 24, 3], [1, 2, 3]) // => (1 42 24 3 2 3)
interspersea -> [a] -> [a]src
Returns a new iterable with the given value interspersed at every other index in the given iterable
intersperse(42, range(1, Infinity)) // => (1 42 2 42 3 42 4 42 5 42...)
isEmpty[a] -> Booleansrc
Returns true if the iterable has no values in it and false otherwise
isEmpty([]) // => true
isEmpty([0]) // => false
iterableFrom[a] -> [a]src
Returns a new iterable with values identical to the given iterable
interableFrom([1, 2, 3]) // => (1 2 3)
iterate(a -> a) -> a -> [a]src
Returns an infinite iterable with the first value as the given initial value and all other values defined by applying the given function to the previous value
iterate(x => 2 * x, 1) // => (1 2 4 8 16 32 64 128 256 512...)
length[a] -> Numbersrc
Returns the number of elements in the given iterable
length(range(1, 100)) // => 100
chain(a -> [b]) -> [a] -> [b]src
Maps a function over an iterable and concatenates the results
chain(x => of(x, x), oneTwoThree) // => (1 1 2 2 3 3)
cycle[a] -> [a]src
Returns a new iterable by infinitely repeating the given iterable
cycle([1, 2, 3]) // => (1 2 3 1 2 3 1 2 3 1...)
map(a -> b) -> [a] -> [b]src
Returns a new Iterable by applying the given function to every value in the given iterable
map(x => 2 * x, range(1, Infinity)) // => (2 4 6 8 10 12 14 16 18 20...)
nthNumber -> [a] -> a | undefinedsrc
Returns the value at the given index in the given iterable, or undefined if no value exists
nth(90, range(1, Infinity)) // => 90
partition(a -> Boolean) -> [a] -> [[a] [a]]src
Returns an iterable of two iterables, the first iterable contains every value from the given iterable where the given function returns truthy and the second iterable contains every value from the given iterable where the given function returns falsy
partition(x => x % 2 === 0, [1, 2, 3, 4]) // => ((2 4) (1 3))
prependa -> [a] -> [a]src
Returns a new iterable with the given value prepended to the given iterable
prepend(42, range(1, Infinity)) // => (42 1 2 3 4 5 6 7 8 9...)
rangeNumber -> Number -> [Number]src
Returns a new iterable starting with the first given value and either descending or ascending in integer steps until the yielded value is equal to the second given value
range(1, 3)) // => (1 2 3)
range(1, Infinity)) // => (1 2 3 4 5 6 7 8 9 10...)
range(-1, -Infinity)) // => (-1 -2 -3 -4 -5 -6 -7 -8 -9 -10...)
reduce((a, b) -> a) -> a -> [b] -> asrc
Returns a value by applying the given function with the accumulated value (starting with the given initialValue) and the current value for every value in the given iterable. The value returned from each call to the given function becomes the accumulated value for the next time it is called. Similar to reduceRight
except the direction of iteration is from the beginning of the iterable to the end and the order of arguments passed to the reducer is (acc, val)
reduce((acc, val) => acc + val, 'a', ['b', 'c', 'd', 'e']) // => 'abcde'
See also reduceRight
reduceRight((a, b) -> b) -> b -> [a] -> bsrc
Returns a value by applying the given function with the accumulated value (starting with the given initialValue) and the current value for every value in the given iterable. The value returned from each call to the given function becomes the accumulated value for the next time it is called. Similar to reduce
except the direction of iteration is from the end of the iterable to the beginning and the order of arguments to the reducer function is (val, acc)
reduceRight((val, acc) => acc + val, 'a', ['e', 'd', 'c', 'b']) // => 'abcde'
See also reduce
reject(a -> Boolean) -> [a] -> [a]src
Returns a new iterable containing only values from the given iterable where the given function applied to that value returns falsy
reject(x => x % 2 === 0, range(1, Infinity)) // => (1 3 5 7 9 11 13 15 17 19...)
See also filter
removeNumber -> Number -> [a] -> [a]src
Returns an iterable of the given iterable, excluding values from the given index for the given count
remove(2, 4, range(1, Infinity)) // => (1 2 7 8 9 10 11 12 13 14...)
repeata -> [a]src
Returns an infinite iterable of the given value
repeat(42) // => (42 42 42 42 42 42 42 42 42 42...)
take(3, repeat('hi')) // => ('hi' 'hi' 'hi')
reverse[a] -> [a]src
Returns a new iterable which is the reverse of the given iterable
reverse([1, 2, 3]) // => (3 2 1)
sliceNumber -> Number -> [a] -> [a]src
Returns an iterable of the given iterable starting at the given start index and ending one before the given end index. If the start index or the end index is negative it indicates an offset from the end of the iterable exactly like native Array.prototype.slice
slice(2, 4, range(1, Infinity)) // => (3 4)
slice(0, -1, range(1, 4)) // => (1 2 3)
some(a -> Boolean) -> [a] -> Booleansrc
Applies the given function to each value in the given iterable until that function returns truthy, in which case true is returned. If the iterable is completely traversed and truthy is never returned by the given function then false is returned
some(x => x === 20, [1, 2, 3, 4]) // => false
some(x => x === 2, [1, 2, 3, 4]) // => true
sort((a, a) -> Number) -> [a] -> [a]src
Returns a new iterable of the given iterable sorted using the given function which is used for comparing elements in the same manner as the native Array.prototype.sort method
sort((a, b) => a - b, [5, 7, 3, 2]) // => (2 3 5 7)
sortBy(a -> b) -> [a] -> [a]src
Returns a new iterable of the given iterable sorted by the return value of the given function when applied to each value
sortBy(
x => x.value,
[{value: 7}, {value: 0}, {value: 7}, {value: 3}]
) // => ({value: 0} {value: 3} {value: 7} {value: 7})
splitEveryNumber -> [a] -> [[a]]src
Returns a new iterable comprised by iterables created from the given iterable of length specified by the given length
const splitEveryTwo = splitEvery(2)
splitEveryTwo([1, 2, 3, 4, 5]) // => ((1 2) (3 4) (5))
splitEveryTwo(range(1, Infinity)) // => ((1 2) (3 4) (5 6) (7 8) (9 10) (11 12) (13 14) (15 16) (17 18) (19 20)...)
sum[Number] -> Numbersrc
Returns the sum of every element in the supplied iterable
sum(of(1, 2, 3)) // => 6
tail[a] -> [a]src
Returns a new iterable of all but the first element of the given iterable
tail(range(1, Infinity)) // => (2 3 4 5 6 7 8 9 10 11...)
takeNumber -> [a] -> [a]src
Returns an iterable of the first n elements of the given iterable
take(3, range(1, Infinity)) // => (1 2 3)
takeWhile(a -> Boolean) -> [a] -> [a]src
Returns an iterable of the all elements of the given iterable until the given function returns falsy when called on the value of that element
takeWhile(x => x < 5, range(1, Infinity)) // => (1 2 3 4)
transpose[[a]] -> [[a]]src
Returns a new iterable which is a transposition of the given iterable (columns and rows swapped)
transpose([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
]) // => ((1 4 7) (2 5 8) (3 6 9))
traverseApplicative<U> → (a → U<b>) → [a] → U<[b]>src
Takes a module U
that supports the Static Land Applicative spec, a function that takes values of type a
and returns Applicatives of type b
, and an iterable of type a
and returns an Applicative from module U
of an iterable of type b
.
import Task from 'fun-task'
traverse(Task, a => Task.of(String(a * 3)), oneTwoThree) // => Task.of(('3' '6' '9'))
zip[a] -> [b] -> [[a b]]src
Returns a new iterable with values as iterables of length 2 with the first element as the corresponding element from the first given iterable and the second element as the corresponding element from the second given iterable. The length of the returned iterable is the same as the shortest iterable supplied
zip([2, 3, 5, 7], range(1, Infinity)) // => ((2 1) (3 2) (5 3) (7 4))
zipWith((a, b) -> c) -> [a] -> [b] -> [c]src
Returns a new iterable with values as the result of calling the given function with the corresponding element from the first and second given iterables respectively. The length of the returned iterable is the same as the shortest iterable supplied
zipWith((a, b) => a + b, [2, 3, 5, 7], range(1, Infinity)) // => (3 5 8 11)