<B>(head: B): <A>(self: Iterable<A>) => Iterable<A | B>
<A, B>(self: Iterable<A>, head: B): Iterable<A | B>Prepends an element to the front of an Iterable, creating a new Iterable.
Example (Prepending an element)
import { Iterable } from "effect"
const numbers = [2, 3, 4]
const withOne = Iterable.prepend(numbers, 1)
console.log(Array.from(withOne)) // [1, 2, 3, 4]
// Works with any iterable
const letters = "abc"
const withZ = Iterable.prepend(letters, "z")
console.log(Array.from(withZ)) // ["z", "a", "b", "c"]export const const prepend: {
<B>(head: B): <A>(
self: Iterable<A>
) => Iterable<A | B>
<A, B>(self: Iterable<A>, head: B): Iterable<
A | B
>
}
Prepends an element to the front of an Iterable, creating a new Iterable.
Example (Prepending an element)
import { Iterable } from "effect"
const numbers = [2, 3, 4]
const withOne = Iterable.prepend(numbers, 1)
console.log(Array.from(withOne)) // [1, 2, 3, 4]
// Works with any iterable
const letters = "abc"
const withZ = Iterable.prepend(letters, "z")
console.log(Array.from(withZ)) // ["z", "a", "b", "c"]
prepend: {
<function (type parameter) B in <B>(head: B): <A>(self: Iterable<A>) => Iterable<A | B>B>(head: Bhead: function (type parameter) B in <B>(head: B): <A>(self: Iterable<A>) => Iterable<A | B>B): <function (type parameter) A in <A>(self: Iterable<A>): Iterable<A | B>A>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>): Iterable<A | B>A>) => interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>): Iterable<A | B>A | function (type parameter) B in <B>(head: B): <A>(self: Iterable<A>) => Iterable<A | B>B>
<function (type parameter) A in <A, B>(self: Iterable<A>, head: B): Iterable<A | B>A, function (type parameter) B in <A, B>(self: Iterable<A>, head: B): Iterable<A | B>B>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A, B>(self: Iterable<A>, head: B): Iterable<A | B>A>, head: Bhead: function (type parameter) B in <A, B>(self: Iterable<A>, head: B): Iterable<A | B>B): interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A, B>(self: Iterable<A>, head: B): Iterable<A | B>A | function (type parameter) B in <A, B>(self: Iterable<A>, head: B): Iterable<A | B>B>
} = dual<(...args: Array<any>) => any, <A, B>(self: Iterable<A>, head: B) => Iterable<A | B>>(arity: 2, body: <A, B>(self: Iterable<A>, head: B) => Iterable<A | B>): ((...args: Array<any>) => any) & (<A, B>(self: Iterable<A>, head: B) => Iterable<A | B>) (+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, B>(self: Iterable<A>, head: B): Iterable<A | B>A, function (type parameter) B in <A, B>(self: Iterable<A>, head: B): Iterable<A | B>B>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A, B>(self: Iterable<A>, head: B): Iterable<A | B>A>, head: Bhead: function (type parameter) B in <A, B>(self: Iterable<A>, head: B): Iterable<A | B>B): interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A, B>(self: Iterable<A>, head: B): Iterable<A | B>A | function (type parameter) B in <A, B>(self: Iterable<A>, head: B): Iterable<A | B>B> => const prependAll: <A, B>(self: Iterable<A>, that: Iterable<B>) => Iterable<A | B> (+1 overload)prependAll(self: Iterable<A>self, [head: Bhead]))