An interpreted programming language written in Go.
This module contains several utility and convenience functions for managing and working with collections such as arrays and maps.
To use: import 'std/collections'
map
applies the function fn
on each element of arr
and returns a new array
with the returned elements.
filter
applies the function fn
on each element of arr
and returns a new array
containing the elements of arr
where fn
returned true.
reduce
applies a function against an accumulator and each element in the array/map
col
(from left to right) to reduce it to a single value.
DEPRECATED: Use for..in loop instead.
foreach
will iterate over the supplied collection calling fn
on each element.
The function fn
is given the index or map key and the element value. Returned
values are ignored. To actually modify the element, use the map()
function
instead.
arrayMatch
returns if arr1
and arr2
have the same length and all elements match
in order. If the arrays have the same elements but in different orders, arrayMatch
will return false.
mapMatch
returns if map1
and map2
have the same length and all elements match.
mapMatch
will recursively check nested maps and arrays.
contains
searches haystack
for needle
and returns true if the needle is in the
array, false otherwise. If haystack
is a map, then contains
returns if the map
has a key needle
.
Joins the elements in arr
separated by separator
.
’’’ join(‘, ‘, [“hello”, “world”]) == “hello, world” ‘’’
If the collection has key
, then return the mapped value. Otherwise, returns
default
.
’’’ getOrDefault({“a”: 1}, “a”, 2) == 1 getOrDefault({“a”: 1}, “b”, 2) == 2 ‘’’