# Stream SΒΆ

stream.spad line 534 [edit on github]

S: Type

A stream is an implementation of a possibly infinite sequence using a list of terms that have been computed and a function closure to compute additional terms when needed.

- <=: (%, %) -> Boolean if S has OrderedSet and % has finiteAggregate
from PartialOrder

- <: (%, %) -> Boolean if S has OrderedSet and % has finiteAggregate
from PartialOrder

- =: (%, %) -> Boolean if S has Hashable and % has finiteAggregate or S has BasicType and % has finiteAggregate or S has SetCategory
from BasicType

- >=: (%, %) -> Boolean if S has OrderedSet and % has finiteAggregate
from PartialOrder

- >: (%, %) -> Boolean if S has OrderedSet and % has finiteAggregate
from PartialOrder

- ~=: (%, %) -> Boolean if S has Hashable and % has finiteAggregate or S has BasicType and % has finiteAggregate or S has SetCategory
from BasicType

- child?: (%, %) -> Boolean if S has BasicType
from RecursiveAggregate S

- children: % -> List %
from RecursiveAggregate S

- coerce: % -> OutputForm if S has CoercibleTo OutputForm
from CoercibleTo OutputForm

- coerce: List S -> %
`coerce(l)`

converts a list`l`

to a stream.

- complete: % -> %
from LazyStreamAggregate S

- concat!: (%, %) -> %
from UnaryRecursiveAggregate S

- concat!: (%, S) -> %
from UnaryRecursiveAggregate S

- concat!: List % -> %
from UnaryRecursiveAggregate S

- concat: (%, %) -> %
from LinearAggregate S

- concat: (%, S) -> %
from LinearAggregate S

- concat: (S, %) -> %
from LinearAggregate S

- concat: List % -> %
from LinearAggregate S

- cons: (S, %) -> %
`cons(a, s)`

returns a stream whose`first`

is`a`

and whose`rest`

is`s`

. Note:`cons(a, s) = concat(a, s)`

.

- construct: List S -> %
from Collection S

- convert: % -> InputForm if S has ConvertibleTo InputForm
from ConvertibleTo InputForm

- count: (S, %) -> NonNegativeInteger if S has BasicType and % has finiteAggregate
from HomogeneousAggregate S

- cycleEntry: % -> %
from UnaryRecursiveAggregate S

- cycleLength: % -> NonNegativeInteger
from UnaryRecursiveAggregate S

- cycleSplit!: % -> %
from UnaryRecursiveAggregate S

- cycleTail: % -> %
from UnaryRecursiveAggregate S

- cyclic?: % -> Boolean
from RecursiveAggregate S

- delay: (() -> %) -> %
`delay(f)`

creates a stream with a lazy evaluation defined by function`f`

. Caution: This function can only be called in compiled code.

- delete: (%, Integer) -> %
from LinearAggregate S

- delete: (%, UniversalSegment Integer) -> %
from LinearAggregate S

- distance: (%, %) -> Integer
from RecursiveAggregate S

- elt: (%, first) -> S
from UnaryRecursiveAggregate S

- elt: (%, Integer) -> S
- elt: (%, Integer, S) -> S
from EltableAggregate(Integer, S)

- elt: (%, last) -> S
from UnaryRecursiveAggregate S

- elt: (%, rest) -> %
from UnaryRecursiveAggregate S

- elt: (%, UniversalSegment Integer) -> %
from Eltable(UniversalSegment Integer, %)

- elt: (%, value) -> S
from RecursiveAggregate S

- entries: % -> List S
from IndexedAggregate(Integer, S)

- entry?: (S, %) -> Boolean if S has BasicType and % has finiteAggregate
from IndexedAggregate(Integer, S)

- eval: (%, Equation S) -> % if S has Evalable S and S has SetCategory
from Evalable S

- eval: (%, List Equation S) -> % if S has Evalable S and S has SetCategory
from Evalable S

- eval: (%, List S, List S) -> % if S has Evalable S and S has SetCategory
from InnerEvalable(S, S)

- eval: (%, S, S) -> % if S has Evalable S and S has SetCategory
from InnerEvalable(S, S)

- explicitEntries?: % -> Boolean
from LazyStreamAggregate S

- explicitlyEmpty?: % -> Boolean
from LazyStreamAggregate S

- explicitlyFinite?: % -> Boolean
from StreamAggregate S

- extend: (%, Integer) -> %
from LazyStreamAggregate S

- fill!: (%, S) -> %
from IndexedAggregate(Integer, S)

- filterUntil: (S -> Boolean, %) -> %
`filterUntil(p, s)`

returns`[x0, x1, ..., x(n)]`

where`s = [x0, x1, x2, ..]`

and`n`

is the smallest index such that`p(xn) = true`

.

- filterWhile: (S -> Boolean, %) -> %
`filterWhile(p, s)`

returns`[x0, x1, ..., x(n-1)]`

where`s = [x0, x1, x2, ..]`

and`n`

is the smallest index such that`p(xn) = false`

.

- find: (S -> Boolean, %) -> Union(S, failed)
from Collection S

- findCycle: (NonNegativeInteger, %) -> Record(cycle?: Boolean, prefix: NonNegativeInteger, period: NonNegativeInteger)
`findCycle(n, st)`

determines if st is periodic within`n`

.

- first: % -> S
from IndexedAggregate(Integer, S)

- first: (%, NonNegativeInteger) -> %
from LinearAggregate S

- frst: % -> S
from LazyStreamAggregate S

- hash: % -> SingleInteger if S has Hashable and % has finiteAggregate
from Hashable

- hashUpdate!: (HashState, %) -> HashState if S has Hashable and % has finiteAggregate
from Hashable

- index?: (Integer, %) -> Boolean
from IndexedAggregate(Integer, S)

- indices: % -> List Integer
from IndexedAggregate(Integer, S)

- insert: (%, %, Integer) -> %
from LinearAggregate S

- insert: (S, %, Integer) -> %
from LinearAggregate S

- last: % -> S
from UnaryRecursiveAggregate S

- last: (%, NonNegativeInteger) -> %
from UnaryRecursiveAggregate S

- latex: % -> String if S has SetCategory
from SetCategory

- lazy?: % -> Boolean
from LazyStreamAggregate S

- lazyEvaluate: % -> %
from LazyStreamAggregate S

- leaf?: % -> Boolean
from RecursiveAggregate S

- leaves: % -> List S
from RecursiveAggregate S

- leftTrim: (%, S) -> % if S has BasicType and % has finiteAggregate
from LinearAggregate S

- less?: (%, NonNegativeInteger) -> Boolean
from Aggregate

- map!: (S -> S, %) -> %
from HomogeneousAggregate S

- map: ((S, S) -> S, %, %) -> %
from LinearAggregate S

- map: (S -> S, %) -> %
from HomogeneousAggregate S

- max: % -> S if S has OrderedSet and % has finiteAggregate
from HomogeneousAggregate S

- max: (%, %) -> % if S has OrderedSet and % has finiteAggregate
from OrderedSet

- maxIndex: % -> Integer
from IndexedAggregate(Integer, S)

- member?: (S, %) -> Boolean if S has BasicType and % has finiteAggregate
from HomogeneousAggregate S

- merge: (%, %) -> % if S has OrderedSet and % has finiteAggregate
from LinearAggregate S

- min: % -> S if S has OrderedSet and % has finiteAggregate
from HomogeneousAggregate S

- min: (%, %) -> % if S has OrderedSet and % has finiteAggregate
from OrderedSet

- minIndex: % -> Integer
from IndexedAggregate(Integer, S)

- more?: (%, NonNegativeInteger) -> Boolean
from Aggregate

- new: (NonNegativeInteger, S) -> %
from LinearAggregate S

- node?: (%, %) -> Boolean if S has BasicType
from RecursiveAggregate S

- nodes: % -> List %
from RecursiveAggregate S

- position: (S, %) -> Integer if S has BasicType and % has finiteAggregate
from LinearAggregate S

- position: (S, %, Integer) -> Integer if S has BasicType and % has finiteAggregate
from LinearAggregate S

- possiblyInfinite?: % -> Boolean
from StreamAggregate S

- qelt: (%, Integer) -> S
from EltableAggregate(Integer, S)

- qsetelt!: (%, Integer, S) -> S
from EltableAggregate(Integer, S)

- qsetfirst!: (%, S) -> S
from UnaryRecursiveAggregate S

- qsetrest!: (%, %) -> %
from UnaryRecursiveAggregate S

- reduce: ((S, S) -> S, %, S, S) -> S if S has BasicType and % has finiteAggregate
from Collection S

- remove: (S -> Boolean, %) -> %
from LazyStreamAggregate S

- remove: (S, %) -> % if S has BasicType and % has finiteAggregate
from Collection S

- removeDuplicates: % -> % if S has BasicType and % has finiteAggregate
from Collection S

- repeating?: (List S, %) -> Boolean if S has SetCategory
`repeating?(l, s)`

returns`true`

if a stream`s`

is periodic with period`l`

, and`false`

otherwise.

- repeating: List S -> %
`repeating(l)`

is a repeating stream whose period is the list`l`

.

- rest: % -> %
from UnaryRecursiveAggregate S

- rest: (%, NonNegativeInteger) -> %
from UnaryRecursiveAggregate S

- rightTrim: (%, S) -> % if S has BasicType and % has finiteAggregate
from LinearAggregate S

- rst: % -> %
from LazyStreamAggregate S

- second: % -> S
from UnaryRecursiveAggregate S

- select: (S -> Boolean, %) -> %
from LazyStreamAggregate S

- setchildren!: (%, List %) -> %
from RecursiveAggregate S

- setelt!: (%, first, S) -> S
from UnaryRecursiveAggregate S

- setelt!: (%, Integer, S) -> S
from EltableAggregate(Integer, S)

- setelt!: (%, last, S) -> S
from UnaryRecursiveAggregate S

- setelt!: (%, rest, %) -> %
from UnaryRecursiveAggregate S

- setelt!: (%, UniversalSegment Integer, S) -> S
from LinearAggregate S

- setelt!: (%, value, S) -> S
from RecursiveAggregate S

- setfirst!: (%, S) -> S
from UnaryRecursiveAggregate S

- setlast!: (%, S) -> S
from UnaryRecursiveAggregate S

- setrest!: (%, %) -> %
from UnaryRecursiveAggregate S

- setrest!: (%, Integer, %) -> %
`setrest!(x, n, y)`

sets rest(`x`

,`n`

) to`y`

. The function will expand cycles if necessary.

- setvalue!: (%, S) -> S
from RecursiveAggregate S

- showAll?: () -> Boolean if S has SetCategory
`showAll?()`

returns`true`

if all computed entries of streams will be displayed.

- showAllElements: % -> OutputForm if S has SetCategory
`showAllElements(s)`

creates an output form which displays all computed elements.

- showElements: (NonNegativeInteger, %) -> OutputForm if S has SetCategory
`showElements(n, st)`

computes and creates and output form of the first`n`

entries of st.

- size?: (%, NonNegativeInteger) -> Boolean
from Aggregate

- smaller?: (%, %) -> Boolean if % has finiteAggregate and S has Comparable or S has OrderedSet and % has finiteAggregate
from Comparable

- sort!: % -> % if S has OrderedSet and % has finiteAggregate
from LinearAggregate S

- sort: % -> % if S has OrderedSet and % has finiteAggregate
from LinearAggregate S

- sorted?: % -> Boolean if S has OrderedSet and % has finiteAggregate
from LinearAggregate S

- split!: (%, NonNegativeInteger) -> %
from UnaryRecursiveAggregate S

- stream: (() -> S) -> %
`stream(f)`

creates an infinite stream all of whose elements are equal to`f()`

. Note:`stream(f) = [f(), f(), f(), ...]`

.

- stream: (S -> S, S) -> %
`stream(f, x)`

creates an infinite stream whose first element is`x`

and whose`n`

th element (`n > 1`

) is`f`

applied to the previous element. Note:`stream(f, x) = [x, f(x), f(f(x)), ...]`

.

- tail: % -> %
from UnaryRecursiveAggregate S

- third: % -> S
from UnaryRecursiveAggregate S

- trim: (%, S) -> % if S has BasicType and % has finiteAggregate
from LinearAggregate S

- value: % -> S
from RecursiveAggregate S

BasicType if S has Hashable and % has finiteAggregate or S has SetCategory or S has BasicType and % has finiteAggregate

CoercibleTo OutputForm if S has CoercibleTo OutputForm

Comparable if % has finiteAggregate and S has Comparable or S has OrderedSet and % has finiteAggregate

ConvertibleTo InputForm if S has ConvertibleTo InputForm

Eltable(UniversalSegment Integer, %)

Evalable S if S has Evalable S and S has SetCategory

Hashable if S has Hashable and % has finiteAggregate

InnerEvalable(S, S) if S has Evalable S and S has SetCategory

OrderedSet if S has OrderedSet and % has finiteAggregate

PartialOrder if S has OrderedSet and % has finiteAggregate

SetCategory if S has SetCategory