(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]export const const remove: {
(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]
remove: {
(i: numberi: number): <function (type parameter) A in <A>(self: Iterable<A>): Array<A>A>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>): Array<A>A>) => interface Array<T>Array<function (type parameter) A in <A>(self: Iterable<A>): Array<A>A>
<function (type parameter) A in <A>(self: Iterable<A>, i: number): Array<A>A>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>, i: number): Array<A>A>, i: numberi: number): interface Array<T>Array<function (type parameter) A in <A>(self: Iterable<A>, i: number): Array<A>A>
} = dual<(...args: Array<any>) => any, <A>(self: Iterable<A>, i: number) => Array<A>>(arity: 2, body: <A>(self: Iterable<A>, i: number) => Array<A>): ((...args: Array<any>) => any) & (<A>(self: Iterable<A>, i: number) => Array<A>) (+1 overload)Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual(2, <function (type parameter) A in <A>(self: Iterable<A>, i: number): Array<A>A>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>, i: number): Array<A>A>, i: numberi: number): interface Array<T>Array<function (type parameter) A in <A>(self: Iterable<A>, i: number): Array<A>A> => {
const const out: A[]out = const Array: ArrayConstructorExposes the global array constructor.
When to use
Use to access native JavaScript array constructor methods such as isArray
or from from the Effect module namespace.
Example (Accessing the Array constructor)
import { Array } from "effect"
const arr = new Array.Array(3)
console.log(arr) // [undefined, undefined, undefined]
Array.ArrayConstructor.from<A>(iterable: Iterable<A> | ArrayLike<A>): A[] (+3 overloads)Creates an array from an iterable object.
from(self: Iterable<A>self)
if (function isOutOfBounds<A>(
i: number,
as: readonly A[]
): boolean
isOutOfBounds(i: numberi, const out: A[]out)) {
return const out: A[]out
}
const out: A[]out.Array<A>.splice(start: number, deleteCount?: number): A[] (+1 overload)Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
splice(i: numberi, 1)
return const out: A[]out
})