| 1682 | * @category mapping |
| 1683 | * @since 2.0.0 |
| 1684 | */ |
| 1685 | export const map: { |
| 1686 | <A, B>(f: (a: A, i: number) => B): <E, R>(self: Stream<A, E, R>) => Stream<B, E, R> |
| 1687 | <A, E, R, B>(self: Stream<A, E, R>, f: (a: A, i: number) => B): Stream<B, E, R> |
| 1688 | } = dual(2, <A, E, R, B>(self: Stream<A, E, R>, f: (a: A, i: number) => B): Stream<B, E, R> => |
| 1689 | suspend(() => { |
| 1690 | let i = 0 |
| 1691 | return fromChannel(Channel.map( |
| 1692 | self.channel, |
| 1693 | Arr.map((o) => f(o, i++)) |
| 1694 | )) |
| 1695 | })) |
| 1696 | |
| 1697 | /** |
| 1698 | * Maps both the failure and success channels of a stream. |
| 1699 | * |
| 1700 | * **Example** (Mapping both the failure and success channels of a stream) |
| 1701 | * |
| 1702 | * ```ts import.meta.vitest |
| 1703 | * import { Effect, Stream } from "effect" |
| 1704 | * |
| 1705 | * const mapper = { |
| 1706 | * onFailure: (error: string) => `error: ${error}`, |
| 1707 | * onSuccess: (value: number) => value * 2 |
| 1708 | * } |