Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
»

ps_set

container.ps_set

(K 
type
:
property.orderable)
:
Set K
 is
[Private constructor]
ps_set -- a partially sorted set based on ps_map

ps_set is a persistent set of ordered values. This set is generally
well-behaved with respect to cumulative and average performance.

WARNING: Due to the high worst-case time for addition, this structure should
not be used in situations when adding a single element repeatedly to the same
instance of ps_set is performance critical. If the resulting set's size n is a
power of 2, this will trigger the worst-case addition time resulting in
O(m*n log² n) for adding an element m times.

Type Parameters

Functions

(k container.ps_set.K)
 => 
container.this.Set container.ps_set.K
[Redefinition of  container.Set.add]
[Contains abstract features]
add new element k to this set.

NYI: UNDER DEVELOPMENT: this should be integrated in the mutate effect!

redefines:

add all elements of the given Sequence to this set
 => 
tuple Sequence.T Sequence.T Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
convert a Sequence's head into a 3-tuple.

ex.

[1,2,3,4,5].as_3tuple produces (1,2,3)
[1,2,3].as_3tuple produces (1,2,3)
[1,2].as_3tuple breaks the pre condition
[1].as_3tuple breaks the pre condition
[].as_3tuple breaks the pre condition
 => 
Sequence (tuple Sequence.T Sequence.T Sequence.T)
[Inherited from  Sequence]
[Contains abstract features]
chop this Sequence into tuples of size 3. In case
the number of elements is not a multiple of 3,
the last count % 3 elements will be dropped silently.

ex.

[1,2,3,4,5,6,7].tuples3 produces [(1,2,3),(4,5,6)]
 => 
tuple Sequence.T Sequence.T Sequence.T Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
convert a Sequence's head into a 4-tuple.

ex.

[1,2,3,4,5].as_4tuple produces (1,2,3,4)
[1,2,3,4].as_4tuple produces (1,2,3,4)
[1,2,3].as_4tuple breaks the pre condition
[1,2].as_4tuple breaks the pre condition
[1].as_4tuple breaks the pre condition
[].as_4tuple breaks the pre condition
chop this Sequence into tuples of size 4. In case
the number of elements is not a multiple of 4,
the last count % 4 elements will be dropped silently.

ex.

[1,2,3,4,5].tuples4 produces [(1,2,3,4)]
convert a Sequence's head into a 5-tuple.

ex.

[1,2,3,4,5,6].as_5tuple produces (1,2,3,4,5)
[1,2,3,4,5].as_5tuple produces (1,2,3,4,5)
[1,2,3,4].as_5tuple breaks the pre condition
[1,2,3].as_5tuple breaks the pre condition
...
[].as_5tuple breaks the pre condition
chop this Sequence into tuples of size 5. In case
the number of elements is not a multiple of 5,
the last count % 5 elements will be dropped silently.

ex.

[1,2,3,4,5,6].tuples5 produces [(1,2,3,4,5)]
convert a Sequence's head into a 6-tuple.

ex.

[1,2,3,4,5,6,7].as_6tuple produces (1,2,3,4,5,6)
[1,2,3,4,5,6].as_6tuple produces (1,2,3,4,5,6)
[1,2,3,4,5].as_6tuple breaks the pre condition
[1,2,3,4].as_6tuple breaks the pre condition
...
[].as_6tuple breaks the pre condition
chop this Sequence into tuples of size 6. In case
the number of elements is not a multiple of 6,
the last count % 6 elements will be dropped silently.

ex.

[1,2,3,4,5,6,7].tuples6 produces [(1,2,3,4,5,6)]
 => 
array container.ps_set.K
[Redefinition of  Sequence.as_array]
[Contains abstract features]
create a sorted array from the elements of this set

redefines:

 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
create an array backed version of this sequence in case this is not array
backed. This will ensure that operations like index[] or drop perform
in constant time.

returns Sequence.this if is_array_backed.
 => 
equatable_sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
wrap this sequence into an equatable type.

This requires the underlying element type to be equatable.
 => 
list container.ps_set.K
[Redefinition of  container.Set.as_list]
[Contains abstract features]
list representation of values in this set
 => 
orderable_sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
wrap this sequence into an orderable type.

This requires the underlying element type to be orderable.

An empty `Sequence` is always less or equal to any other `Sequence`. Two non
empty `Sequence`s whose first elements are unequal are ordered by the
order of those two elements. If those two elements are equal, the tail
of both `Sequence`s will be used to find the order.
(sep String)
 => 
String
[Inherited from  Sequence]
[Contains abstract features]
create a string representation of this Sequence including all the string
representations of its contents, separated by 'sep'.

NOTE: In case this Sequence is not finite, this will attempt to create an
infinitely long string resulting in failure due to resource exhaustion.
 => 
String
[Inherited from  Set]
[Contains abstract features]
 => 
String
[Inherited from  Sequence]
[Contains abstract features]
create a string representation of this Sequence including all the string
representations of its contents, separated by ", " and enclosed in '['
and ']'.

NOTE: In case this Sequence is not finite, this will attempt to create an
infinitely long string resulting in failure due to resource exhaustion.
 => 
Sequence String
[Inherited from  Sequence]
[Contains abstract features]
call 'as_string' on the elements
 => 
tuple Sequence.T Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
convert a Sequence's head into a 2-tuple.

ex.

[1,2,3,4,5].as_tuple produces (1,2)
[1,2].as_tuple produces (1,2)
[1].as_tuple breaks the pre condition
[].as_tuple breaks the pre condition
 => 
Sequence (tuple Sequence.T Sequence.T)
[Inherited from  Sequence]
[Contains abstract features]
chop this Sequence into tuples of size 2. In case
the number of elements is not a multiple of 2,
the last count % 2 elements will be dropped silently.

ex.

[1,2,3,4,5].tuples produces [(1,2),(3,4)]
 => 
option Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
the arithmetic mean of the sequence
https://en.wikipedia.org/wiki/Arithmetic_mean
(f Unary bool Sequence.T)
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
create a new Sequence that contains the first elements of
this Sequence for which 'f e' is false
(chunk_size i32)
 => 
Sequence (Sequence Sequence.T)
[Inherited from  Sequence]
[Contains abstract features]
chop this Sequence into chunks of `chunk_size`.
the last chunk may be smaller than `chunk_size`.
(U 
type
, V 
type
, b Sequence U, f Binary V Sequence.T U)
 => 
Sequence V
[Inherited from  Sequence]
[Contains abstract features]
create a new Sequence from the result of applying 'f' to the
elements all combinations of elements of this Sequence and
all elements of 'b' iterating of 'b' repeatedly as follows

Sequence.this[0] , b[0]
Sequence.this[0] , b[1]
Sequence.this[0] , b[2]
Sequence.this[0] , ...
Sequence.this[0] , b.last
Sequence.this[1] , b[0]
Sequence.this[1] , b[1]
Sequence.this[1] , ...
... , ...
Sequence.this.last, b.last
(s Sequence Sequence.T)
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
create a Sequence that consists of all the elements of this Sequence followed
by all the elements of s

General case: This will perform `as_list.concat_list` in case one of
`Sequence.this` or `s`is not known to be finite (`finite != trit.yet`) or
`s.count` is larger than `count`.

Otherwise, if `Sequence.this` or `s` is empty, the result will be `s` or
`Sequence.this`, respectively.

In all other cases, an instance of `container.expanding_array` will be
created and the elements of `this` and `s` will be added. Note that
`concat` is redefined for `container.expanding_array` to achieve
average `O(1)` performance for repeated concatenation with `s.count < c`
for some constant `c`.

Performance: O(count + s.count) worst case, O(s.count) average case

NOTE: For repeated concatenation `a.concat b` that fall into the general
case the resulting sequence will have iteration performance in `O(n²)`
for `n` concatenation. Explicitly use `container.expanding_array` to
avoid this. This implementation cannot do this automatically since
repeated wrapping of `a` into an `expanding_array` would result
in `O(n²)` performance for the concatenations.
(e container.ps_set.K)
 => 
bool
[Redefinition of  container.Set.contains]
[Contains abstract features]
does this set contain the given value?
 => 
i32
[Inherited from  Sequence]
[Contains abstract features]
count the number of elements in this Sequence. Note that this typically
runs forever if executed on an endless Sequence

For Sequences that are not array backed, this might require time in O(count).
(f Unary bool Sequence.T)
 => 
i32
[Inherited from  Sequence]
[Contains abstract features]
count the number of elements in this Sequence that match the
given predicate. Note that this typically
runs forever if executed on an endless Sequence.
(l Sequence Sequence.T)
 => 
i32
[Inherited from  Sequence]
[Contains abstract features]
get the number of non-overlapping matches of l within this
(l Sequence Sequence.T)
 => 
i32
[Inherited from  Sequence]
[Contains abstract features]
get the number of matches of l
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
create a Sequence that repeats the current Sequence indefinitely. In case 'Sequence.this'
is empty, returns 'nil'
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
filter out consecutive duplicate elements.

Keep the order of elements unchanged.

ex.
[1,2,2,3,2,2,2,4].dedup = [1,2,3,2,4]
(by Binary bool Sequence.T Sequence.T)
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
filter out consecutive duplicate elements using the
given relation.

Keep the order of elements unchanged.

ex.
[4,2,2,6,2,1,2,4].dedup (a,b -> a%2=b%2) = [4,1,2]
[4,2,2,6,2,1,2,4].dedup (<=) = [4,2,1]
(other container.Set container.Set.E)
 => 
container.Set container.Set.E
[Inherited from  Set]
[Contains abstract features]
this Set without all elements in other
(n i32)
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
create a Sequence that consists of the elements of this Sequence except the first
n elements

NOTE: this may have performance in O(n) unless it is backed by an immutable array.
(p Unary bool Sequence.T)
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
Lazily drop the first elements of this Sequence for which predicate 'p' holds.
 => 
Type
[Inherited from  Any]
[Contains abstract features]
Get the dynamic type of this instance. For value instances `x`, this is
equal to `type_of x`, but for `x` with a `ref` type `x.dynamic_type` gives
the actual runtime type, while `type_of x` results in the static
compile-time type.

There is no dynamic type of a type instance since this would result in an
endless hierarchy of types. So for Type values, dynamic_type is redefined
to just return Type.type.
 => 
Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
the euclidean norm of this sequence
i.e. the square of the sum of squares of this sequence
(f Unary bool Sequence.T)
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
filter elements using predicate f
values for which f is false are dropped
(pattern Sequence Sequence.T)
 => 
option i32
[Inherited from  Sequence]
[Contains abstract features]
get the index of pattern within this Sequence or nil if it does not exist

uses the Knuth-Morris-Pratt algorithm
port of racket code from this paper:
https://www.cambridge.org/core/services/aop-cambridge-core/content/view/8EFA77D663D585B68630E372BCE1EBA4/S0956796824000017a.pdf/knuth-morris-pratt-illustrated.pdf

worst-case performance: O( seq_length ) + O( pattern_length )
worst-case space complexity: O( pattern_length )
 => 
trit
[Inherited from  Set]
[Contains abstract features]
is this sequence known to be finite? For infinite sequences, features like
count diverge.
 => 
option Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
get the first element of this Sequence
(default Sequence.T)
 => 
Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
get the first element of this Sequence or default if sequence is empty
(B 
type
, f Unary (Sequence B) Sequence.T)
 => 
Sequence B
[Inherited from  Sequence]
[Contains abstract features]
map each element of this Sequence to Sequence
Then flatten the result by one level,
essentially combining all the sequences.
(m Monoid Sequence.T)
 => 
Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
fold the elements of this Sequence using the given monoid.

e.g., to sum the elements of a Sequence of i32, use s.fold i32.sum
(f Binary Sequence.T Sequence.T Sequence.T)
 => 
Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
fold the elements of this non-empty Sequence using the given function

e.g., to find the minimum of a Sequence of i32, use `s.fold1 (<=)`
(B 
type
, e B, f Binary B B Sequence.T)
 => 
B
[Inherited from  Sequence]
[Contains abstract features]
fold the elements of this Sequence using the given function and initial
value.

In case this Sequence is empty, the result is `e`.

e.g., to find the product of a Sequence of i32, use `s.foldf (*) 1`
(m Monoid Sequence.T)
 => 
Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
fold the elements of this Sequence using the given monoid right-to-left.

e.g., to concat the elements of a Sequence `s` of Strings, use `s.foldr String.concat`
(s Sequence.T, m Monoid Sequence.T)
 => 
Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
fold the elements of this Sequence using the given monoid and initial value right-to-left.

Used to fold a Sequence tail-recursively
(f Binary Sequence.T Sequence.T Sequence.T)
 => 
Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
fold the elements of this non-empty Sequence using the given function right-to-left

e.g., to concat the elements of a non-empty Sequence of Sequeces, use `foldr1 (++)`
(B 
type
, e B, f Binary B Sequence.T B)
 => 
B
[Inherited from  Sequence]
[Contains abstract features]
fold the elements of this Sequence using the given function right-to-left.

e.g., to concat the elements of a Sequence of Sequences, use `foldrf [] (++)`
(f Unary unit Sequence.T)
 => 
unit
[Inherited from  Sequence]
[Contains abstract features]
run `f` on each element in this Sequence in order.

Note that this makes sense only if `f` has some side-effect, e.g., to print
each element, use `s.for_each say`
(f Unary bool Sequence.T)
 => 
unit
[Inherited from  Sequence]
[Contains abstract features]
apply 'f' to each element 'e' as long as 'f e'
(K 
type
:
property.orderable, f Unary K Sequence.T)
 => 
container.Map K (Sequence Sequence.T)
[Inherited from  Sequence]
[Contains abstract features]
group the elements of this sequence by a key of type K
using a mutable_tree_map

f determines the key of an element
(K 
type
:
property.equatable, M 
type
:container.Mutable_Map Sequence.group_by_mutable_map.K (Sequence Sequence.T), f Unary K Sequence.T)
 => 
container.Map K (Sequence Sequence.T)
[Inherited from  Sequence]
[Contains abstract features]
group the elements of this sequence by a key of type K
using a custom Mutable_Map

f determines the key of an element
(K 
type
:
property.orderable, B 
type
, key_f Unary K Sequence.T, f Unary B Sequence.T)
 => 
container.Map K (Sequence B)
[Inherited from  Sequence]
[Contains abstract features]
group the elements of this sequence by a key of type and applies function f to all elements

example: group characters by category and add underscores around each character

values array codepoint := ["A", "1", "b", "?", "X", "4"]

classify (c codepoint) String => c.is_ascii_letter ? "letter" : c.is_ascii_digit ? "digit" : "other"

values.group_map String String classify (x->"_{x}_")

=> {(digit => [_1_, _4_]), (letter => [_A_, _b_, _X_]), (other => [_?_])}
(K 
type
:
property.orderable, B 
type
, key_f Unary K Sequence.T, f Unary B Sequence.T, reduce_f Binary B B B)
 => 
container.Map K B
[Inherited from  Sequence]
[Contains abstract features]
group elements using key_f and
reduce elements within a group by first applying f and then using reduce_f to reduce

example: count occurrences of letters, numbers and other characters

values array codepoint := ["A", "1", "b", "?", "X", "4"]

classify (c codepoint) String => c.is_ascii_letter ? "letter" : c.is_ascii_digit ? "digit" : "other"

values.group_map_reduce String i32 classify (_->1) (+)

=> {(digit => 2), (letter => 3), (other => 1)}
group elements using key_f and reduce elements within a group using reduce_f
in contrast to the more general version, values in the resulting map must have the same type as in the input

example: sum even and odd numbers individually

(0..10).group_reduce String (x -> x%%2 ? "even" : "odd") (+)

=> {(even => 30), (odd => 25)}
(k container.ps_set.K)
 => 
bool
[Contains abstract features]
check if an element equal to given element k is part of this set
 => 
Unary Sequence.T i32
[Inherited from  Sequence]
[Contains abstract features]
get a function that, given an index, returns the element at that index
(i i32)
 => 
Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
the nth element in the sequence, must exist
(x Sequence.T)
 => 
option i32
[Inherited from  Sequence]
[Contains abstract features]
determine the index of element x within this list. 0 if x is at the
head of the list, 1 if it comes directly after head, etc. nil if x is
not in the list.
 => 
Sequence (tuple i32 Sequence.T)
[Inherited from  Sequence]
[Contains abstract features]
adds the corresponding index to
every element in the sequence
(I 
type
:
has_interval, start_idx I)
 => 
Sequence (tuple I Sequence.T)
[Inherited from  Sequence]
[Contains abstract features]
adds an index to every element
in the sequence starting at start_idx
(n i32)
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
create a Sequence that repeats the current Sequence `n` times.
(s Sequence Sequence.T)
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
infix operand synonym for concat
(B 
type
, f Unary B Sequence.T)
 => 
Sequence B
[Inherited from  Sequence]
[Contains abstract features]
map the Sequence to a new Sequence applying function f to all elements

This is an infix operator alias of map enabling piping code like

l := 1..10 | *10 | 300-

to obtain 290,280,270,...200

Note that map and therefore also this operator is lazy, so

_ := (1..10 | say)

will not print anything while

(1..10 | say).for_each _->unit

will print the elements since `for_each` is not lazy.
(f Unary bool Sequence.T)
 => 
bool
[Inherited from  Sequence]
[Contains abstract features]
check if predicate f holds for all elements
(f Unary bool Sequence.T)
 => 
bool
[Inherited from  Sequence]
[Contains abstract features]
check if predicate f holds for at least one element
(other container.Set container.Set.E)
 => 
container.Set container.Set.E
[Inherited from  Set]
[Contains abstract features]
infix variant for Set.difference
Note: the operator is NOT a backslash, but the unicode character U+2216 (SET MINUS)
(other container.Set container.Set.E)
 => 
container.Set container.Set.E
[Inherited from  Set]
[Contains abstract features]
infix variant for Set.intersection
(other container.Set container.Set.E)
 => 
container.Set container.Set.E
[Inherited from  Set]
[Contains abstract features]
infix variant for Set.union
(at i32, v Sequence.T)
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
insert element v at position at
(other container.Set container.Set.E)
 => 
container.Set container.Set.E
[Inherited from  Set]
[Contains abstract features]
create an intersection of these two Sets
(TA 
type
, xf transducer (Sequence TA) TA Sequence.T)
 => 
Sequence TA
[Inherited from  Sequence]
[Contains abstract features]
apply transducer to sequence, returning a sequence of results

example usage:
human(age i32) is
ages := map (Sequence i32) human i32 (x -> x.age)
gt_ten := filter (Sequence i32) i32 (x -> x > 10)
xf := ages ∘ gt_ten
say ([human 4, human 12, human 30].into xf) # [12,30]
 => 
bool
[Inherited from  Sequence]
[Contains abstract features]
is this Sequence known to be array backed? If so, this means that operations
like index[] are fast.
 => 
bool
[Inherited from  Sequence]
[Contains abstract features]
is this Sequence empty?
 => 
bool
[Inherited from  Sequence]
[Contains abstract features]
is this Sequence sorted?
(other container.Set container.Set.E)
 => 
bool
[Inherited from  Set]
[Contains abstract features]
is this Set a subset of other?
true, iff other contains all
elements that this Set contains.
(other container.Set container.Set.E)
 => 
bool
[Inherited from  Set]
[Contains abstract features]
is this Set a superset of other?
true, iff this Set contains all
elements that other contains.
(i i32)
 => 
bool
[Inherited from  Sequence]
[Contains abstract features]
check if argument is a valid index in this sequence.

Note that this may have a performance in O(i) unless this
Sequence is_array_backed.
 => 
option Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
get the last element of this Sequence

This may take time in O(count), in particular, it may not terminate
for an infinite Sequence.
(default Sequence.T)
 => 
Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
get the last element of this Sequence or default if sequence is empty
(B 
type
, f Unary B Sequence.T)
 => 
Sequence B
[Inherited from  Sequence]
[Contains abstract features]
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 resulting list are accessed.
(B 
type
, f Binary B Sequence.T Sequence.T)
 => 
Sequence B
[Inherited from  Sequence]
[Contains abstract features]
Map this Sequence to f applied to neighboring pairs of values
in this Sequence.

In case this Sequence has less than two elements, the result will
be the empty list.

ex. to obtain a Sequence of differences, you may use `map_pairs (-)`:

[2,3,5,7,11,13,17,19,23,29].map_pairs a,b->b-a

results in `[1,2,2,4,2,4,2,4,6]`
 => 
option container.ps_set.K
[Redefinition of  Sequence.max]
[Contains abstract features]
get the highest element in this set

redefines:

 => 
option Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
the median of the sequence
https://en.wikipedia.org/wiki/Median
 => 
option container.ps_set.K
[Redefinition of  Sequence.min]
[Contains abstract features]
get the lowest element in this set

redefines:

(n i32)
 => 
option Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
the nth element in the sequence if it exists, wrapped in an option,
nil otherwise.

Complexity: if Sequence is array backed O(1) otherwise O(n)
(U 
type
, b Sequence U)
 => 
Sequence (tuple Sequence.T U)
[Inherited from  Sequence]
[Contains abstract features]
create a new Sequence from tuples of all combinations of elements
of this Sequence and all elements of 'b' iterating of 'b' repeatedly
as follows

(Sequence.this[0] , b[0] )
(Sequence.this[0] , b[1] )
(Sequence.this[0] , b[2] )
(Sequence.this[0] , ... )
(Sequence.this[0] , b.last)
(Sequence.this[1] , b[0] )
(Sequence.this[1] , b[1] )
(Sequence.this[1] , ... )
(... , ... )
(Sequence.this.last, b.last)
(f Unary unit Sequence.T)
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
calls `f` for each element in the Sequence.

Unlike `for_each` this returns itself
allowing easier composition with
other Sequence features.

example:

[1,2,3,4,5]
.filter is_prime
.peek say
.drop_while <10
 => 
String
[Inherited from  Any]
[Contains abstract features]
convenience prefix operator to create a string from a value.

This permits usage of `$` as a prefix operator in a similar way both
inside and outside of constant strings: $x and "$x" will produce the
same string.
 => 
Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
generic product of the elements of a Sequence of numeric.

This allows multiplying the elements of a list, as in

l := [1,2,3]
say <| l.product # '6'
(R 
type
, init R, f Binary (choice R (abort R)) R Sequence.T)
 => 
R
[Inherited from  Sequence]
[Contains abstract features]
reduce this Sequence to R with an initial value init
and a reducing function f.
the reduction is finished once f yields abort or
if the end of the sequence is reached.
(R 
type
, init R, f Binary (choice R (abort (outcome R))) R Sequence.T)
 => 
outcome R
[Inherited from  Sequence]
[Contains abstract features]
reduce this Sequence to `outcome R`
with an initial value `init` and a reducing function `f`.
the reduction is finished once `f` yields `abort` or
if the end of the sequence is reached.
(old Sequence Sequence.T, new Sequence Sequence.T)
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
replace all occurrences of old by new
(old Sequence Sequence.T, new Sequence Sequence.T, n u64)
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
replace the first n occurrences of old by new
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
reverse the order of the elements in this Sequence
(m Monoid Sequence.T)
 => 
list Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
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
(R 
type
, a R, f Binary R R Sequence.T)
 => 
Sequence R
[Inherited from  Sequence]
[Contains abstract features]
map this Sequence to a Sequence that contains the result of folding
all prefixes using the given function and initial value.

e.g., for a Sequence s `[3,8,10]`, `s.scan 0 (+)` creates a Sequence of
partial sums `[0, 3, 11, 21]`
(f Binary Sequence.T Sequence.T Sequence.T)
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
scan1 works like its counterpart with an initial value, except
that the initial value is taken to be the first element of the given
Sequence.

for example, (1::id).scan (+) would create [1, 2, 3, 4, ...], while
(1..).scan (+) would create [1, 3, 6, 10, ...].
 => 
option i32
[Redefinition of  container.Set.size_option]
[Contains abstract features]
number of entries in this set. May be undefined, i.e., a range of
floating point numbers or an infinite set.
(from i32, to i32)
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
create a slice from this Sequence that consists of the elements starting at index
from (including) up to index to (excluding).
(size i32)
 => 
Sequence (Sequence Sequence.T)
[Inherited from  Sequence]
[Contains abstract features]
sliding window with step size one
blocks of size elements, each is offset by one element to the previous one

example:
`(0..5).sliding 3`
=> `[[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5]]`
(size i32, step i32)
 => 
Sequence (Sequence Sequence.T)
[Inherited from  Sequence]
[Contains abstract features]
sliding window
blocks of size elements, each is offset by step elements to the previous one

examples:
`(0..5).sliding 3 1`
=> `[[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5]]`

`(0..9).sliding 3 2`
=> `[[0, 1, 2], [2, 3, 4], [4, 5, 6], [6, 7, 8]]`
 => 
container.sorted_array Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
sort this Sequence
(less_or_equal Binary bool Sequence.T Sequence.T)
 => 
container.sorted_array Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
sort this Sequence using the order defined by less_or_equal
(at i32)
 => 
tuple (Sequence Sequence.T) (Sequence Sequence.T)
[Inherited from  Sequence]
[Contains abstract features]
create a tuple of two Sequences by splitting this at the given index, i.e.,
a Sequence of length 'at' and one of length 'count-at'.

at may be <= 0 or >= count, in which case the resulting tuple will be the
(empty list, Sequence.this.as_list) or (Sequence.this.as_list, empty list), resp.
(l Sequence Sequence.T)
 => 
bool
[Inherited from  Sequence]
[Contains abstract features]
does this sequence start with l?
 => 
option Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
the standard deviation of the sequence
https://en.wikipedia.org/wiki/Standard_deviation
 => 
Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
generic sum of the elements of a Sequence of numeric.

This allows summing the elements of a list, as in

l := [1,2,3]
say <| l.sum # '6'
 => 
list (list Sequence.T)
[Inherited from  Sequence]
[Contains abstract features]
create a lazy list of all the tails of this Sequence, including the complete Sequence
as a list and the empty list 'nil'.
(n i32)
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
create a Sequence that consists only of the first n elements of this
Sequence, fewer if this Sequence has fewer elements
(p Unary bool Sequence.T)
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
Lazily take the first elements of this Sequence for which predicate 'p' holds.
(TA 
type
, U 
type
, xf transducer TA U Sequence.T, rf Binary TA TA U, init TA)
 => 
TA
[Inherited from  Sequence]
[Contains abstract features]
takes a transducer xf, a reducer f and an initial value
returns the result of applying the reducer xf f to the Sequence
(other container.Set container.Set.E)
 => 
container.Set container.Set.E
[Inherited from  Set]
[Contains abstract features]
create a union of these two Sets
 => 
Sequence Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
filter out duplicate elements.

Keep the order of elements unchanged.

Other languages call this 'distinct' (eg., Java, C# or Kotlin)
or `nub` (Haskell).

ex.
[4,1,2,2,3,2,2,2,4].unique = [4, 1, 2, 3]
 => 
option Sequence.T
[Inherited from  Sequence]
[Contains abstract features]
the variance of the sequence
https://en.wikipedia.org/wiki/Variance
(U 
type
, V 
type
, b Sequence U, f Binary V Sequence.T U)
 => 
Sequence V
[Inherited from  Sequence]
[Contains abstract features]
create a new Sequence from the result of applying 'f' to the
elements of this Sequence and 'b' in order.

Type Functions

 => 
String
[Inherited from  Type]
[Contains abstract features]
string representation of this type to be used for debugging.

result has the form "Type of '<name>'", but this might change in the future

redefines:

 => 
i32
[Inherited from  Sequence]
[Contains abstract features]
Maximum number of elements shown for on a call to `as_string` for a non-finite
Sequence.
 => 
Monoid (Sequence Sequence.type.T)
[Inherited from  Sequence]
[Contains abstract features]
monoid of Sequences with infix concatenation operation.
 => 
Type
[Inherited from  Type]
[Contains abstract features]
There is no dynamic type of a type instance since this would result in an
endless hierarchy of types, so dynamic_type is redefined to just return
Type.type here.

redefines:

an empty ps_set
(a property.equatable.this.type, b property.equatable.this.type)
 => 
bool
[Inherited from  equatable]
[Abstract feature]
[Contains abstract features]
equality implements the default equality relation for values of this type.

This relation must be

- reflexive (equality a b),
- symmetric (equality a b = equality b a), and
- transitive ((equality a b && equality b c) : equality a c).

result is true iff 'a' is considered to represent the same abstract value
as 'b'.
(T 
type
)
 => 
bool
[Inherited from  Type]
[Contains abstract features]
Is this type assignable to a type parameter with constraint `T`?

The result of this is a compile-time constant that can be used to specialize
code for a particular type.

is_of_integer_type(n T : numeric) => T : integer
say (is_of_integer_type 1234) # true
say (is_of_integer_type 3.14) # false

it is most useful in conjunction preconditions or `if` statements as in

pair(a,b T) is
same
pre T : property.equatable
=>
a = b

or

val(n T) is

# check if T is numeric, if so
# return true if n > zero,
# return nil if T is not numeric
#
more_than_zero option bool =>
if T : numeric then
n > T.zero
else
nil
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 => 
String
[Inherited from  Type]
[Contains abstract features]
name of this type, including type parameters, e.g. 'option (list i32)'.
initialize a partially sorted set from one Sequence

This feature creates a pre-initialized instance of ps_set.
 => 
String
[Inherited from  Type]
[Contains abstract features]
convenience prefix operator to create a string from a value.

This permits usage of `$` as a prefix operator in a similar way both
inside and outside of constant strings: $x and "$x" will produce the
same string.

NYI: Redefinition allows the type feature to be distinguished from its normal counterpart, see #3913

redefines:

 => 
Type
[Inherited from  Any]
[Contains abstract features]
Get a type as a value.

This is a feature with the effect equivalent to Fuzion's `expr.type` call tail.
It is recommended to use `expr.type` and not `expr.type_value`.

`type_value` is here to show how this can be implemented and to illustrate the
difference to `dynamic_type`.
 => 
Monoid (container.Set container.Set.type.E)
[Inherited from  Set]
[Contains abstract features]
monoid of Set with infix ∪ operation.
0.094dev (2025-06-18 15:08:51 GIT hash 89cffc23ae669b0898a5564fefbf793fcb8e5ca7 built by fridi@fzen)