Hyperlinkv0.8.0-beta.28

Array

Array.mapconsteffect/Array.ts:3493
<S extends ReadonlyArray<any>, B>(
  f: (a: ReadonlyArray.Infer<S>, i: number) => B
): (self: S) => ReadonlyArray.With<S, B>
<S extends ReadonlyArray<any>, B>(
  self: S,
  f: (a: ReadonlyArray.Infer<S>, i: number) => B
): ReadonlyArray.With<S, B>

Transforms each element using a function, returning a new array.

When to use

Use to transform each element independently while preserving the array shape.

Details

The function receives (element, index). The return type preserves NonEmptyArray.

Example (Doubling values)

import { Array } from "effect"

console.log(Array.map([1, 2, 3], (x) => x * 2)) // [2, 4, 6]
mappingflatMap
Source effect/Array.ts:34936 lines
export const map: {
  <S extends ReadonlyArray<any>, B>(
    f: (a: ReadonlyArray.Infer<S>, i: number) => B
  ): (self: S) => ReadonlyArray.With<S, B>
  <S extends ReadonlyArray<any>, B>(self: S, f: (a: ReadonlyArray.Infer<S>, i: number) => B): ReadonlyArray.With<S, B>
} = dual(2, <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => B): Array<B> => self.map(f))
Referenced by 13 symbols