<B>(i: number, b: B): <A>(self: Chunk<A>) => O.Option<Chunk<B | A>>
<A, B>(self: Chunk<A>, i: number, b: B): O.Option<Chunk<B | A>>Changes the element at the specified index safely, creating a new Chunk,
or returns None if the index is out of bounds.
Example (Replacing an element)
import { Chunk } from "effect"
const chunk = Chunk.make("a", "b", "c", "d")
const result = Chunk.replace(chunk, 1, "X")
console.log(result) // Option.some(Chunk.make("a", "X", "c", "d"))
// Index out of bounds returns None
const outOfBounds = chunk.pipe(Chunk.replace(10, "Y"))
console.log(outOfBounds) // Option.none()
// Negative index returns None
const negative = chunk.pipe(Chunk.replace(-1, "Z"))
console.log(negative) // Option.none()export const const replace: {
<B>(i: number, b: B): <A>(
self: Chunk<A>
) => O.Option<Chunk<B | A>>
<A, B>(
self: Chunk<A>,
i: number,
b: B
): O.Option<Chunk<B | A>>
}
Changes the element at the specified index safely, creating a new Chunk,
or returns None if the index is out of bounds.
Example (Replacing an element)
import { Chunk } from "effect"
const chunk = Chunk.make("a", "b", "c", "d")
const result = Chunk.replace(chunk, 1, "X")
console.log(result) // Option.some(Chunk.make("a", "X", "c", "d"))
// Index out of bounds returns None
const outOfBounds = chunk.pipe(Chunk.replace(10, "Y"))
console.log(outOfBounds) // Option.none()
// Negative index returns None
const negative = chunk.pipe(Chunk.replace(-1, "Z"))
console.log(negative) // Option.none()
replace: {
<function (type parameter) B in <B>(i: number, b: B): <A>(self: Chunk<A>) => O.Option<Chunk<B | A>>B>(i: numberi: number, b: Bb: function (type parameter) B in <B>(i: number, b: B): <A>(self: Chunk<A>) => O.Option<Chunk<B | A>>B): <function (type parameter) A in <A>(self: Chunk<A>): O.Option<Chunk<B | 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>): O.Option<Chunk<B | A>>A>) => import OO.type Option<A> = O.None<A> | O.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<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) B in <B>(i: number, b: B): <A>(self: Chunk<A>) => O.Option<Chunk<B | A>>B | function (type parameter) A in <A>(self: Chunk<A>): O.Option<Chunk<B | A>>A>>
<function (type parameter) A in <A, B>(self: Chunk<A>, i: number, b: B): O.Option<Chunk<B | A>>A, function (type parameter) B in <A, B>(self: Chunk<A>, i: number, b: B): O.Option<Chunk<B | A>>B>(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, B>(self: Chunk<A>, i: number, b: B): O.Option<Chunk<B | A>>A>, i: numberi: number, b: Bb: function (type parameter) B in <A, B>(self: Chunk<A>, i: number, b: B): O.Option<Chunk<B | A>>B): import OO.type Option<A> = O.None<A> | O.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<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) B in <A, B>(self: Chunk<A>, i: number, b: B): O.Option<Chunk<B | A>>B | function (type parameter) A in <A, B>(self: Chunk<A>, i: number, b: B): O.Option<Chunk<B | A>>A>>
} = dual<(...args: Array<any>) => any, <A, B>(self: Chunk<A>, i: number, b: B) => O.Option<Chunk<B | A>>>(arity: 3, body: <A, B>(self: Chunk<A>, i: number, b: B) => O.Option<Chunk<B | A>>): ((...args: Array<any>) => any) & (<A, B>(self: Chunk<A>, i: number, b: B) => O.Option<Chunk<B | 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(3, <function (type parameter) A in <A, B>(self: Chunk<A>, i: number, b: B): O.Option<Chunk<B | A>>A, function (type parameter) B in <A, B>(self: Chunk<A>, i: number, b: B): O.Option<Chunk<B | A>>B>(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, B>(self: Chunk<A>, i: number, b: B): O.Option<Chunk<B | A>>A>, i: numberi: number, b: Bb: function (type parameter) B in <A, B>(self: Chunk<A>, i: number, b: B): O.Option<Chunk<B | A>>B): import OO.type Option<A> = O.None<A> | O.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<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) B in <A, B>(self: Chunk<A>, i: number, b: B): O.Option<Chunk<B | A>>B | function (type parameter) A in <A, B>(self: Chunk<A>, i: number, b: B): O.Option<Chunk<B | A>>A>> => const modify: {
<A, B>(i: number, f: (a: A) => B): (
self: Chunk<A>
) => O.Option<Chunk<A | B>>
<A, B>(
self: Chunk<A>,
i: number,
f: (a: A) => B
): O.Option<Chunk<A | B>>
}
modify(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, i: numberi, () => b: Bb))