Hyperlinkv0.8.0-beta.28

Array

Array.extendconsteffect/Array.ts:4210
<A, B>(f: (as: ReadonlyArray<A>) => B): (
  self: ReadonlyArray<A>
) => Array<B>
<A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B>

Applies a function to each suffix of the array (starting from each index), collecting the results.

When to use

Use when you need to compute a result from every suffix of an array, such as cumulative aggregations from each position.

Details

For index i, the function receives self.slice(i).

Example (Computing suffix lengths)

import { Array } from "effect"

console.log(Array.extend([1, 2, 3], (as) => as.length)) // [3, 2, 1]
mappingscan
Source effect/Array.ts:42107 lines
export const extend: {
  <A, B>(f: (as: ReadonlyArray<A>) => B): (self: ReadonlyArray<A>) => Array<B>
  <A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B>
} = dual(
  2,
  <A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B> => self.map((_, i, as) => f(as.slice(i)))
)