Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

Sequence

🌌Sequence

Sequence -- ancestor for features that can be converted to a 'list' or a
'stream'

Sequences are empty, finite or infinite ordered collections of instances
of a given type. Sequences calculate elements lazily on demand.

Sequence is a 'ref' type, i.e., different sub-features may be assigned
to a field of type 'Sequence'.

Heirs of Sequence must implement either 'asList' or 'asStream'. Failure
to implement any of these results in an endless recursion when the Sequence
is used.

collect the contents of this Sequence into an array

create a list from this Sequence.

A list is immutable, so it can be reused and shared between threads.
Compared to a stream, a list may require more (heap) allocation.

Default implementation uses asStream. Heirs must redefine at least
one of asList or asStream.

create a stream of T.

A stream contains mutable state, so it cannot be reused or shared
between threads.

Default implementation uses asList. Heirs must redefine at least
one of asList or asStream.

create a string representation of this list including all the string
representations of its contents, separated by ',' and enclosed in '['
and ']'.

redefines Object.asString:

create a string representation of this list including all the string
representations of its contents, separated by 'sep'.

create a new stream that contains the first elements of this stream for
which 'f e' is false

create a Sequence that consists of all the elements of this Sequence followed
by all the elements of s

count the number of elements in this Sequence. Note that this typically
runs forever if executed on an endless list

create a list that repeats the current Sequence indefinitely. In case 'Sequence.this'
is empty, returns 'nil'

create a list that consists of the elements of this Sequence except the first
n elements

Lazily drop the first elements of a list for which predicate 'p' holds.

create a new stream and filter its elements using predicate f

get the head of this list, panic if list is empty

fold the elements of this Sequence using the given monoid.

e.g., to sum the elements of a stream of i32, use s.fold i32.sum

create a stream and call 'forAll f' on it

create a new stream and apply 'f' to each element 'e' as long as 'f e'

create a new stream and filter its elements using predicate f, infix operator
synonyme of filter.

NYI: What is better, 'infix |&' or 'infix &', or something else?

infix operand synonyme for concatSequences

create a stream and have it consumed by f, infix operator synonyme of forAll.

create a new stream and filter its elements using predicate f, infix operator
synonyme of filter.

create a stream and check if predicate f holds for all elements produced

create a stream and check if predicate f holds for at least one element produced

insert element v at position at

is this list empty?

get the last element of this list, panic if list is empty

This may take time in O(count), in particular, it may not terminate
for an infinite list.

map the Sequence to a new Sequence applying function f to all elements

This performs a lazy mapping, f is called only when the elements
in the list are accessed.

NYI: As long as covariance for result type is not permitted we cannot
call this 'map' since this would clash with, e.g., 'array.map'

create a stream, infix operator synonyme for asStream

reduce this Sequence to R with an initial value init
and a reducing function f

create a slice from this Sequence that consists of the elements starting at index
from (including) up to index to (excluding).

sort this Sequence using the total order defined by lessOrEqual

sort this Sequence using total order defined for 'f a[i]'

create a lazy list of all the tails of this list, including the complete list
'list.this' and the empty list 'nil'.

create a list that consists only of the first n elements of this
Sequence, fewer if this stream has fewer elements

Lazily take the first elements of a list for which predicate 'p' holds.

create a new list from the result of applying 'f' to the
elements of this list and 'b' in order.