Skip to main content
Module

x/fun/mod.ts>array.insertAt

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function array.insertAt
import { array } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { insertAt } = array;

Create a new array by inserting a value into an array at an index. If the index is out of range of the existing array then no change is made.

Examples

Example 1

import * as A from "./array.ts";
import { pipe } from "./fn.ts";

const insertAt = A.insertAt(0); // Insert at index 0
const arr = [1, 2, 3];

const result1 = pipe(arr, insertAt(0)); // [0, 1, 2, 3]
const result2 = pipe(arr, insertAt(1)); // [1, 1, 2, 3]
const result3 = pipe(
  arr,
  A.insertAt(100)(100),
); // [1, 2, 3]

Parameters

index: number