Hyperlinkv0.8.0-beta.28

Stream

Stream.fromIterableconsteffect/Stream.ts:1102
<A>(
  iterable: Iterable<A>,
  options?: { readonly chunkSize?: number | undefined }
): Stream<A>

Creates a new Stream from an iterable collection of values.

Details

  • chunkSize: Maximum number of values emitted per chunk.

Example (Creating a stream from an iterable)

import { Console, Effect, Stream } from "effect"

const numbers = [1, 2, 3]

const program = Effect.gen(function*() {
  const stream = Stream.fromIterable(numbers)
  const values = yield* Stream.runCollect(stream)
  yield* Console.log(values)
})

Effect.runPromise(program)
// Output: [ 1, 2, 3 ]
constructors
Source effect/Stream.ts:11029 lines
export const fromIterable = <A>(
  iterable: Iterable<A>,
  options?: {
    readonly chunkSize?: number | undefined
  }
): Stream<A> =>
  Array.isArray(iterable) && options?.chunkSize === undefined
    ? fromArray(iterable)
    : fromChannel(Channel.fromIterableArray(iterable, options?.chunkSize))
Referenced by 6 symbols