collection library for javascript
fold<U>(f: (accumulator: U, element: T) => U, initialValue: U): U
reduces a list with an initial value.
const list = new List([1, 2, 3])
const result = list.fold((a, b) => a + b, "N")
//result: "N123"
forEach(f: (element: T) => any): void
applies a function to each elements from a collection
const list = new List([1, 2, 3])
list.forEach(x => console.log(`number: ${x}`))
//number: 1
//number: 2
//number: 3
map<U>(f: (element: T) => U): List<U>
applies a function to each elements from a collection and store each result
const list = new List([1, 2, 3])
const result = list.map(x => x * 2)
//result: [2, 4, 6]
reduce(f: (accumulator: T, element: T) => T): T
reduces a list
const list = new List([1, 2, 3])
const result = list.reduce((a, b) => a + b)
//result: 6