Skip to main content
Module

x/fun/mod.ts>array.modify

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

Create a new array by modifying a value of 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 modify = A.modify((n: number) => n + 1); // Increment the value
const arr = [1, 2, 3];

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

Parameters

modifyFn: (a: A) => A