Hyperlinkv0.8.0-beta.28

Array

Array.removeconsteffect/Array.ts:2006
(i: number): <A>(self: Iterable<A>) => Array<A>
<A>(self: Iterable<A>, i: number): Array<A>

Removes the element at the specified index, returning a new array. If the index is out of bounds, returns a copy of the original.

When to use

Use when you want a missing index to be a no-op and need a fresh array result instead of an optional failure.

Example (Removing an element)

import { Array } from "effect"

console.log(Array.remove([1, 2, 3, 4], 2)) // [1, 2, 4]
console.log(Array.remove([1, 2, 3, 4], 5)) // [1, 2, 3, 4]
Source effect/Array.ts:200611 lines
export const remove: {
  (i: number): <A>(self: Iterable<A>) => Array<A>
  <A>(self: Iterable<A>, i: number): Array<A>
} = dual(2, <A>(self: Iterable<A>, i: number): Array<A> => {
  const out = Array.from(self)
  if (isOutOfBounds(i, out)) {
    return out
  }
  out.splice(i, 1)
  return out
})
Referenced by 1 symbols