Hyperlinkv0.8.0-beta.28

Channel

Channel.mapconsteffect/Channel.ts:1762
<OutElem, OutElem2>(f: (o: OutElem, i: number) => OutElem2): <
  OutErr,
  OutDone,
  InElem,
  InErr,
  InDone,
  Env
>(
  self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>
) => Channel<OutElem2, OutErr, OutDone, InElem, InErr, InDone, Env>
<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env, OutElem2>(
  self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>,
  f: (o: OutElem, i: number) => OutElem2
): Channel<OutElem2, OutErr, OutDone, InElem, InErr, InDone, Env>

Maps the output of this channel using the specified function.

Example (Mapping channel output)

import { Channel, Data } from "effect"

class TransformError extends Data.TaggedError("TransformError")<{
  readonly reason: string
}> {}

// Basic mapping of channel values
const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5])
const doubledChannel = Channel.map(numbersChannel, (n) => n * 2)
// Outputs: 2, 4, 6, 8, 10

// Transform string data
const wordsChannel = Channel.fromIterable(["hello", "world", "effect"])
const upperCaseChannel = Channel.map(wordsChannel, (word) => word.toUpperCase())
// Outputs: "HELLO", "WORLD", "EFFECT"

// Complex object transformation
type User = { id: number; name: string }
type UserDisplay = { displayName: string; isActive: boolean }

const usersChannel = Channel.fromIterable([
  { id: 1, name: "Alice" },
  { id: 2, name: "Bob" }
])
const displayChannel = Channel.map(usersChannel, (user): UserDisplay => ({
  displayName: `User: ${user.name}`,
  isActive: true
}))
sequencing
Source effect/Channel.ts:176222 lines
export const map: {
  <OutElem, OutElem2>(
    f: (o: OutElem, i: number) => OutElem2
  ): <OutErr, OutDone, InElem, InErr, InDone, Env>(
    self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>
  ) => Channel<OutElem2, OutErr, OutDone, InElem, InErr, InDone, Env>
  <OutElem, OutErr, OutDone, InElem, InErr, InDone, Env, OutElem2>(
    self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>,
    f: (o: OutElem, i: number) => OutElem2
  ): Channel<OutElem2, OutErr, OutDone, InElem, InErr, InDone, Env>
} = dual(
  2,
  <OutElem, OutErr, OutDone, InElem, InErr, InDone, Env, OutElem2>(
    self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>,
    f: (o: OutElem, i: number) => OutElem2
  ): Channel<OutElem2, OutErr, OutDone, InElem, InErr, InDone, Env> =>
    transformPull(self, (pull) =>
      Effect.sync(() => {
        let i = 0
        return Effect.map(pull, (o) => f(o, i++))
      }))
)
Referenced by 11 symbols