LazyList provides lazy evaluation for list operations. Operations are deferred until the list is materialized.
// Basic lazy evaluationconst result = LazyList([1, 2, 3, 4, 5]) .map(x => x * 2) .filter(x => x > 5) .toArray() // [6, 8, 10] Copy
// Basic lazy evaluationconst result = LazyList([1, 2, 3, 4, 5]) .map(x => x * 2) .filter(x => x > 5) .toArray() // [6, 8, 10]
// Infinite sequences with takeconst fibonacci = LazyList.iterate([0, 1], ([a, b]) => [b, a + b]) .map(([a]) => a) .take(10) .toArray() // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] Copy
// Infinite sequences with takeconst fibonacci = LazyList.iterate([0, 1], ([a, b]) => [b, a + b]) .map(([a]) => a) .take(10) .toArray() // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Readonly
Pattern matches over the structure, applying specific handlers for each variant
Function to apply if the structure is empty or has no value
Function to apply if the structure has a value
The result of applying the appropriate function
Left-associative fold using the provided zero value and operation
Zero/identity value
A function that takes an operation to apply
Right-associative fold using the provided zero value and operation
Pipes the value through the provided function
The return type of the function
The function to apply to the value
The result of applying the function to the value
Returns a string representation of an object.
LazyList provides lazy evaluation for list operations. Operations are deferred until the list is materialized.
Example
Example