Hyperlinkv0.8.0-beta.28

Array

Array.replicateconsteffect/Array.ts:271
(n: number): <A>(a: A) => NonEmptyArray<A>
<A>(a: A, n: number): NonEmptyArray<A>

Creates a NonEmptyArray containing a value repeated n times.

When to use

Use when you need a non-empty array containing repeated copies of one value.

Details

n is normalized to an integer greater than or equal to 1, so this function always returns at least one element. Supports both data-first and data-last usage.

Example (Repeating a value)

import { Array } from "effect"

const result = Array.replicate("a", 3)
console.log(result) // ["a", "a", "a"]
constructorsmakeBy
Source effect/Array.ts:2714 lines
export const replicate: {
  (n: number): <A>(a: A) => NonEmptyArray<A>
  <A>(a: A, n: number): NonEmptyArray<A>
} = dual(2, <A>(a: A, n: number): NonEmptyArray<A> => makeBy(n, () => a))