7b5d207914
* fix documentation for enum.filter fixes https://github.com/d5/tengo/issues/358 * update stdlib code comment for enum.filter
2.3 KiB
2.3 KiB
Module - "enum"
enum := import("enum")
Functions
all(x, fn) => bool
: returns true if the given functionfn
evaluates to a truthy value on all of the items inx
. It returns undefined ifx
is not enumerable.any(x, fn) => bool
: returns true if the given functionfn
evaluates to a truthy value on any of the items inx
. It returns undefined ifx
is not enumerable.chunk(x, size) => [object]
: returns an array of elements split into groups the length of size. Ifx
can't be split evenly, the final chunk will be the remaining elements. It returns undefined ifx
is not array.at(x, key) => object
: returns an element at the given index (ifx
is array) or key (ifx
is map). It returns undefined ifx
is not enumerable.each(x, fn)
: iterates over elements ofx
and invokesfn
for each element.fn
is invoked with two arguments:key
andvalue
.key
is an int index ifx
is array.key
is a string key ifx
is map. It does not iterate and returns undefined ifx
is not enumerable.`filter(x, fn) => [object]
: iterates over elements ofx
, returning an array of all elementsfn
returns truthy for.fn
is invoked with two arguments:key
andvalue
.key
is an int index ifx
is array. It returns undefined ifx
is not array.find(x, fn) => object
: iterates over elements ofx
, returning value of the first elementfn
returns truthy for.fn
is invoked with two arguments:key
andvalue
.key
is an int index ifx
is array.key
is a string key ifx
is map. It returns undefined ifx
is not enumerable.find_key(x, fn) => int/string
: iterates over elements ofx
, returning key or index of the first elementfn
returns truthy for.fn
is invoked with two arguments:key
andvalue
.key
is an int index ifx
is array.key
is a string key ifx
is map. It returns undefined ifx
is not enumerable.map(x, fn) => [object]
: creates an array of values by running each element inx
throughfn
.fn
is invoked with two arguments:key
andvalue
.key
is an int index ifx
is array.key
is a string key ifx
is map. It returns undefined ifx
is not enumerable.key(k, _) => object
: returns the first argument.value(_, v) => object
: returns the second argument.