Packages

builtin
cbindgen
core
core.alloc
core.alloc.arena
core.alloc.atomic
core.alloc.fixed
core.alloc.gc
core.alloc.heap
core.alloc.log
core.alloc.memdebug
core.alloc.pool
core.alloc.ring
core.arg_parse
core.array
core.avl_tree
core.bucket_array
core.conv
core.doc
core.encoding
core.encoding.base64
core.encoding.csv
core.encoding.hex
core.encoding.json
core.encoding.kdl
core.encoding.osad
core.encoding.utf8
core.hash
core.hash.md5
core.hash.sha1
core.hash.sha256
core.heap
core.intrinsics
core.intrinsics.atomics
core.intrinsics.onyx
core.intrinsics.types
core.intrinsics.wasm
core.io
core.io.binary
core.iter
core.js
core.list
core.map
core.math
core.memory
core.misc
core.net
core.os
core.random
core.set
core.slice
core.string
core.sync
core.test
core.thread
core.time
main
runtime
runtime.info
runtime.platform
runtime.vars
simd

package core.iter

as_iter
as_iter :: (list: &List) -> #auto
as_iter :: (s: &Set) -> #auto
as_iter :: (b: &Bucket_Array($T)) -> Iterator(T)
as_iter :: (arr: [] $T) -> #auto
    where type_is_struct(T)
as_iter :: (arr: [] $T, by_pointer: bool) -> #auto
as_iter :: (arr: [] $T) -> #auto
as_iter :: (arr: [] $T) -> #auto
    where type_is_struct(T)
as_iter :: (arr: [] $T, by_pointer: bool) -> #auto
as_iter :: (arr: [] $T) -> #auto
as_iter :: macro (x: &[..] $T) -> #auto
as_iter :: macro (x: &[..] $T, by_pointer: bool) -> #auto
as_iter :: (r: range) -> Iterator(i32)
as_iter :: (r: range64) -> Iterator(i64)
as_iter :: (x: &$T) -> #auto
    where ImplicitIterator(T)
as_iter :: macro (x: $T) -> #auto
    where HasAsIter(T)

The standard function to convert something to an Iterator. For-loops currently do not use this function to determine how to iterate over something unknown, but that could be a feature down the line.

close
close :: (it: Iterator) -> void

Helper function to close an iterator, if a close function is defined.

collect
collect :: (it: Iterator($T), allocator) -> [..] T

Collects elements into an array, or a map, depending on if the iterator produces a Pair(K, V) or not.

comp
comp :: macro (i: Iterator(&$V), value: Code) -> #auto
comp :: macro (i: Iterator($V), value: Code) -> #auto
comp :: macro (i: $I, value: Code) -> #auto
    where Iterable(I)

Simple iterator comprehensions, in the same vein as Pythons comprehension syntax.

Python:

results = [it * 2 for it in [1, 2, 3, 4, 5]]

Onyx:

results := iter.comp(u32.[1, 2, 3, 4, 5], [it](it * 2));
concat
concat :: (iters: ..Iterator($T)) -> Iterator(T)

Combines iterators by first yielding all values from one, then yielding all values from the next, and so on.

const
const :: (value: $T) -> Iterator(T)

Yields the same value indefinitely. Useful with iter.zip.

count
count :: macro (it: $T, cond: $F) -> #auto
    where Iterable(T)
count :: (it: Iterator($T), cond: (T) -> bool) -> i32

Returns how many times the cond was true.

counter
counter :: (start: type, $type: type_expr) -> Iterator(type)

Helper function to create an infinite counting iterator.

Use start to configure the starting value.

Use type to configure the type used for the iterator.

distributor
distributor :: macro (it: $T) -> #auto
    where Iterable(T)
distributor :: (it: Iterator) -> Iterator(it.Iter_Type)
empty
empty :: ($T: type_expr) -> Iterator(T)

Helper function to create an iterator of a type that does not produce an values.

enumerate
enumerate :: macro (it: $T, start_index: i32) -> #auto
    where Iterable(T)
enumerate :: (it: Iterator($T), start_index: i32) -> Iterator(CALL)

Yields a value that contains:

1) the value from the iterator,
2) an incrementing integer.
every
every :: macro (it: $T, cond: $F) -> #auto
    where Iterable(T)
every :: (it: Iterator($T), cond: (T) -> bool) -> bool

Returns if cond returned true for all yielded values.

filter
filter :: (it: Iterator($T), predicate: (T) -> bool) -> #auto
filter :: (it: Iterator($T), ctx: $Ctx, predicate: (T, Ctx) -> bool) -> #auto

Only yields the values for which the predicate is true.

find
find :: macro (it: $T, predicate: $F) -> #auto
    where Iterable(T)
find :: (it: Iterator($T), predicate: (T) -> bool) -> ? T
flat_map
flat_map :: (it: Iterator($T), transform: (T) -> Iterator($R)) -> #auto
flat_map :: (it: Iterator($T), ctx: $Ctx, transform: (T, Ctx) -> Iterator($R)) -> #auto

Transforms every value that comes out of an iterator using the transform function into a new iterator, from which subsequent values will be output.

iter.flat_map(iter.as_iter(1 .. 5), x => iter.as_iter(1 .. x+1))
// 1, 1, 2, 1, 2, 3, 1, 2, 3, 4
flatten
flatten :: (i: Iterator($T), f: (T) -> ? $R) -> Iterator(R)

Filters and maps at the same time.

If the provided function returns a None variant of Optional, then the entry is discarded.

If the provided function returns Some(x), then x is yielded.

fold
fold :: macro (it: $T, init: $R, combine: $S) -> #auto
    where Iterable(T)
fold :: (it: Iterator($T), initial_value: $R, combine: (T, R) -> R) -> R

Incremently calls combine on the yielded value and the accumulated value, producing a new accumulated value. Returns the final accumulated value.

fold1
fold1 :: macro (it: $T, combine: $S) -> #auto
    where Iterable(T)
fold1 :: (it: Iterator($T), combine: (T, T) -> T) -> ? T

Incremently calls combine on the yielded value and the accumulated value, producing a new accumulated value. Returns the final accumulated value.

from_array
from_array :: (arr: [] $T) -> #auto
    where type_is_struct(T)
from_array :: (arr: [] $T, by_pointer: bool) -> #auto
from_array :: (arr: [] $T) -> #auto

from_array has two almost identical implementations, but the details are important here. Normally, from_array returns an iterator by value, unless the array is of structures, then it returns an iterator by pointer. This seems weird, but in practice it is closer to what you want, as you don't want to have to copy every structure out of the array. While for primitives, you don't want to dereference it everywhere.

generator
generator :: (ctx: &$Ctx, gen: (&Ctx) -> ? $T) -> Iterator(T)
generator :: (ctx: &$Ctx, gen: (&Ctx) -> ? $T, close: (&Ctx) -> void) -> Iterator(T)

Using the polymorph solving system, you can write type free versions of arbitrary iterators. This is used heavily by many of the functions defined above.

Maybe at some point an alternate allocator would be good for this? For now, I think the temporary allocator is sufficient.

generator_no_copy
generator_no_copy :: (ctx: &$Ctx, gen: (&Ctx) -> ? $T) -> #auto
generator_no_copy :: (ctx: &$Ctx, gen: (&Ctx) -> ? $T, close: (&Ctx) -> void) -> #auto
generic_dynamic_array_as_iter
generic_dynamic_array_as_iter :: (x: &[..] $T, $access: Code, $return_type: type_expr) -> #auto

Iterators created from pointers to dynamic arrays are special, because they support the #remove directive.

map
map :: (it: Iterator($T), transform: (T) -> $R) -> #auto
map :: (it: Iterator($T), ctx: $Ctx, transform: (T, Ctx) -> $R) -> #auto

Transforms every value that comes out of an iterator using the transform function.

next_opt
next_opt :: (it: Iterator) -> ? it.Iter_Type

Helper function to get the next value out of an iterator, but translated to an optional. Returns None if the iterator was empty, Some(value) otherwise.

parallel_for
parallel_for :: macro (iterable: $I, thread_count: u32, thread_data: &$Ctx, body: Code) -> void
    where Iterable(I)
parallel_for :: macro (iter: Iterator($T), thread_count: u32, thread_data: &$Ctx, body: Code) -> void

Allows you to easily write a parallelized for-loop over an iterator. For example,

iter.parallel_for(1 .. 100, 4, &.{}) {
    printf("Thread {} has {}!\n", context.thread_id, it);
}
prod
prod :: macro (x: $I, y: $I2) -> #auto
    where Iterable(I), Iterable(I2)
prod :: (x: $I1, y_iter: Iterator($Y)) -> #auto
    where Iterable(I1)

Produces an iterator that first yields all values from the first iterable, combined with the first yield value from the second iterable. Then, steps the second iterable, and repeats.

For example,

 iter.prod(1 .. 4, 1 .. 3)

Would yield:

 (1, 1), (2, 1), (3, 1), (1, 2), (2, 2), (3, 2)
single
single :: (value: $T, dispose: (T) -> void) -> Iterator(T)

Yields a single value, then stops.

skip_while
skip_while :: (it: Iterator($T), predicate: (T) -> bool) -> Iterator(T)
skip_while :: (it: Iterator($T), ctx: $Ctx, predicate: (T, Ctx) -> bool) -> Iterator(T)

Discards values while the predicate is true, then yields all values.

some
some :: macro (it: $T, cond: $F) -> #auto
    where Iterable(T)
some :: (it: Iterator($T), cond: (T) -> bool) -> bool

Returns if cond returned true for any yielded value.

sum
sum :: macro (it: $T) -> #auto
    where Iterable(T)
sum :: (it: Iterator($T)) -> T

Returns the sum of all yield values, using the + operator.

take
take :: (it: Iterator($T), count: u32) -> Iterator(T)

Only yields the first count values, then closes.

take_while
take_while :: (it: Iterator($T), predicate: (T) -> bool) -> Iterator(T)

Yields values while the predicate returns true.

to_array
to_array :: (it: Iterator($T), allocator) -> [..] T

Places all yielded values into a dynamically allocated array, using the allocator provided (context.allocator by default).

to_map
to_map :: (it: Iterator(CALL), allocator) -> Map(K, V)

Places all yielded values into a Map, with the first member being the key, and the second member being the value.

zip
zip :: (left_iterator: Iterator($T), right_iterator: Iterator($R)) -> Iterator(CALL)

Combines two iterators into one by yielding a Pair of the value from each of the iterators.