flatMap

Maps each element of the Collection to a Collection of values and then flattens them into a single List.

Syntax

flatMap<R>(mapper(item : Collection<?>) : Collection<R>) : List<R>

Example

var items = {{1},{2,2},{3,3,3},{4,4,4,4}}
print(items.flatMap(\ ___item -> ___item))
Output
[1, 2, 2, 3, 3, 3, 4, 4, 4, 4]

fold

Accumulates the values of an Collection into a single T.

Syntax

fold(aggregator(aggregate : T, item : T) : T) : T

Example

var items = {{1},{2,2},{3,3,3},{4,4,4,4}}
var flatItems = items.flatMap(\ ___item -> ___item)
print(flatItems.fold(\ ___aggr, ___item -> ___aggr + ___item))
Output
30

intersect

Returns a Set that is the intersection of the two Collection objects.

Syntax

intersect(that: Collection<T>) : Set<T>

Example

var items1 = {1,2,3,4,5,6}
var items2 = {4,5,6,7,8,9}
print(items1.intersect(items2))
Output
[4, 5, 6]

map

Returns a List of each element of the Collection mapped to a new value.

Syntax

map<Q>(mapper(item : <INPUT>) : <Q>) : List<Q>

Example

var numbers = {1,2,3}
var words = {"one","two","three"}
print(numbers.map(\ ___number -> words[___number-1]))
Output
[one, two, three]

partition

Partitions this Collection into a Map of keys to a list of elements in this Collection.

Syntax

partition<Q>(partitioner(item : R) : Q) : Map<Q, List<R>>

Example

var numbers = {1,2,3,4,5,6,8}
print(numbers.partition<String>(\ ___number -> ___number % 2 == 0 ? "even" : "odd"))
Output
{even=[2, 4, 6, 8], odd=[1, 3, 5]}

reduce

Accumulates the values of a Collection into a single V given an initial seed value

Syntax

reduce<T>(init : T, aggregrator(aggregate: T, item : ?) : T) : T

Example

var numbers = {1,2,3,4,5,6,8}
var sumOfNumbers = numbers.reduce(0, \ ___aggr, ___number -> ___aggr + ___number)
print(sumOfNumbers)
Output
29

union

Returns a new Set that is the union of the two Collections

Syntax

union(that : Collection<T>) : Set<T>

Example

var items1 = {1,2,3,4,5,6}
var items2 = {4,5,6,7,8,9}
print(items1.union(items2))
Output
[1, 2, 3, 4, 5, 6, 7, 8, 9]

disjunction

Returns a new Set that is the set disjunction of this collection and the other collection

Syntax

disjunction(that : Collection<T>) : Set<T>

Example

var items1 = {1,2,3,4,5,6}
var items2 = {4,5,6,7,8,9}
print(items1.disjunction(items2))
Output
[1, 2, 3, 7, 8, 9]

join

Joins all elements together as a string with a delimiter

Syntax

join(delim : String) : String

Example

var words = {"Hello", "World"}
print(words.join(" "))
Output
Hello World