Skip to main content
Module

x/fun/mod.ts>array.insert

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Go to Latest
function array.insert
import { array } from "https://deno.land/x/fun@v2.0.0-alpha.12/mod.ts";
const { insert } = 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 insert = A.insert(100); // Insert the value 100
const arr = [1, 2, 3];

const result1 = pipe(arr, insert(0)); // [100, 1, 2, 3]
const result2 = pipe(arr, insert(1)); // [1, 100, 2, 3]
const result3 = pipe(arr, insert(4)); // [1, 2, 3, 100]
const result4 = pipe(arr, insert(4)); // [1, 2, 3]