<A2>(a: A2): <A>(self: Chunk<A>) => NonEmptyChunk<A2 | A>
<A, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<A | A2>Appends the specified element to the end of the Chunk.
When to use
Use to add one element after the existing chunk elements and return a
NonEmptyChunk.
Example (Appending an element)
import { Chunk } from "effect"
const chunk = Chunk.make(1, 2, 3)
const newChunk = Chunk.append(chunk, 4)
console.log(Chunk.toArray(newChunk)) // [1, 2, 3, 4]
// Appending to empty chunk
const emptyChunk = Chunk.empty<number>()
const singleElement = Chunk.append(emptyChunk, 42)
console.log(Chunk.toArray(singleElement)) // [42]export const const append: {
<A2>(a: A2): <A>(
self: Chunk<A>
) => NonEmptyChunk<A2 | A>
<A, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<
A | A2
>
}
Appends the specified element to the end of the Chunk.
When to use
Use to add one element after the existing chunk elements and return a
NonEmptyChunk.
Example (Appending an element)
import { Chunk } from "effect"
const chunk = Chunk.make(1, 2, 3)
const newChunk = Chunk.append(chunk, 4)
console.log(Chunk.toArray(newChunk)) // [1, 2, 3, 4]
// Appending to empty chunk
const emptyChunk = Chunk.empty<number>()
const singleElement = Chunk.append(emptyChunk, 42)
console.log(Chunk.toArray(singleElement)) // [42]
append: {
<function (type parameter) A2 in <A2>(a: A2): <A>(self: Chunk<A>) => NonEmptyChunk<A2 | A>A2>(a: A2a: function (type parameter) A2 in <A2>(a: A2): <A>(self: Chunk<A>) => NonEmptyChunk<A2 | A>A2): <function (type parameter) A in <A>(self: Chunk<A>): NonEmptyChunk<A2 | A>A>(self: Chunk<A>(parameter) self: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self: interface Chunk<out A>A Chunk is an immutable, ordered collection optimized for efficient concatenation and access patterns.
Example (Inspecting chunk values)
import { Chunk } from "effect"
const chunk: Chunk.Chunk<number> = Chunk.make(1, 2, 3)
console.log(chunk.length) // 3
console.log(Chunk.toArray(chunk)) // [1, 2, 3]
A namespace containing utility types for Chunk operations.
Example (Working with Chunk utility types)
import type { Chunk } from "effect"
// Extract the element type from a Chunk
declare const chunk: Chunk.Chunk<string>
type ElementType = Chunk.Chunk.Infer<typeof chunk> // string
// Create a preserving non-emptiness
declare const nonEmptyChunk: Chunk.NonEmptyChunk<number>
type WithString = Chunk.Chunk.With<typeof nonEmptyChunk, string> // Chunk.NonEmptyChunk<string>
Chunk<function (type parameter) A in <A>(self: Chunk<A>): NonEmptyChunk<A2 | A>A>) => interface NonEmptyChunk<out A>A non-empty Chunk guaranteed to contain at least one element.
Example (Working with non-empty chunks)
import { Chunk } from "effect"
const nonEmptyChunk: Chunk.NonEmptyChunk<number> = Chunk.make(1, 2, 3)
console.log(Chunk.headNonEmpty(nonEmptyChunk)) // 1
console.log(Chunk.lastNonEmpty(nonEmptyChunk)) // 3
NonEmptyChunk<function (type parameter) A2 in <A2>(a: A2): <A>(self: Chunk<A>) => NonEmptyChunk<A2 | A>A2 | function (type parameter) A in <A>(self: Chunk<A>): NonEmptyChunk<A2 | A>A>
<function (type parameter) A in <A, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<A | A2>A, function (type parameter) A2 in <A, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<A | A2>A2>(self: Chunk<A>(parameter) self: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self: interface Chunk<out A>A Chunk is an immutable, ordered collection optimized for efficient concatenation and access patterns.
Example (Inspecting chunk values)
import { Chunk } from "effect"
const chunk: Chunk.Chunk<number> = Chunk.make(1, 2, 3)
console.log(chunk.length) // 3
console.log(Chunk.toArray(chunk)) // [1, 2, 3]
A namespace containing utility types for Chunk operations.
Example (Working with Chunk utility types)
import type { Chunk } from "effect"
// Extract the element type from a Chunk
declare const chunk: Chunk.Chunk<string>
type ElementType = Chunk.Chunk.Infer<typeof chunk> // string
// Create a preserving non-emptiness
declare const nonEmptyChunk: Chunk.NonEmptyChunk<number>
type WithString = Chunk.Chunk.With<typeof nonEmptyChunk, string> // Chunk.NonEmptyChunk<string>
Chunk<function (type parameter) A in <A, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<A | A2>A>, a: A2a: function (type parameter) A2 in <A, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<A | A2>A2): interface NonEmptyChunk<out A>A non-empty Chunk guaranteed to contain at least one element.
Example (Working with non-empty chunks)
import { Chunk } from "effect"
const nonEmptyChunk: Chunk.NonEmptyChunk<number> = Chunk.make(1, 2, 3)
console.log(Chunk.headNonEmpty(nonEmptyChunk)) // 1
console.log(Chunk.lastNonEmpty(nonEmptyChunk)) // 3
NonEmptyChunk<function (type parameter) A in <A, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<A | A2>A | function (type parameter) A2 in <A, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<A | A2>A2>
} = dual<(...args: Array<any>) => any, <A, A2>(self: Chunk<A>, a: A2) => NonEmptyChunk<A | A2>>(arity: 2, body: <A, A2>(self: Chunk<A>, a: A2) => NonEmptyChunk<A | A2>): ((...args: Array<any>) => any) & (<A, A2>(self: Chunk<A>, a: A2) => NonEmptyChunk<A | A2>) (+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, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<A | A2>A, function (type parameter) A2 in <A, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<A | A2>A2>(self: Chunk<A>(parameter) self: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self: interface Chunk<out A>A Chunk is an immutable, ordered collection optimized for efficient concatenation and access patterns.
Example (Inspecting chunk values)
import { Chunk } from "effect"
const chunk: Chunk.Chunk<number> = Chunk.make(1, 2, 3)
console.log(chunk.length) // 3
console.log(Chunk.toArray(chunk)) // [1, 2, 3]
A namespace containing utility types for Chunk operations.
Example (Working with Chunk utility types)
import type { Chunk } from "effect"
// Extract the element type from a Chunk
declare const chunk: Chunk.Chunk<string>
type ElementType = Chunk.Chunk.Infer<typeof chunk> // string
// Create a preserving non-emptiness
declare const nonEmptyChunk: Chunk.NonEmptyChunk<number>
type WithString = Chunk.Chunk.With<typeof nonEmptyChunk, string> // Chunk.NonEmptyChunk<string>
Chunk<function (type parameter) A in <A, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<A | A2>A>, a: A2a: function (type parameter) A2 in <A, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<A | A2>A2): interface NonEmptyChunk<out A>A non-empty Chunk guaranteed to contain at least one element.
Example (Working with non-empty chunks)
import { Chunk } from "effect"
const nonEmptyChunk: Chunk.NonEmptyChunk<number> = Chunk.make(1, 2, 3)
console.log(Chunk.headNonEmpty(nonEmptyChunk)) // 1
console.log(Chunk.lastNonEmpty(nonEmptyChunk)) // 3
NonEmptyChunk<function (type parameter) A in <A, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<A | A2>A | function (type parameter) A2 in <A, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<A | A2>A2> => const appendAll: {
<S extends Chunk<any>, T extends Chunk<any>>(
that: T
): (
self: S
) => Chunk.OrNonEmpty<
S,
T,
Chunk.Infer<S> | Chunk.Infer<T>
>
<A, B>(
self: Chunk<A>,
that: NonEmptyChunk<B>
): NonEmptyChunk<A | B>
<A, B>(
self: NonEmptyChunk<A>,
that: Chunk<B>
): NonEmptyChunk<A | B>
<A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<
A | B
>
}
appendAll(self: Chunk<A>(parameter) self: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self, const of: <A>(a: A) => NonEmptyChunk<A>Builds a NonEmptyChunk from a single element.
Example (Creating a single-element chunk)
import { Chunk } from "effect"
const chunk = Chunk.of("hello")
console.log(Chunk.toArray(chunk)) // ["hello"]
of(a: A2a)))