<Arr extends ReadonlyArray<ReadonlyArray<any>>>(...arrays: Arr): Stream<
Arr[number][number]
>Creates a stream from an arbitrary number of arrays.
Example (Creating a stream from an arbitrary number of arrays)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const stream = Stream.fromArrays([1, 2], [3, 4])
const values = yield* Stream.runCollect(stream)
yield* Console.log(values)
})
Effect.runPromise(program)
// Output: [ 1, 2, 3, 4 ]export const const fromArrays: <
Arr extends ReadonlyArray<ReadonlyArray<any>>
>(
...arrays: Arr
) => Stream<Arr[number][number]>
Creates a stream from an arbitrary number of arrays.
Example (Creating a stream from an arbitrary number of arrays)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const stream = Stream.fromArrays([1, 2], [3, 4])
const values = yield* Stream.runCollect(stream)
yield* Console.log(values)
})
Effect.runPromise(program)
// Output: [ 1, 2, 3, 4 ]
fromArrays = <function (type parameter) Arr in <Arr extends ReadonlyArray<ReadonlyArray<any>>>(...arrays: Arr): Stream<Arr[number][number]>Arr extends interface ReadonlyArray<T>ReadonlyArray<interface ReadonlyArray<T>ReadonlyArray<any>>>(
...arrays: Arr extends ReadonlyArray<ReadonlyArray<any>>arrays: function (type parameter) Arr in <Arr extends ReadonlyArray<ReadonlyArray<any>>>(...arrays: Arr): Stream<Arr[number][number]>Arr
): interface Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<function (type parameter) Arr in <Arr extends ReadonlyArray<ReadonlyArray<any>>>(...arrays: Arr): Stream<Arr[number][number]>Arr[number][number]> => const fromChannel: <
Arr extends Arr.NonEmptyReadonlyArray<any>,
E,
R
>(
channel: Channel.Channel<
Arr,
E,
void,
unknown,
unknown,
unknown,
R
>
) => Stream<
Arr extends Arr.NonEmptyReadonlyArray<infer A>
? A
: never,
E,
R
>
Creates a stream from a array-emitting Channel.
Example (Creating a stream from an array-emitting channel)
import { Channel, Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const channel = Channel.succeed([1, 2, 3] as const)
const stream = Stream.fromChannel(channel)
const result = yield* Stream.runCollect(stream)
yield* Console.log(result)
})
// Output: [ 1, 2, 3 ]
fromChannel(import ChannelChannel.const fromArray: <A>(
array: ReadonlyArray<A>
) => Channel<A>
Creates a Channel that emits all elements from an array.
Example (Creating channels from arrays)
import { Channel } from "effect"
const channel = Channel.fromArray([1, 2, 3, 4, 5])
// Emits: 1, 2, 3, 4, 5
fromArray(import ArrArr.const filter: {
<A, B extends A>(
refinement: (
a: NoInfer<A>,
i: number
) => a is B
): (self: Iterable<A>) => Array<B>
<A>(
predicate: (
a: NoInfer<A>,
i: number
) => boolean
): (self: Iterable<A>) => Array<A>
<A, B extends A>(
self: Iterable<A>,
refinement: (a: A, i: number) => a is B
): Array<B>
<A>(
self: Iterable<A>,
predicate: (a: A, i: number) => boolean
): Array<A>
}
filter(arrays: Arr extends ReadonlyArray<ReadonlyArray<any>>arrays, import ArrArr.const isReadonlyArrayNonEmpty: <A>(
self: ReadonlyArray<A>
) => self is NonEmptyReadonlyArray<A>
Checks whether a ReadonlyArray is non-empty, narrowing the type to
NonEmptyReadonlyArray.
When to use
Use when you need to prove a readonly array has at least one element without
requiring mutable array methods afterward.
Example (Checking for a non-empty readonly array)
import { Array } from "effect"
console.log(Array.isReadonlyArrayNonEmpty([])) // false
console.log(Array.isReadonlyArrayNonEmpty([1, 2, 3])) // true
isReadonlyArrayNonEmpty)))