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

stream

stream

stream -- a stream of values

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

The mutable nature of streams requires particular prudence, as even basic
actions, such as calling as_string on a stream will consume values and thus
change the state of the stream, as the following example demonstrates:

a := [1, 2, 3, 4, 5].as_stream
say a
say a

In this example, the first invocation of say will print "1, 2, 3, 4, 5",
the second invocation will print "".

NYI: Check if stream should be replaced by a lazy list, which is a choice
of either nil or a tuple (head, tail). This should avoid the need to store
mutable state.

Constructors

NYI this was broken but is meanwhile fixed.
Should be removed eventually.

Functions

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

redefines:

create a list from this stream

redefines:

count the elements of this stream

redefines:

collect all items from this stream into an array

redefines:

apply f to all elements in this stream

redefines:

fold the elements of this stream using the given monoid.

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

redefines:

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

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

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

redefines:

apply 'f' to each element 'e' as long as 'f e'

redefines:

check if predicate f holds for all elements produced by this stream
check if predicate f holds for at least one element produced by this stream
take n items from stream, less if stream has fewer than n items

redefines:

does this stream have one more element?
§next
 => 
stream.T
:
Any 
the next element in this stream
map the stream to a new stream applying function f to all elements

This performs a lazy mapping, f is called only when the elements
are taken from the stream.
last changed: 2024-08-13