iter
module
The iter
module contains several functions that interact with iterable
objects, like strings or arrays.
Function | Use |
---|---|
accumulate(array, function) |
Yields accumulated applications of function 2on consecutive elements of array .If for example function returned the sum of both of its arguments,then accumulate([/, /\, //, /\\, /\/], function) would yield 1 , 3 , 6 , 10 , and 15 . |
all(array) |
Returns 1 if all elements of array are truthy,0 otherwise. Returns 1 for empty arrays. |
any(array) |
Returns 1 if any of the elements of array is truthy,0 otherwise. Returns 0 for empty arrays. |
chunks(array, size) |
Iterates over array in chunks of size size .When array 's length is not evenly divided by size ,the last slice of array will be the remainder. |
cycle(iter) |
Copies an iterable by consuming it, and yields its elements in an infinite cycle. |
count(array, target) |
Returns the number of times target appears in array . |
drop_while(array, function) |
Evaluates function 1 on each item of array ,and yields elements of array starting from the first item(from the left) for which function returns a falsy value. |
filter(function, array) |
Evaluates function 1 on each item of array ,and yields those items that cause function to return a truthy value.function s taking x (≥2) arguments requireeach element of array to have x elements. |
filter_false(function, array) |
Evaluates function 1 on each item of array ,and yields those items that cause function to return a falsy value. |
find(array, target) |
Finds the first instance of target in array , and returns its index.array may be of type Array or String.If target does not appear in array , -1 is returned instead. |
find_all(array, target) |
Finds all instances of target in array , and yields their indices. |
flatten(array[, depth]) |
Flattens array depth times.By default, flattens recursively as deep as possible. |
map(function, array) |
Applies function 1 to each item of array , and yields those new values.function s taking x (≥2) arguments requireeach element of array to have x elements. |
pairwise(array) |
Yields successive overlapping pairs taken from array . |
reduce(function, array) |
Applies function 2 cumulatively to consecutive items of array ,reducing it to a single value, then returns this value. Equivalent to [i ... i ->? accumulate(array, function)]<<-/>> . |
reverse(array) |
Yields the items of array in reverse order. |
sorted(array[, key]) |
Returns a sorted copy of array .The optional parameter key specifies a function1 that is usedto extract a comparison key from each element in array .Elements are compared directly by default. |
take_while(array, function) |
Evaluates function 1 on each item of array ,and yields elements of array that is cut off at the first item(from the left) for which function returns a falsy value. |
zip_longest(fill, arrays...) |
Iterates over several arrays, producing a set of arrays containing an item from each original array. If the arrays are of uneven length, missing values are filled using the fill argument. |