<A, Pass, Fail>(
f: (input: NoInfer<A>, i: number) => Result<Pass, Fail>
): (self: Chunk<A>) => [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]
<A, Pass, Fail>(
self: Chunk<A>,
f: (input: A, i: number) => Result<Pass, Fail>
): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Splits a chunk using a Filter into failures and successes.
Details
Returns [excluded, satisfying]. The filter receives (element, index).
Example (Partitioning with a Result)
import { Chunk, Result } from "effect"
const [excluded, satisfying] = Chunk.partition(Chunk.make(1, -2, 3), (n, i) =>
n > 0 ? Result.succeed(n + i) : Result.fail(`negative:${n}`)
)
console.log(Chunk.toArray(excluded)) // ["negative:-2"]
console.log(Chunk.toArray(satisfying)) // [1, 5]export const const partition: {
<A, Pass, Fail>(
f: (
input: NoInfer<A>,
i: number
) => Result<Pass, Fail>
): (
self: Chunk<A>
) => [
excluded: Chunk<Fail>,
satisfying: Chunk<Pass>
]
<A, Pass, Fail>(
self: Chunk<A>,
f: (input: A, i: number) => Result<Pass, Fail>
): [
excluded: Chunk<Fail>,
satisfying: Chunk<Pass>
]
}
Splits a chunk using a Filter into failures and successes.
Details
Returns [excluded, satisfying]. The filter receives (element, index).
Example (Partitioning with a Result)
import { Chunk, Result } from "effect"
const [excluded, satisfying] = Chunk.partition(Chunk.make(1, -2, 3), (n, i) =>
n > 0 ? Result.succeed(n + i) : Result.fail(`negative:${n}`)
)
console.log(Chunk.toArray(excluded)) // ["negative:-2"]
console.log(Chunk.toArray(satisfying)) // [1, 5]
partition: {
<function (type parameter) A in <A, Pass, Fail>(f: (input: NoInfer<A>, i: number) => Result<Pass, Fail>): (self: Chunk<A>) => [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]A, function (type parameter) Pass in <A, Pass, Fail>(f: (input: NoInfer<A>, i: number) => Result<Pass, Fail>): (self: Chunk<A>) => [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Pass, function (type parameter) Fail in <A, Pass, Fail>(f: (input: NoInfer<A>, i: number) => Result<Pass, Fail>): (self: Chunk<A>) => [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Fail>(
f: (
input: NoInfer<A>,
i: number
) => Result<Pass, Fail>
f: (input: NoInfer<A>input: type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) A in <A, Pass, Fail>(f: (input: NoInfer<A>, i: number) => Result<Pass, Fail>): (self: Chunk<A>) => [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]A>, i: numberi: number) => type Result<A, E = never> = R.Success<A, E> | R.Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<function (type parameter) Pass in <A, Pass, Fail>(f: (input: NoInfer<A>, i: number) => Result<Pass, Fail>): (self: Chunk<A>) => [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Pass, function (type parameter) Fail in <A, Pass, Fail>(f: (input: NoInfer<A>, i: number) => Result<Pass, Fail>): (self: Chunk<A>) => [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Fail>
): (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, Pass, Fail>(f: (input: NoInfer<A>, i: number) => Result<Pass, Fail>): (self: Chunk<A>) => [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]A>) => [Chunk<Fail>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>
excluded: 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) Fail in <A, Pass, Fail>(f: (input: NoInfer<A>, i: number) => Result<Pass, Fail>): (self: Chunk<A>) => [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Fail>, Chunk<Pass>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>
satisfying: 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) Pass in <A, Pass, Fail>(f: (input: NoInfer<A>, i: number) => Result<Pass, Fail>): (self: Chunk<A>) => [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Pass>]
<function (type parameter) A in <A, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]A, function (type parameter) Pass in <A, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Pass, function (type parameter) Fail in <A, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Fail>(
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, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]A>,
f: (
input: A,
i: number
) => Result<Pass, Fail>
f: (input: Ainput: function (type parameter) A in <A, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]A, i: numberi: number) => type Result<A, E = never> = R.Success<A, E> | R.Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<function (type parameter) Pass in <A, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Pass, function (type parameter) Fail in <A, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Fail>
): [Chunk<Fail>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>
excluded: 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) Fail in <A, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Fail>, Chunk<Pass>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>
satisfying: 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) Pass in <A, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Pass>]
} = dual<(...args: Array<any>) => any, <A, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>) => [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]>(arity: 2, body: <A, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>) => [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]): ((...args: Array<any>) => any) & (<A, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>) => [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]) (+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, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]A, function (type parameter) Pass in <A, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Pass, function (type parameter) Fail in <A, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Fail>(
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, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]A>,
f: (
input: A,
i: number
) => Result<Pass, Fail>
f: (input: Ainput: function (type parameter) A in <A, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]A, i: numberi: number) => type Result<A, E = never> = R.Success<A, E> | R.Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<function (type parameter) Pass in <A, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Pass, function (type parameter) Fail in <A, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Fail>
): [Chunk<Fail>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>
excluded: 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) Fail in <A, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Fail>, Chunk<Pass>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>
satisfying: 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) Pass in <A, Pass, Fail>(self: Chunk<A>, f: (input: A, i: number) => Result<Pass, Fail>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]Pass>] => {
const [const excluded: anyexcluded, const satisfying: anysatisfying] = import RARA.partition(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, f: (
input: A,
i: number
) => Result<Pass, Fail>
f)
return [const fromArrayUnsafe: <A>(
self: ReadonlyArray<A>
) => Chunk<A>
Wraps an array into a chunk without copying.
When to use
Use when the input array can be shared with the resulting Chunk and avoiding
a copy matters.
Gotchas
Mutating the source array after wrapping can mutate the resulting Chunk.
Example (Creating chunks without copying arrays)
import { Chunk } from "effect"
const array = [1, 2, 3, 4, 5]
const chunk = Chunk.fromArrayUnsafe(array)
console.log(Chunk.toArray(chunk)) // [1, 2, 3, 4, 5]
// Warning: Since this doesn't copy the array, mutations affect the chunk
array[0] = 999
console.log(Chunk.toArray(chunk)) // [999, 2, 3, 4, 5]
fromArrayUnsafe(const excluded: anyexcluded), const fromArrayUnsafe: <A>(
self: ReadonlyArray<A>
) => Chunk<A>
Wraps an array into a chunk without copying.
When to use
Use when the input array can be shared with the resulting Chunk and avoiding
a copy matters.
Gotchas
Mutating the source array after wrapping can mutate the resulting Chunk.
Example (Creating chunks without copying arrays)
import { Chunk } from "effect"
const array = [1, 2, 3, 4, 5]
const chunk = Chunk.fromArrayUnsafe(array)
console.log(Chunk.toArray(chunk)) // [1, 2, 3, 4, 5]
// Warning: Since this doesn't copy the array, mutations affect the chunk
array[0] = 999
console.log(Chunk.toArray(chunk)) // [999, 2, 3, 4, 5]
fromArrayUnsafe(const satisfying: anysatisfying)]
}
)