(n: number): <A>(self: Iterable<A>) => Iterable<A>
<A>(self: Iterable<A>, n: number): Iterable<A>Drops a max number of elements from the start of an Iterable
Details
n is normalized to a non-negative integer.
Example (Dropping from the start)
import { Iterable } from "effect"
const numbers = [1, 2, 3, 4, 5]
const withoutFirstTwo = Iterable.drop(numbers, 2)
console.log(Array.from(withoutFirstTwo)) // [3, 4, 5]
// Dropping more than available returns empty
const withoutFirstTen = Iterable.drop(numbers, 10)
console.log(Array.from(withoutFirstTen)) // []
// Dropping 0 or negative returns all elements
const all = Iterable.drop(numbers, 0)
console.log(Array.from(all)) // [1, 2, 3, 4, 5]
// Combine with take for slicing
const slice = Iterable.take(Iterable.drop(numbers, 1), 3)
console.log(Array.from(slice)) // [2, 3, 4]export const const drop: {
(n: number): <A>(
self: Iterable<A>
) => Iterable<A>
<A>(self: Iterable<A>, n: number): Iterable<A>
}
Drops a max number of elements from the start of an Iterable
Details
n is normalized to a non-negative integer.
Example (Dropping from the start)
import { Iterable } from "effect"
const numbers = [1, 2, 3, 4, 5]
const withoutFirstTwo = Iterable.drop(numbers, 2)
console.log(Array.from(withoutFirstTwo)) // [3, 4, 5]
// Dropping more than available returns empty
const withoutFirstTen = Iterable.drop(numbers, 10)
console.log(Array.from(withoutFirstTen)) // []
// Dropping 0 or negative returns all elements
const all = Iterable.drop(numbers, 0)
console.log(Array.from(all)) // [1, 2, 3, 4, 5]
// Combine with take for slicing
const slice = Iterable.take(Iterable.drop(numbers, 1), 3)
console.log(Array.from(slice)) // [2, 3, 4]
drop: {
(n: numbern: number): <function (type parameter) A in <A>(self: Iterable<A>): Iterable<A>A>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>): Iterable<A>A>) => interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>): Iterable<A>A>
<function (type parameter) A in <A>(self: Iterable<A>, n: number): Iterable<A>A>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>, n: number): Iterable<A>A>, n: numbern: number): interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>, n: number): Iterable<A>A>
} = dual<(...args: Array<any>) => any, <A>(self: Iterable<A>, n: number) => Iterable<A>>(arity: 2, body: <A>(self: Iterable<A>, n: number) => Iterable<A>): ((...args: Array<any>) => any) & (<A>(self: Iterable<A>, n: number) => Iterable<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>, n: number): Iterable<A>A>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>, n: number): Iterable<A>A>, n: numbern: number): interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>, n: number): Iterable<A>A> => ({
[var Symbol: SymbolConstructorSymbol.SymbolConstructor.iterator: typeof Symbol.iteratorA method that returns the default iterator for an object. Called by the semantics of the
for-of statement.
iterator]() {
const const iterator: Iterator<A, any, any>iterator = self: Iterable<A>self[var Symbol: SymbolConstructorSymbol.SymbolConstructor.iterator: typeof Symbol.iteratorA method that returns the default iterator for an object. Called by the semantics of the
for-of statement.
iterator]()
let let i: numberi = 0
return {
Iterator<A, any, any>.next(...[value]: [] | [any]): IteratorResult<A, any>next() {
while (let i: numberi < n: numbern) {
const const result: IteratorResult<A, any>result = const iterator: Iterator<A, any, any>iterator.Iterator<A, any, any>.next(...[value]: [] | [any]): IteratorResult<A, any>next()
if (const result: IteratorResult<A, any>result.done?: boolean | undefineddone) {
return { IteratorReturnResult<TReturn>.done: truedone: true, IteratorReturnResult<any>.value: anyvalue: var undefinedundefined }
}
let i: numberi++
}
return const iterator: Iterator<A, any, any>iterator.Iterator<A, any, any>.next(...[value]: [] | [any]): IteratorResult<A, any>next()
}
}
}
}))