lazy-list

Lazy list in MoonBit

lazy
lazy-list
moon add CAIMEOX/lazy-list@0.1.2
Download zip
Author
Version
0.1.2
License
MIT
Last updated
10 months ago
Downloads
31

Dependencies

README

#LazyList

MoonBit lazy list library providing efficient, on-demand evaluation of list operations. The library supports common list operations like map, filter, fold, etc like @immut/list, but evaluates them lazily, only computing elements when needed.

#
LazyList

pub(all) enum LazyList[T] {
Nil
Cons(T,
Lazy
[LazyList[T]])
}

A lazy list type that can be either empty (Nil) or a head element with a lazily evaluated tail (Cons).
impl Add for LazyList[T]
impl Eq for LazyList[T]
impl Show for LazyList[T]

#
LazyList::concat

fn[T] LazyList::concat(self : LazyList[T], other : LazyList[T]) -> LazyList[T]

Concatenates two lazy lists together.

#
LazyList::drop

fn[T] LazyList::drop(self : LazyList[T], n : Int) -> LazyList[T]

Drops the first n elements from a lazy list.

#
LazyList::drop_while

fn[T] LazyList::drop_while(self : LazyList[T], p : (T) -> Bool) -> LazyList[T]

Drops elements from a lazy list while they satisfy a predicate.

#
LazyList::each

fn[T] LazyList::each(self : LazyList[T], f : (T) -> Unit) -> Unit

Applies a function to each element of a lazy list for side effects.

#
LazyList::eachi

fn[T] LazyList::eachi(self : LazyList[T], f : (Int, T) -> Unit) -> Unit

Applies a function to each element with its index for side effects.

#
LazyList::filter

fn[T] LazyList::filter(self : LazyList[T], pred : (T) -> Bool) -> LazyList[T]

Filters a lazy list using a predicate.

#
LazyList::flat_map

fn[T, U] LazyList::flat_map(self : LazyList[T], f : (T) -> LazyList[U]) -> LazyList[U]

Flat maps a function over a lazy list.

#
LazyList::flatten

fn[T] LazyList::flatten(self : LazyList[LazyList[T]]) -> LazyList[T]

Flattens a lazy list of lazy lists into a single lazy list.

#
LazyList::fold_left

fn[T, U] LazyList::fold_left(self : LazyList[T], f : (U, T) -> U, init~ : U) -> U

Left fold over a lazy list.

#
LazyList::fold_right

fn[T, U] LazyList::fold_right(self : LazyList[T], f : (T, U) -> U, init~ : U) -> U

Right fold over a lazy list.

#
LazyList::from_array

fn[T] LazyList::from_array(ar : Array[T]) -> LazyList[T]

Converts an Array to a LazyList in reverse order.

#
LazyList::from_list

fn[T] LazyList::from_list(ls :
List
[T]) -> LazyList[T]

Converts an immutable List to a LazyList.

#
LazyList::head

fn[T] LazyList::head(self : LazyList[T]) -> T

Gets the first element of a lazy list.

#
LazyList::index

fn[T] LazyList::index(self : LazyList[T], i : Int) -> T

Gets the element at a specific index in the lazy list.

#
LazyList::length

fn[T] LazyList::length(self : LazyList[T]) -> Int

Computes the length of a lazy list.

#
LazyList::map

fn[T, U] LazyList::map(self : LazyList[T], f : (T) -> U) -> LazyList[U]

Maps a function over a lazy list.

#
LazyList::split_at

fn[T] LazyList::split_at(self : LazyList[T], i : Int) -> (LazyList[T], LazyList[T])

Splits a lazy list at the given index.

#
LazyList::tail

fn[T] LazyList::tail(self : LazyList[T]) -> LazyList[T]

Gets the tail of a lazy list.

#
LazyList::tails

fn[T] LazyList::tails(self : LazyList[T]) -> LazyList[LazyList[T]]

Returns a lazy list of all final segments of the original list.

#
LazyList::take

fn[T] LazyList::take(self : LazyList[T], n : Int) -> LazyList[T]

Takes the first n elements from a lazy list.

#
LazyList::take_while

fn[T] LazyList::take_while(self : LazyList[T], p : (T) -> Bool) -> LazyList[T]

Takes elements from a lazy list while they satisfy a predicate.

#
LazyList::to_array

fn[T] LazyList::to_array(self : LazyList[T]) -> Array[T]

Converts a lazy list to an array.

#
LazyList::unfold

fn[T] LazyList::unfold(self : LazyList[T], f : (LazyList[T]) -> (T, LazyList[T])?) -> LazyList[T]

Unfolds a lazy list using a generator function.

#
LazyList::unzip

fn[T, W] LazyList::unzip(self : LazyList[(T, W)]) -> (LazyList[T], LazyList[W])

Unzips a lazy list of pairs into a pair of lazy lists.

#
LazyList::zip_lazy_normal

fn[A, B, C] LazyList::zip_lazy_normal(self : LazyList[A], f : (A, B) -> C, ys :
List
[B]) ->
List
[C]

Zips a lazy list with a normal list using a combining function.

#
LazyList::zip_with

fn[A, B, C] LazyList::zip_with(self : LazyList[A], ys : LazyList[B], f : (A, B) -> C) -> LazyList[C]

Zips two lazy lists with a combining function.

#
default

fn[X] default() -> LazyList[X]

Creates a default empty lazy list for types that implement Default.

#
infinite_stream

fn[X : Add] infinite_stream(start : X, step : X) -> LazyList[X]

Creates an infinite lazy list with arithmetic progression.

#
nats

fn nats() -> LazyList[Int]

Creates an infinite lazy list of natural numbers starting from 0.

#
repeat

fn[T] repeat(val : T) -> LazyList[T]

Creates an infinite lazy list repeating the same value.

#
sum

fn[X : Add] sum(l : LazyList[X], init~ : X) -> X

Sums the elements of a lazy list with an initial value.

#
zip_plus

fn[T] zip_plus(f : (T, T) -> T, ls1 : LazyList[T], ls2 : LazyList[T]) -> LazyList[T]

Zips two lazy lists with a combining function, concatenating remaining elements.

Source Files

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io