Hyperlinkv0.8.0-beta.28

Stream

Stream.bindconsteffect/Stream.ts:10447
<N extends string, A, B, E2, R2>(
  tag: Exclude<N, keyof A>,
  f: (_: NoInfer<A>) => Stream<B, E2, R2>,
  options?:
    | {
        readonly concurrency?: number | "unbounded" | undefined
        readonly bufferSize?: number | undefined
      }
    | undefined
): <E, R>(
  self: Stream<A, E, R>
) => Stream<
  { [K in N | keyof A]: K extends keyof A ? A[K] : B },
  E2 | E,
  R2 | R
>
<A, E, R, N extends string, B, E2, R2>(
  self: Stream<A, E, R>,
  tag: Exclude<N, keyof A>,
  f: (_: NoInfer<A>) => Stream<B, E2, R2>,
  options?:
    | {
        readonly concurrency?: number | "unbounded" | undefined
        readonly bufferSize?: number | undefined
      }
    | undefined
): Stream<
  { [K in N | keyof A]: K extends keyof A ? A[K] : B },
  E | E2,
  R | R2
>

Binds the result of a stream to a field in the do-notation record.

Example (Binding a stream value)

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

const program = Stream.Do.pipe(
  Stream.bind("a", () => Stream.make(1, 2)),
  Stream.bind("b", ({ a }) => Stream.succeed(a + 1))
)

const result = Stream.runCollect(program)

Effect.runPromise(Effect.flatMap(result, Console.log))
// [{ a: 1, b: 2 }, { a: 2, b: 3 }]
do notation
Source effect/Stream.ts:1044728 lines
export const bind: {
  <N extends string, A, B, E2, R2>(
    tag: Exclude<N, keyof A>,
    f: (_: NoInfer<A>) => Stream<B, E2, R2>,
    options?: {
      readonly concurrency?: number | "unbounded" | undefined
      readonly bufferSize?: number | undefined
    } | undefined
  ): <E, R>(self: Stream<A, E, R>) => Stream<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, E2 | E, R2 | R>
  <A, E, R, N extends string, B, E2, R2>(
    self: Stream<A, E, R>,
    tag: Exclude<N, keyof A>,
    f: (_: NoInfer<A>) => Stream<B, E2, R2>,
    options?: {
      readonly concurrency?: number | "unbounded" | undefined
      readonly bufferSize?: number | undefined
    } | undefined
  ): Stream<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, E | E2, R | R2>
} = dual((args) => isStream(args[0]), <A, E, R, N extends string, B, E2, R2>(
  self: Stream<A, E, R>,
  tag: Exclude<N, keyof A>,
  f: (_: NoInfer<A>) => Stream<B, E2, R2>,
  options?: {
    readonly concurrency?: number | "unbounded" | undefined
    readonly bufferSize?: number | undefined
  } | undefined
): Stream<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, E | E2, R | R2> =>
  flatMap(self, (a) => map(f(a), (b) => ({ ...a, [tag]: b } as any)), options))