<B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => B
<A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): BReduces the elements of a chunk from right to left.
Example (Reducing from the right)
import { Chunk } from "effect"
const chunk = Chunk.make(1, 2, 3, 4)
const result = Chunk.reduceRight(chunk, 0, (acc, n) => acc + n)
console.log(result) // 10
// String building (right to left)
const words = Chunk.make("a", "b", "c")
const reversed = Chunk.reduceRight(
words,
"",
(acc, word, i) => acc + `${i}:${word} `
)
console.log(reversed) // "2:c 1:b 0:a "
// Subtract from right to left
const subtraction = Chunk.reduceRight(chunk, 0, (acc, n) => n - acc)
console.log(subtraction) // -2 (4 - (3 - (2 - (1 - 0))))folding
Source effect/Chunk.ts:28944 lines
export const const reduceRight: {
<B, A>(b: B, f: (b: B, a: A, i: number) => B): (
self: Chunk<A>
) => B
<A, B>(
self: Chunk<A>,
b: B,
f: (b: B, a: A, i: number) => B
): B
}
Reduces the elements of a chunk from right to left.
Example (Reducing from the right)
import { Chunk } from "effect"
const chunk = Chunk.make(1, 2, 3, 4)
const result = Chunk.reduceRight(chunk, 0, (acc, n) => acc + n)
console.log(result) // 10
// String building (right to left)
const words = Chunk.make("a", "b", "c")
const reversed = Chunk.reduceRight(
words,
"",
(acc, word, i) => acc + `${i}:${word} `
)
console.log(reversed) // "2:c 1:b 0:a "
// Subtract from right to left
const subtraction = Chunk.reduceRight(chunk, 0, (acc, n) => n - acc)
console.log(subtraction) // -2 (4 - (3 - (2 - (1 - 0))))
reduceRight: {
<function (type parameter) B in <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => BB, function (type parameter) A in <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => BA>(b: Bb: function (type parameter) B in <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => BB, f: (b: B, a: A, i: number) => Bf: (b: Bb: function (type parameter) B in <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => BB, a: Aa: function (type parameter) A in <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => BA, i: numberi: number) => function (type parameter) B in <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => BB): (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 <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => BA>) => function (type parameter) B in <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => BB
<function (type parameter) A in <A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): BA, function (type parameter) B in <A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): BB>(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>, b: B, f: (b: B, a: A, i: number) => B): BA>, b: Bb: function (type parameter) B in <A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): BB, f: (b: B, a: A, i: number) => Bf: (b: Bb: function (type parameter) B in <A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): BB, a: Aa: function (type parameter) A in <A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): BA, i: numberi: number) => function (type parameter) B in <A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): BB): function (type parameter) B in <A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): BB
} = import RARA.reduceRight