effect-io-ai

Package: effect
Module: Array

Array.pad

Pads or truncates an array to exactly n elements, filling with fill if the array is shorter, or slicing if longer.

When to use

Use to ensure an array has a specific length, padding with a fill value or truncating as needed.

Details

Returns an empty array when n <= 0.

Example (Padding an array)

import { Array } from "effect"

console.log(Array.pad([1, 2, 3], 6, 0)) // [1, 2, 3, 0, 0, 0]

See

Signature

declare const pad: { <A, T>(n: number, fill: T): (self: Array<A>) => Array<A | T>; <A, T>(self: Array<A>, n: number, fill: T): Array<A | T>; }

Source

Since v3.8.4