Hyperlinkv0.8.0-beta.28

Stream

Stream.bindToconsteffect/Stream.ts:10552
<N extends string>(name: N): <A, E, R>(
  self: Stream<A, E, R>
) => Stream<{ [K in N]: A }, E, R>
<A, E, R, N extends string>(self: Stream<A, E, R>, name: N): Stream<
  { [K in N]: A },
  E,
  R
>

Maps each element into a record keyed by the provided name.

Example (Binding values to a record key)

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

const stream = Stream.make(1, 2, 3).pipe(Stream.bindTo("value"))

const program = Stream.runCollect(stream).pipe(Effect.flatMap(Console.log))

Effect.runPromise(program)
// [{ value: 1 }, { value: 2 }, { value: 3 }]
do notation
export const bindTo: {
  <N extends string>(name: N): <A, E, R>(self: Stream<A, E, R>) => Stream<{ [K in N]: A }, E, R>
  <A, E, R, N extends string>(self: Stream<A, E, R>, name: N): Stream<{ [K in N]: A }, E, R>
} = dual(2, <A, E, R, N extends string>(
  self: Stream<A, E, R>,
  name: N
): Stream<{ [K in N]: A }, E, R> => map(self, (a) => ({ [name]: a } as any)))