std:array
std:array
std:array provides immutable collection helpers for ordered data.
import Array from 'std:array'Representative API
Array.map = <T, U>(fn: (value: T): U, items: T[]): U[]Array.filter = <T>(fn: (value: T): Boolean, items: T[]): T[]Array.reduce = <T, U>(fn: (state: U, value: T): U, initial: U, items: T[]): UArray.forEach = <T>(fn: (value: T): Undefined, items: T[]): UndefinedArray.length = <T>(items: T[]): NumberArray.append = <T>(value: T, items: T[]): T[]Array.concat = <T>(right: T[], left: T[]): T[]Array.at = <T>(index: Number, items: T[]): T | NullArray.slice = <T>(start: Number, end: Number, items: T[]): T[]Array.flatMap = <T, U>(fn: (value: T): U[], items: T[]): U[]Example
names = users |> Array.filter((user) => user.active) |> Array.map((user) => user.name)Why the API looks this way
- curried by default
- data-last for pipe friendliness
- immutable updates
Comparison to JavaScript
This module replaces prototype calls such as .map, .filter, and .reduce.