iter

stdlib::rss::iter

Range, collection traversal, transformation, filtering, and reduction helpers.

Import

use stdlib::rss::iter;

Functions

FunctionDescription
range_stepReturns an array of numbers from start to stop using the given step.
rangeReturns an array of numbers from 0 up to stop.
enumerateReturns [index, value] pairs for an array.
zipZips two arrays into [lhs, rhs] pairs up to the shorter length.
takeReturns the first count values from an array.
skipReturns an array without the first count values.
chunkSplits an array into fixed-size chunks.
sumReturns the sum of numeric values.
any_trueReturns whether any value in an array is truthy.
all_trueReturns whether every value in an array is truthy.
mapApplies a function to each value in an array.
filterReturns the values for which pred(value) is true.
reduceReduces an array by applying func(acc, value) from left to right.
eachCalls a function for each value in an array and returns null.

Function details

range_step

pub fn range_step(start: int, stop: int, step: int) -> [int]

Returns an array of numbers from start to stop using the given step.

range

pub fn range(stop: int) -> [int]

Returns an array of numbers from 0 up to stop.

enumerate

pub fn enumerate<T>(values: [T]) -> [[int, T]]

Returns [index, value] pairs for an array.

zip

pub fn zip<L, R>(lhs: [L], rhs: [R]) -> [[L, R]]

Zips two arrays into [lhs, rhs] pairs up to the shorter length.

take

pub fn take<T>(values: [T], count: int) -> [T]

Returns the first count values from an array.

skip

pub fn skip<T>(values: [T], count: int) -> [T]

Returns an array without the first count values.

chunk

pub fn chunk<T>(values: [T], size: int) -> [[T]]

Splits an array into fixed-size chunks.

sum

pub fn sum(values: [number]) -> number

Returns the sum of numeric values.

any_true

pub fn any_true(values: [bool]) -> bool

Returns whether any value in an array is truthy.

all_true

pub fn all_true(values: [bool]) -> bool

Returns whether every value in an array is truthy.

map

pub fn map<T, U>(values: [T], func: fn(T) -> U) -> [U]

Applies a function to each value in an array.

filter

pub fn filter<T>(values: [T], pred: fn(T) -> bool) -> [T]

Returns the values for which pred(value) is true.

reduce

pub fn reduce<T, U>(values: [T], init: U, func: fn(U, T) -> U) -> U

Reduces an array by applying func(acc, value) from left to right.

each

pub fn each<T, U>(values: [T], func: fn(T) -> U) -> null

Calls a function for each value in an array and returns null.