Light Dark

Types

Iter core

fn (v: Vec): Iter

Iterator type constructor - creates a lazy iterator from Vec, Map, or Str.

Example

it Iter([1, 2, 3])
is-iter(it)  // true
collect(it)  // [1, 2, 3]

Next core

Next type {
    value: Any,
    done: Bool
}

Result type from calling next on an iterator.

Fields

  • value - The current value (null if done)
  • done - Whether the iterator is exhausted

Functions

collect core

fn (iter: Any): Vec

Collect all values from an iterator into a vector.

Warning: This will block until the iterator is exhausted. For infinite or long-running iterators, use for-each or take instead.

Example

iter Iter([1, 2, 3])
next(iter)        // consume first value
collect(iter)     // [2, 3]

for-each core

fn (coll: Any, f: Fn): Null

Apply a function to each value from an iterable.

Accepts Vec, Map, Str, or Iter. Auto-converts to Iter if needed. Uses tail-call optimization for efficient iteration.

Example

for-each([1, 2, 3], fn (x) { print(x) })

is-iter core

fn (value: Any): Bool

Check if a value is an Iter.

Example

it Iter([1, 2, 3])
is-iter(it)           // true
is-iter([1, 2, 3])    // false

next core

fn (iter: Any): Next

Get the next value from an iterator.

Returns a Next result with the next value and a done flag.

Example

iter Iter([1, 2, 3])

first next(iter)
first.value   // 1
first.done    // false

second next(iter)
second.value  // 2

// After exhaustion
// result.done is true, result.value is null

take core

fn (coll: Any, n: Int): Vec
fn (iter: Iter, n: Int, count: Int, acc: Vec): Vec

Take the first n values from an iterable.

Accepts Vec, Map, Str, or Iter. Returns a vector with at most n values.

Example

take([1, 2, 3, 4, 5], 3)  // [1, 2, 3]
take(range(1000), 5)      // [0, 1, 2, 3, 4]

$var_0

fn (m: Map): Iter

$var_1

fn (s: Str): Iter

$var_2

fn (it: Iter): Iter

$var_3

fn (start: Int, end: Int): Any

$var_4

fn (end: Int): Any

range

fn (start: Int, end: Int, step: Int): Any

Create a lazy range iterator over integers.

Example

numbers ::hot::iter/range(1, 10001)
sum ::hot::coll/reduce(numbers, fn (acc, n) { ::hot::math/add(acc, n) }, 0)