Hyperlinkv0.8.0-beta.28

Stream

Stream.mapconsteffect/Stream.ts:1878
<A, B>(f: (a: A, i: number) => B): <E, R>(
  self: Stream<A, E, R>
) => Stream<B, E, R>
<A, E, R, B>(self: Stream<A, E, R>, f: (a: A, i: number) => B): Stream<
  B,
  E,
  R
>

Transforms the elements of this stream using the supplied function.

Example (Mapping stream values)

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

const stream = Stream.fromArray([1, 2, 3]).pipe(Stream.map((n, i) => n + i))
const program = Stream.runCollect(stream).pipe(
  Effect.tap((values) => Console.log(values))
)

Effect.runPromise(program)
// [ 1, 3, 5 ]
mapping
Source effect/Stream.ts:187811 lines
export const map: {
  <A, B>(f: (a: A, i: number) => B): <E, R>(self: Stream<A, E, R>) => Stream<B, E, R>
  <A, E, R, B>(self: Stream<A, E, R>, f: (a: A, i: number) => B): Stream<B, E, R>
} = dual(2, <A, E, R, B>(self: Stream<A, E, R>, f: (a: A, i: number) => B): Stream<B, E, R> =>
  suspend(() => {
    let i = 0
    return fromChannel(Channel.map(
      self.channel,
      Arr.map((o) => f(o, i++))
    ))
  }))
Referenced by 14 symbols