api/classes/qstream
Globals / QStream
Class: QStream<A1, E1, R1>
Represents a sequence of values that are emitted over time.
Type parameters
| Name | Default | Description |
|---|---|---|
A1 | unknown | The value that would be emitted by this stream. |
E1 | never | Possible errors that could be thrown by the stream. |
R1 | unknown | Environment needed to execute this instance. Example: ts import {QStream} from '@qio/core' const s = QStream.of(1, 2, 3).reduce(0, (a, b) => a + b) const runtime = defaultRuntime() runtime.execute(s.drain, console.log) // 6 |
Hierarchy
- QStream
Index
Constructors
Properties
Accessors
Methods
- chain
- const
- filter
- foldLeft
- foldUntil
- forEach
- forEachWhile
- haltWhen
- haltWhenM
- holdFor
- map
- mapAcc
- mapAccM
- mapM
- merge
- pipe
- scan
- scanM
- take
- toQueue
- zipWith
- const
- fromArray
- fromEffect
- fromEventEmitter
- fromQueue
- interval
- of
- produce
- range
- reject
Constructors
constructor
+ new QStream(fold: <A2, E2, R2>(state: A2, cont: (s: A2) => boolean, next: (s: A2, a: A1) => QIO<A2, E2, R2>) => QIO<A2, E1 | E2, R1 & R2>): QStream
Defined in packages/stream/lib/QStream.ts:197
Constructor to create a new [[Stream]]
Parameters:
| Name | Type | |
|---|---|---|
fold | <A2, E2, R2>(state: A2, cont: (s: A2) => boolean, next: (s: A2, a: A1) => QIO<A2, E2, R2>) => QIO<A2, E1 \ | E2, R1 & R2> |
Returns: QStream
Properties
fold
• Readonly fold: <A2, E2, R2>(state: A2, cont: (s: A2) => boolean, next: (s: A2, a: A1) => QIO<A2, E2, R2>) => QIO<A2, E1 | E2, R1 & R2>
Defined in packages/stream/lib/QStream.ts:202
Accessors
asArray
• get asArray(): QIO<A1[], E1, R1>
Defined in packages/stream/lib/QStream.ts:211
Collects all the values from a stream and returns an Array of those values.
Returns: QIO<A1[], E1, R1>
drain
• get drain(): QIO<void, E1, R1>
Defined in packages/stream/lib/QStream.ts:216
Returns: QIO<void, E1, R1>
zipWithIndex
• get zipWithIndex(): QStream<{ 0: A1 ; 1: number }, E1, R1>
Defined in packages/stream/lib/QStream.ts:222
Adds an index to each value emitted by the current stream.
Returns: QStream<{ 0: A1 ; 1: number }, E1, R1>
Methods
chain
▸ chain<A2, E2, R2>(aFb: (a: A1) => QStream<A2, E2, R2>): QStream<A2, E1 | E2, R1 & R2>
Defined in packages/stream/lib/QStream.ts:228
Flattens the inner stream produced by the each value of the provided stream
Type parameters:
| Name |
|---|
A2 |
E2 |
R2 |
Parameters:
| Name | Type |
|---|---|
aFb | (a: A1) => QStream<A2, E2, R2> |
Returns: QStream<A2, E1 | E2, R1 & R2>
const
▸ const<A2>(a: A2): QStream<A2, E1, R1>
Defined in packages/stream/lib/QStream.ts:239
Converts a stream to a constant stream
Type parameters:
| Name |
|---|
A2 |
Parameters:
| Name | Type |
|---|---|
a | A2 |
Returns: QStream<A2, E1, R1>
filter
▸ filter(f: (a: A1) => boolean): QStream<A1, E1, R1>
Defined in packages/stream/lib/QStream.ts:245
Creates a new streams that emits values, satisfied by the provided filter.
Parameters:
| Name | Type |
|---|---|
f | (a: A1) => boolean |
Returns: QStream<A1, E1, R1>
foldLeft
▸ foldLeft<S2>(seed: S2, fn: (s: S2, a: A1) => S2): QIO<S2, E1, R1>
Defined in packages/stream/lib/QStream.ts:260
Folds a stream into a value.
Type parameters:
| Name |
|---|
S2 |
Parameters:
| Name | Type |
|---|---|
seed | S2 |
fn | (s: S2, a: A1) => S2 |
Returns: QIO<S2, E1, R1>
foldUntil
▸ foldUntil<A2, E2, R2, A3, E3>(state: A2, cont: (s: A2) => boolean, next: (s: A2, a: A1) => QIO<A2, E2, R2>, awt: Await<A3, E3>): QIO<A2, E1 | E2, R1 & R2>
Defined in packages/stream/lib/QStream.ts:267
Folds a stream until the Await is set
Type parameters:
| Name |
|---|
A2 |
E2 |
R2 |
A3 |
E3 |
Parameters:
| Name | Type |
|---|---|
state | A2 |
cont | (s: A2) => boolean |
next | (s: A2, a: A1) => QIO<A2, E2, R2> |
awt | Await<A3, E3> |
Returns: QIO<A2, E1 | E2, R1 & R2>
forEach
▸ forEach<A2, E2, R2>(f: (a: A1) => QIO<A2, E2, R2>): QIO<boolean, E1 | E2, R1 & R2>
Defined in packages/stream/lib/QStream.ts:298
Performs the given effect-full function for each value of the stream
Type parameters:
| Name |
|---|
A2 |
E2 |
R2 |
Parameters:
| Name | Type |
|---|---|
f | (a: A1) => QIO<A2, E2, R2> |
Returns: QIO<boolean, E1 | E2, R1 & R2>
forEachWhile
▸ forEachWhile<E2, R2>(f: (a: A1) => QIO<boolean, E2, R2>): QIO<boolean, E1 | E2, R1 & R2>
Defined in packages/stream/lib/QStream.ts:306
Keeps consuming the stream until the effect-full function returns a false.
Type parameters:
| Name |
|---|
E2 |
R2 |
Parameters:
| Name | Type |
|---|---|
f | (a: A1) => QIO<boolean, E2, R2> |
Returns: QIO<boolean, E1 | E2, R1 & R2>
haltWhen
▸ haltWhen<A3, E3>(awt: Await<A3, E3>): QStream<A1, E1, R1>
Defined in packages/stream/lib/QStream.ts:321
Creates a stream that halts after the Await is set.
Type parameters:
| Name |
|---|
A3 |
E3 |
Parameters:
| Name | Type |
|---|---|
awt | Await<A3, E3> |
Returns: QStream<A1, E1, R1>
haltWhenM
▸ haltWhenM<A3, E3, R3>(io: QIO<A3, E3, R3>): QStream<A1, E1, R1 & R3>
Defined in packages/stream/lib/QStream.ts:330
Halt the current stream as soon as the io completes.
Type parameters:
| Name |
|---|
A3 |
E3 |
R3 |
Parameters:
| Name | Type |
|---|---|
io | QIO<A3, E3, R3> |
Returns: QStream<A1, E1, R1 & R3>
holdFor
▸ holdFor(duration: number): QStream<A1, E1, R1>
Defined in packages/stream/lib/QStream.ts:344
Holds each value for the given duration amount.
Parameters:
| Name | Type |
|---|---|
duration | number |
Returns: QStream<A1, E1, R1>
map
▸ map<A2>(ab: (a: A1) => A2): QStream<A2, E1, R1>
Defined in packages/stream/lib/QStream.ts:351
Transforms the values that are being produced by the stream.
Type parameters:
| Name |
|---|
A2 |
Parameters:
| Name | Type |
|---|---|
ab | (a: A1) => A2 |
Returns: QStream<A2, E1, R1>
mapAcc
▸ mapAcc<S, A3>(acc: S, fn: (S: S, A: A1) => { 0: S ; 1: A3 }): QStream<A3, E1, R1>
Defined in packages/stream/lib/QStream.ts:360
Like mapAccM but doesn't produce values effectfully.
Type parameters:
| Name |
|---|
S |
A3 |
Parameters:
| Name | Type |
|---|---|
acc | S |
fn | (S: S, A: A1) => { 0: S ; 1: A3 } |
Returns: QStream<A3, E1, R1>
mapAccM
▸ mapAccM<S, A3, E2, R2>(acc: S, fn: (S: S, A: A1) => QIO<{ 0: S ; 1: A3 }, E2, R2>): QStream<A3, E1 | E2, R1 & R2>
Defined in packages/stream/lib/QStream.ts:371
Effectfully produces new elements using the elements from the current stream and an initial state.
Type parameters:
| Name |
|---|
S |
A3 |
E2 |
R2 |
Parameters:
| Name | Type |
|---|---|
acc | S |
fn | (S: S, A: A1) => QIO<{ 0: S ; 1: A3 }, E2, R2> |
Returns: QStream<A3, E1 | E2, R1 & R2>
mapM
▸ mapM<A2, E2, R2>(f: (a: A1) => QIO<A2, E2, R2>): QStream<A2, E1 | E2, R1 & R2>
Defined in packages/stream/lib/QStream.ts:390
Performs an effect on each value emitted by the stream.
Type parameters:
| Name |
|---|
A2 |
E2 |
R2 |
Parameters:
| Name | Type |
|---|---|
f | (a: A1) => QIO<A2, E2, R2> |
Returns: QStream<A2, E1 | E2, R1 & R2>
merge
▸ merge(that: QStream<A1, E1, R1>): QStream<A1, E1, R1>
Defined in packages/stream/lib/QStream.ts:401
Merges two streams.
Parameters:
| Name | Type |
|---|---|
that | QStream<A1, E1, R1> |
Returns: QStream<A1, E1, R1>
pipe
▸ pipe<A2, E2, R2>(fn: (a1: QStream<A1, E1, R1>) => QStream<A2, E2, R2>): QStream<A2, E2, R2>
Defined in packages/stream/lib/QStream.ts:427
Pipes the current stream through a function that creates a new Stream.
Type parameters:
| Name |
|---|
A2 |
E2 |
R2 |
Parameters:
| Name | Type |
|---|---|
fn | (a1: QStream<A1, E1, R1>) => QStream<A2, E2, R2> |
Returns: QStream<A2, E2, R2>
scan
▸ scan<A3>(acc: A3, fn: (s: A3, a: A1) => A3): QStream<A3, E1, R1>
Defined in packages/stream/lib/QStream.ts:436
Like scanM it creates new values based on some memory.
Type parameters:
| Name |
|---|
A3 |
Parameters:
| Name | Type |
|---|---|
acc | A3 |
fn | (s: A3, a: A1) => A3 |
Returns: QStream<A3, E1, R1>
scanM
▸ scanM<A3, E3, R3>(acc: A3, fn: (s: A3, a: A1) => QIO<A3, E3, R3>): QStream<A3, E1 | E3, R1 & R3>
Defined in packages/stream/lib/QStream.ts:444
Creates a new stream of accumulator values, using an initial accumulator and a function that produces the next set of values.
Type parameters:
| Name |
|---|
A3 |
E3 |
R3 |
Parameters:
| Name | Type |
|---|---|
acc | A3 |
fn | (s: A3, a: A1) => QIO<A3, E3, R3> |
Returns: QStream<A3, E1 | E3, R1 & R3>
take
▸ take(count: number): QStream<A1, E1, R1>
Defined in packages/stream/lib/QStream.ts:453
Emits the first N values skipping the rest.
Parameters:
| Name | Type |
|---|---|
count | number |
Returns: QStream<A1, E1, R1>
toQueue
▸ toQueue(capacity: number): Managed<Queue<A1>, E1, R1>
Defined in packages/stream/lib/QStream.ts:467
Converts a Stream into a managed queue
Parameters:
| Name | Type | Default value |
|---|---|---|
capacity | number | Number.MAX_SAFE_INTEGER |
Returns: Managed<Queue<A1>, E1, R1>
zipWith
▸ zipWith<A2, E2, R2, A>(that: QStream<A2, E2, R2>, fn: (A1: A1, A2: A2) => A): QStream<A, E1 | E2, R1 & R2>
Defined in packages/stream/lib/QStream.ts:489
Combines two streams such that only one value from each stream is consumed at a time.
Type parameters:
| Name |
|---|
A2 |
E2 |
R2 |
A |
Parameters:
| Name | Type |
|---|---|
that | QStream<A2, E2, R2> |
fn | (A1: A1, A2: A2) => A |
Returns: QStream<A, E1 | E2, R1 & R2>
const
▸ Staticconst<A1>(a: A1): QStream<A1>
Defined in packages/stream/lib/QStream.ts:34
Creates a stream that constantly emits the provided value.
Type parameters:
| Name |
|---|
A1 |
Parameters:
| Name | Type |
|---|---|
a | A1 |
Returns: QStream<A1>
fromArray
▸ StaticfromArray<A1>(t: A1[]): QStream<A1>
Defined in packages/stream/lib/QStream.ts:43
Create a stream from an array
Type parameters:
| Name |
|---|
A1 |
Parameters:
| Name | Type |
|---|---|
t | A1[] |
Returns: QStream<A1>
fromEffect
▸ StaticfromEffect<A1, E1, R1>(io: QIO<A1, E1, R1>): QStream<A1, E1, R1>
Defined in packages/stream/lib/QStream.ts:61
Type parameters:
| Name |
|---|
A1 |
E1 |
R1 |
Parameters:
| Name | Type |
|---|---|
io | QIO<A1, E1, R1> |
Returns: QStream<A1, E1, R1>
fromEventEmitter
▸ StaticfromEventEmitter<A>(ev: EventEmitter, name: string): QStream<A>
Defined in packages/stream/lib/QStream.ts:76
Creates a stream of events from an event emitter.
Type parameters:
| Name |
|---|
A |
Parameters:
| Name | Type |
|---|---|
ev | EventEmitter |
name | string |
Returns: QStream<A>
fromQueue
▸ StaticfromQueue<A1>(Q: Queue<A1>): QStream<A1>
Defined in packages/stream/lib/QStream.ts:105
Creates a stream from a Queue
Type parameters:
| Name |
|---|
A1 |
Parameters:
| Name | Type |
|---|---|
Q | Queue<A1> |
Returns: QStream<A1>
interval
▸ Staticinterval<A1>(A1: A1, duration: number): QStream<A1>
Defined in packages/stream/lib/QStream.ts:127
Creates a stream that emits after every given duration of time.
Type parameters:
| Name |
|---|
A1 |
Parameters:
| Name | Type |
|---|---|
A1 | A1 |
duration | number |
Returns: QStream<A1>
of
▸ Staticof<A1>(...t: A1[]): QStream<A1>
Defined in packages/stream/lib/QStream.ts:134
Creates a stream from the provided values
Type parameters:
| Name |
|---|
A1 |
Parameters:
| Name | Type |
|---|---|
...t | A1[] |
Returns: QStream<A1>
produce
▸ Staticproduce<A1, E1, R1>(io: QIO<A1, E1, R1>): QStream<A1, E1, R1>
Defined in packages/stream/lib/QStream.ts:141
Creates a stream by continuously executing the provided IO
Type parameters:
| Name |
|---|
A1 |
E1 |
R1 |
Parameters:
| Name | Type |
|---|---|
io | QIO<A1, E1, R1> |
Returns: QStream<A1, E1, R1>
range
▸ Staticrange(min: number, max: number): QStream<number>
Defined in packages/stream/lib/QStream.ts:163
Creates a stream that emits the given ranges of values
Parameters:
| Name | Type |
|---|---|
min | number |
max | number |
Returns: QStream<number>
reject
▸ Staticreject<E1>(err: E1): QStream<never, E1>
Defined in packages/stream/lib/QStream.ts:195
Type parameters:
| Name |
|---|
E1 |
Parameters:
| Name | Type |
|---|---|
err | E1 |
Returns: QStream<never, E1>