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

list

list

list -- feature used to define lists

list provides an abstract type for a sequence of elements of the same type.

A list sequence may be empty and contain no element, or it may have a fixed
or even an infinite number of elements.

The core of the implementation of an actual list lies in the implementation
of the actual Cons cell a non-empty list consists of.

Lists can typically be traversed using only immutable data. This makes them
more flexible than streams that require to store and update their state.

A list is immutable, so it can be reused and shared between threads.
Due to the nature of lists, in which many Cons cells are used, a list
may require more (heap) allocation than an array.

Functions

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

redefines:

Return this list as a list.

This is a helper function that needs to be defined because list is an heir
of Sequence.

redefines:

count the elements of this list

redefines:

collect the contents of this list into an array

redefines:

call f in order on all elements of this list

redefines:

create a list from the tail of list.this dropping n elements (or fewer
if the list is shorter than n).

redefines:

fold the elements of this list using the given monoid.

e.g., to sum the elements of a list of i32, use l.fold i32.sum

redefines:

§fold(s list.A, m Monoid list.A)
 => 
list.A
:
Any 
fold the elements of this list using the given monoid and initial value

Used to fold a list tail-recursively
get the head of this list if it exists, nil if it does
not exist
get the tail of this list if it exists, nil if it does
not exist or it is the empty list
is this list empty?

redefines:

§first
 => 
list.A
:
Any 
get the head of this list

list must not be empty, causes precondition failure if debug is enabled.

redefines:

§last
 => 
list.A
:
Any 
get the last element of this list

list must not be empty, causes precondition failure if debug is enabled.

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

redefines:

Lazily filter the elements of a list.

The result contains exactly those elements for which p
is true.

redefines:

check if predicate f holds for all elements
check if predicate f holds for at least one element
Lazily take the first n elements of a list, alternatively the whole list if it
is shorter than n, or the empty list if n <= 0

redefines:

Lazily take the first elements of a list for which predicate 'p' holds.
Lazily drop the first elements of a list for which predicate 'p' holds.
infix operand synonym for concat

redefines:

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

redefines:

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

redefines:

fold the elements of this non-empty list using the given function

e.g., to find the minimum of a list of i32, use `l.fold1 (<=)`

redefines:

map this Sequence to a list that contains the result of folding
all prefixes using the given monoid.

e.g., for a Sequence of i32 s, s.scan i32.sum creates a list of
partial sums (0..).map x->(s.take x).fold i32.sum

redefines:

map this Sequence to a list that contains the result of folding
all prefixes using the given monoid and initial value

Used to scan a list tail-recursively
Lazy list concatenation, O(1)
t is evaluated only when this list is exhausted

This is useful when doing buffered reading from an input
source and the next buffer chunk, the tail should only
be created when actually necessary.
returns the list of all but the last element of this list

list must not be empty, causes precondition failure if debug is enabled.
map the list to a new list applying function f to all elements

This performs a lazy mapping, f is called only when the elements
are taken from the list.
map the list to a new list applying function f to all elements
and flatten the result of f in the process

This performs a lazy mapping, f is called only when the elements
are taken from the list.
§foldf_list(B 
type
, f Function list.foldf_list.B list.foldf_list.B list.A, e list.foldf_list.B)
 => 
list.foldf_list.B
:
Any 
fold the elements of this list using the given function

e.g., to find the product of a list of i32, use `s.foldf (*) 1`

NYI: #2319: rename as `foldf` as soon as redefinition of feature with
type parameters works
reverse the order of the elements in this list
add an element sep in front of every element of this list.
add an element sep between every element of this list.
List concatenation, O(count)
create a new list from the result of applying 'f' to the
elements of this list and 'b' in order.
create a new list from the result of applying 'f' to the
elements all combinations of elements of this list and
all elements of 'b' iterating of 'b' repeatedly as follows

list.this[0] , b[0]
list.this[0] , b[1]
list.this[0] , b[2]
list.this[0] , ...
list.this[0] , b.last
list.this[1] , b[0]
list.this[1] , b[1]
list.this[1] , ...
... , ...
list.this.last, b.last

Type Features

create an empty list
fmap lifts a function from A to B to a function from list A to list B
monoid of lists with infix concatentation operation.

NYI: Name should be `concat_monoid`, we use `list_concat_monoid`
to avoid clash with inherited `Sequence.concat_monoid`. Maybe
the inherited one should be renamed once renmaing is supported.