<S extends Chunk<any>>(self: S): Chunk.With<S, Chunk.Infer<S>>Reverses the order of elements in a Chunk.
When to use
Use to read or process chunk elements in reverse order.
Details
If the input chunk is a NonEmptyChunk, the reversed chunk is also a
NonEmptyChunk.
Example (Reversing chunks)
import { Chunk } from "effect"
const chunk = Chunk.make(1, 2, 3)
const result = Chunk.reverse(chunk)
console.log(Chunk.toArray(result)) // [3, 2, 1]export const const reverse: <S extends Chunk<any>>(
self: S
) => Chunk.With<S, Chunk.Infer<S>>
Reverses the order of elements in a Chunk.
When to use
Use to read or process chunk elements in reverse order.
Details
If the input chunk is a NonEmptyChunk, the reversed chunk is also a
NonEmptyChunk.
Example (Reversing chunks)
import { Chunk } from "effect"
const chunk = Chunk.make(1, 2, 3)
const result = Chunk.reverse(chunk)
console.log(Chunk.toArray(result)) // [3, 2, 1]
reverse: <function (type parameter) S in <S extends Chunk<any>>(self: S): Chunk.With<S, Chunk.Infer<S>>S extends 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<any>>(self: S extends Chunk<any>self: function (type parameter) S in <S extends Chunk<any>>(self: S): Chunk.With<S, Chunk.Infer<S>>S) => Chunk.type Chunk<out A>.With<S extends Chunk<any>, A> = S extends NonEmptyChunk<any> ? NonEmptyChunk<A> : Chunk<A>Constructs a Chunk type preserving non-emptiness.
Example (Preserving non-emptiness)
import type { Chunk } from "effect"
declare const regularChunk: Chunk.Chunk<number>
declare const nonEmptyChunk: Chunk.NonEmptyChunk<number>
type WithString1 = Chunk.Chunk.With<typeof regularChunk, string> // Chunk.Chunk<string>
type WithString2 = Chunk.Chunk.With<typeof nonEmptyChunk, string> // Chunk.NonEmptyChunk<string>
With<function (type parameter) S in <S extends Chunk<any>>(self: S): Chunk.With<S, Chunk.Infer<S>>S, Chunk.type Chunk<out A>.Infer<S extends Chunk<any>> = S extends Chunk<infer A> ? A : neverInfers the element type of a Chunk.
Example (Inferring element types)
import type { Chunk } from "effect"
declare const numberChunk: Chunk.Chunk<number>
declare const stringChunk: Chunk.Chunk<string>
type NumberType = Chunk.Chunk.Infer<typeof numberChunk> // number
type StringType = Chunk.Chunk.Infer<typeof stringChunk> // string
Infer<function (type parameter) S in <S extends Chunk<any>>(self: S): Chunk.With<S, Chunk.Infer<S>>S>> = const reverseChunk: <A>(
self: Chunk<A>
) => Chunk<A>
reverseChunk as any