Hyperlinkv0.8.0-beta.28

Chunk

Chunk.mapconsteffect/Chunk.ts:1707
<S extends Chunk<any>, B>(f: (a: Chunk.Infer<S>, i: number) => B): (
  self: S
) => Chunk.With<S, B>
<A, B>(
  self: NonEmptyChunk<A>,
  f: (a: A, i: number) => B
): NonEmptyChunk<B>
<A, B>(self: Chunk<A>, f: (a: A, i: number) => B): Chunk<B>

Transforms the elements of a chunk using the specified mapping function. If the input chunk is non-empty, the resulting chunk will also be non-empty.

Example (Mapping values)

import { Chunk } from "effect"

const result = Chunk.map(Chunk.make(1, 2), (n) => n + 1)

console.log(Chunk.toArray(result)) // [2, 3]
mapping
Source effect/Chunk.ts:17078 lines
export const map: {
  <S extends Chunk<any>, B>(f: (a: Chunk.Infer<S>, i: number) => B): (self: S) => Chunk.With<S, B>
  <A, B>(self: NonEmptyChunk<A>, f: (a: A, i: number) => B): NonEmptyChunk<B>
  <A, B>(self: Chunk<A>, f: (a: A, i: number) => B): Chunk<B>
} = dual(2, <A, B>(self: Chunk<A>, f: (a: A, i: number) => B): Chunk<B> =>
  self.backing._tag === "ISingleton" ?
    of(f(self.backing.a, 0)) :
    fromArrayUnsafe(pipe(toReadonlyArray(self), RA.map((a, i) => f(a, i)))))
Referenced by 1 symbols