diff --git "a/.opencode/node_modules/effect/src/Chunk.ts" "b/.opencode/node_modules/effect/src/Chunk.ts" --- "a/.opencode/node_modules/effect/src/Chunk.ts" +++ "b/.opencode/node_modules/effect/src/Chunk.ts" @@ -1,70 +1,11 @@ /** - * The `Chunk` module provides an immutable, high-performance sequence data structure - * optimized for functional programming patterns. A `Chunk` is a persistent data structure - * that supports efficient append, prepend, and concatenation operations. + * Stores many values in an immutable ordered collection. * - * ## What is a Chunk? - * - * A `Chunk` is an immutable sequence of elements of type `A` that provides: - * - **O(1) append and prepend operations** - * - **Efficient concatenation** through tree-like structure - * - **Memory efficiency** with structural sharing - * - **Rich API** with functional programming operations - * - **Type safety** with full TypeScript integration - * - * ## Key Features - * - * - **Immutable**: All operations return new chunks without modifying the original - * - **Efficient**: Optimized data structure with logarithmic complexity for most operations - * - **Functional**: Rich set of transformation and combination operators - * - **Lazy evaluation**: Many operations are deferred until needed - * - **Interoperable**: Easy conversion to/from arrays and other collections - * - * ## Performance Characteristics - * - * - **Append/Prepend**: O(1) amortized - * - **Random Access**: O(log n) - * - **Concatenation**: O(log min(m, n)) - * - **Iteration**: O(n) - * - **Memory**: Structural sharing minimizes allocation - * - * @example - * ```ts - * import { Chunk } from "effect" - * - * // Creating chunks - * const chunk1 = Chunk.fromIterable([1, 2, 3]) - * const chunk2 = Chunk.fromIterable([4, 5, 6]) - * const empty = Chunk.empty() - * - * // Combining chunks - * const combined = Chunk.appendAll(chunk1, chunk2) - * console.log(Chunk.toReadonlyArray(combined)) // [1, 2, 3, 4, 5, 6] - * ``` - * - * @example - * ```ts - * import { Chunk } from "effect" - * - * // Functional transformations - * const numbers = Chunk.range(1, 5) // [1, 2, 3, 4, 5] - * const doubled = Chunk.map(numbers, (n) => n * 2) // [2, 4, 6, 8, 10] - * const evens = Chunk.filter(doubled, (n) => n % 4 === 0) // [4, 8] - * const sum = Chunk.reduce(evens, 0, (acc, n) => acc + n) // 12 - * ``` - * - * @example - * ```ts - * import { Chunk, Effect } from "effect" - * - * // Working with Effects - * const processChunk = (chunk: Chunk.Chunk) => - * Effect.gen(function*() { - * const mapped = Chunk.map(chunk, (n) => n * 2) - * const filtered = Chunk.filter(mapped, (n) => n > 5) - * return Chunk.toReadonlyArray(filtered) - * }) - * ``` + * A `Chunk` is useful when you need to build or transform collections + * without changing the original collection. It is designed for efficient + * append, prepend, and concatenation. This module includes helpers for + * creating, reading, slicing, mapping, filtering, sorting, zipping, combining, + * and converting chunks to and from arrays and iterables. * * @since 2.0.0 */ @@ -94,7 +35,8 @@ const TypeId = "~effect/collections/Chunk" /** * A Chunk is an immutable, ordered collection optimized for efficient concatenation and access patterns. * - * @example + * **Example** (Inspecting chunk values) + * * ```ts * import { Chunk } from "effect" * @@ -120,7 +62,8 @@ export interface Chunk extends Iterable, Equal.Equal, Pipeable, Inspec /** * A non-empty Chunk guaranteed to contain at least one element. * - * @example + * **Example** (Working with non-empty chunks) + * * ```ts * import { Chunk } from "effect" * @@ -137,13 +80,13 @@ export interface NonEmptyChunk extends Chunk, NonEmptyIterable {} /** * Type lambda for Chunk, used for higher-kinded type operations. * - * @example + * **Example** (Applying the Chunk type lambda) + * * ```ts - * import type { ChunkTypeLambda } from "effect/Chunk" - * import type { Kind } from "effect/HKT" + * import type { Chunk, HKT } from "effect" * * // Create a Chunk type using the type lambda - * type NumberChunk = Kind + * type NumberChunk = HKT.Kind * // Equivalent to: Chunk * ``` * @@ -204,12 +147,13 @@ function copy( const emptyArray: ReadonlyArray = [] /** - * Compares the two chunks of equal length using the specified function + * Creates an `Equivalence` for chunks that compares chunk lengths and then + * compares corresponding elements with the provided element equivalence. + * + * **Example** (Comparing chunks for equivalence) * - * @example * ```ts - * import { Chunk } from "effect" - * import * as Equivalence from "effect/Equivalence" + * import { Chunk, Equivalence } from "effect" * * const chunk1 = Chunk.make(1, 2, 3) * const chunk2 = Chunk.make(1, 2, 3) @@ -220,8 +164,8 @@ const emptyArray: ReadonlyArray = [] * console.log(eq(chunk1, chunk3)) // false * ``` * - * @category equivalence - * @since 2.0.0 + * @category instances + * @since 4.0.0 */ export const makeEquivalence = (isEquivalent: Equivalence.Equivalence): Equivalence.Equivalence> => Equivalence.make((self, that) => @@ -314,9 +258,10 @@ const makeChunk = (backing: Backing): Chunk => { } /** - * Checks if `u` is a `Chunk` + * Checks whether `u` is a `Chunk` + * + * **Example** (Checking for chunks) * - * @example * ```ts * import { Chunk } from "effect" * @@ -333,9 +278,10 @@ const makeChunk = (backing: Backing): Chunk => { */ export const isChunk: { /** - * Checks if `u` is a `Chunk` + * Checks whether `u` is a `Chunk` + * + * **Example** (Checking for chunks) * - * @example * ```ts * import { Chunk } from "effect" * @@ -352,9 +298,10 @@ export const isChunk: { */ (u: Iterable): u is Chunk /** - * Checks if `u` is a `Chunk` + * Checks whether `u` is a `Chunk` + * + * **Example** (Checking for chunks) * - * @example * ```ts * import { Chunk } from "effect" * @@ -377,7 +324,8 @@ const _empty = makeChunk({ _tag: "IEmpty" }) /** * Creates an empty `Chunk`. * - * @example + * **Example** (Creating an empty chunk) + * * ```ts * import { Chunk } from "effect" * @@ -393,13 +341,13 @@ export const empty: () => Chunk = () => _empty /** * Builds a `NonEmptyChunk` from an non-empty collection of elements. * - * @example + * **Example** (Creating a non-empty chunk) + * * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4) - * console.log(chunk) - * // { _id: 'Chunk', values: [ 1, 2, 3, 4 ] } + * console.log(Chunk.toArray(chunk)) // [1, 2, 3, 4] * ``` * * @category constructors @@ -411,13 +359,13 @@ export const make = ]>(...as: As): NonEm /** * Builds a `NonEmptyChunk` from a single element. * - * @example + * **Example** (Creating a single-element chunk) + * * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.of("hello") - * console.log(chunk) - * // { _id: 'Chunk', values: [ "hello" ] } + * console.log(Chunk.toArray(chunk)) // ["hello"] * ``` * * @category constructors @@ -428,13 +376,13 @@ export const of = (a: A): NonEmptyChunk => makeChunk({ _tag: "ISingleton", /** * Creates a new `Chunk` from an iterable collection of values. * - * @example + * **Example** (Creating chunks from iterables) + * * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.fromIterable([1, 2, 3]) - * console.log(chunk) - * // { _id: 'Chunk', values: [ 1, 2, 3 ] } + * console.log(Chunk.toArray(chunk)) // [1, 2, 3] * ``` * * @category constructors @@ -478,7 +426,8 @@ const toArray_ = (self: Chunk): Array => toReadonlyArray(self).slice() * (`NonEmptyChunk`), the function will return a `NonEmptyArray`, ensuring the * non-empty property is preserved. * - * @example + * **Example** (Converting chunks to mutable arrays) + * * ```ts * import { Chunk } from "effect" * @@ -492,7 +441,7 @@ const toArray_ = (self: Chunk): Array => toReadonlyArray(self).slice() * console.log(Chunk.toArray(emptyChunk)) // [] * ``` * - * @category conversions + * @category converting * @since 2.0.0 */ export const toArray: >( @@ -527,7 +476,8 @@ const toReadonlyArray_ = (self: Chunk): ReadonlyArray => { * non-empty (`NonEmptyChunk`), the function will return a * `NonEmptyReadonlyArray`, ensuring the non-empty property is preserved. * - * @example + * **Example** (Converting chunks to readonly arrays) + * * ```ts * import { Chunk } from "effect" * @@ -543,7 +493,7 @@ const toReadonlyArray_ = (self: Chunk): ReadonlyArray => { * console.log(Chunk.toReadonlyArray(emptyChunk)) // [] * ``` * - * @category conversions + * @category converting * @since 2.0.0 */ export const toReadonlyArray: >( @@ -569,9 +519,17 @@ const reverseChunk = (self: Chunk): Chunk => { /** * Reverses the order of elements in a `Chunk`. - * Importantly, if the input chunk is a `NonEmptyChunk`, the reversed chunk will also be a `NonEmptyChunk`. * - * @example + * **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) * * ```ts * import { Chunk } from "effect" @@ -579,19 +537,20 @@ const reverseChunk = (self: Chunk): Chunk => { * const chunk = Chunk.make(1, 2, 3) * const result = Chunk.reverse(chunk) * - * console.log(result) - * // { _id: 'Chunk', values: [ 3, 2, 1 ] } + * console.log(Chunk.toArray(result)) // [3, 2, 1] * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ export const reverse: >(self: S) => Chunk.With> = reverseChunk as any /** - * This function provides a safe way to read a value at a particular index from a `Chunk`. + * Gets the value at an index in a `Chunk` safely, returning `None` when the index is + * out of bounds. + * + * **Example** (Accessing elements safely) * - * @example * ```ts * import { Chunk } from "effect" * @@ -611,9 +570,11 @@ export const reverse: >(self: S) => Chunk.With(self: Chunk) => Option /** - * This function provides a safe way to read a value at a particular index from a `Chunk`. + * Gets the value at an index in a `Chunk` safely, returning `None` when the index is + * out of bounds. + * + * **Example** (Accessing elements safely) * - * @example * ```ts * import { Chunk } from "effect" * @@ -661,9 +624,19 @@ export const get: { ) /** - * Wraps an array into a chunk without copying, unsafe on mutable arrays + * 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) * - * @example * ```ts * import { Chunk } from "effect" * @@ -676,19 +649,28 @@ export const get: { * console.log(Chunk.toArray(chunk)) // [999, 2, 3, 4, 5] * ``` * - * @since 2.0.0 * @category unsafe + * @since 4.0.0 */ export const fromArrayUnsafe = (self: ReadonlyArray): Chunk => self.length === 0 ? empty() : self.length === 1 ? of(self[0]) : makeChunk({ _tag: "IArray", array: self }) /** - * Wraps an array into a chunk without copying, unsafe on mutable arrays + * Wraps a non-empty array into a non-empty chunk without copying. + * + * **When to use** + * + * Use when the input array is already known to be non-empty, 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 non-empty chunks without copying arrays) * - * @example * ```ts - * import { Chunk } from "effect" - * import * as Array from "effect/Array" + * import { Array, Chunk } from "effect" * * const nonEmptyArray = Array.make(1, 2, 3, 4, 5) * const chunk = Chunk.fromNonEmptyArrayUnsafe(nonEmptyArray) @@ -698,82 +680,100 @@ export const fromArrayUnsafe = (self: ReadonlyArray): Chunk => * console.log(Chunk.isNonEmpty(chunk)) // true * ``` * - * @since 2.0.0 * @category unsafe + * @since 4.0.0 */ export const fromNonEmptyArrayUnsafe = (self: NonEmptyReadonlyArray): NonEmptyChunk => fromArrayUnsafe(self) as any /** - * Gets an element unsafely, will throw on out of bounds + * Gets an element at the specified index without returning an `Option`. + * + * **When to use** + * + * Use when reading from a `Chunk` at an index known to be in bounds and direct + * element access is preferred over handling `Option.none`. + * + * **Gotchas** + * + * Throws if the index is out of bounds. + * + * **Example** (Accessing elements unsafely) * - * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk, Option } from "effect" * * const chunk = Chunk.make("a", "b", "c", "d") * * console.log(Chunk.getUnsafe(chunk, 1)) // "b" * console.log(Chunk.getUnsafe(chunk, 3)) // "d" * - * // Warning: This will throw an error for invalid indices - * try { - * Chunk.getUnsafe(chunk, 10) // throws "Index out of bounds" - * } catch (error) { - * console.log((error as Error).message) // "Index out of bounds" - * } + * // Use Chunk.get when the index may be out of bounds + * console.log(Option.isNone(Chunk.get(chunk, 10))) // true * ``` * - * @since 2.0.0 * @category unsafe + * @since 4.0.0 */ export const getUnsafe: { /** - * Gets an element unsafely, will throw on out of bounds + * Gets an element at the specified index without returning an `Option`. + * + * **When to use** + * + * Use when reading from a `Chunk` at an index known to be in bounds and direct + * element access is preferred over handling `Option.none`. + * + * **Gotchas** + * + * Throws if the index is out of bounds. + * + * **Example** (Accessing elements unsafely) * - * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk, Option } from "effect" * * const chunk = Chunk.make("a", "b", "c", "d") * * console.log(Chunk.getUnsafe(chunk, 1)) // "b" * console.log(Chunk.getUnsafe(chunk, 3)) // "d" * - * // Warning: This will throw an error for invalid indices - * try { - * Chunk.getUnsafe(chunk, 10) // throws "Index out of bounds" - * } catch (error) { - * console.log((error as Error).message) // "Index out of bounds" - * } + * // Use Chunk.get when the index may be out of bounds + * console.log(Option.isNone(Chunk.get(chunk, 10))) // true * ``` * - * @since 2.0.0 * @category unsafe + * @since 4.0.0 */ (index: number): (self: Chunk) => A /** - * Gets an element unsafely, will throw on out of bounds + * Gets an element at the specified index without returning an `Option`. + * + * **When to use** + * + * Use when reading from a `Chunk` at an index known to be in bounds and direct + * element access is preferred over handling `Option.none`. + * + * **Gotchas** + * + * Throws if the index is out of bounds. + * + * **Example** (Accessing elements unsafely) * - * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk, Option } from "effect" * * const chunk = Chunk.make("a", "b", "c", "d") * * console.log(Chunk.getUnsafe(chunk, 1)) // "b" * console.log(Chunk.getUnsafe(chunk, 3)) // "d" * - * // Warning: This will throw an error for invalid indices - * try { - * Chunk.getUnsafe(chunk, 10) // throws "Index out of bounds" - * } catch (error) { - * console.log((error as Error).message) // "Index out of bounds" - * } + * // Use Chunk.get when the index may be out of bounds + * console.log(Option.isNone(Chunk.get(chunk, 10))) // true * ``` * - * @since 2.0.0 * @category unsafe + * @since 4.0.0 */ (self: Chunk, index: number): A } = dual(2, (self: Chunk, index: number): A => { @@ -808,7 +808,13 @@ export const getUnsafe: { /** * Appends the specified element to the end of the `Chunk`. * - * @example + * **When to use** + * + * Use to add one element after the existing chunk elements and return a + * `NonEmptyChunk`. + * + * **Example** (Appending an element) + * * ```ts * import { Chunk } from "effect" * @@ -822,14 +828,23 @@ export const getUnsafe: { * console.log(Chunk.toArray(singleElement)) // [42] * ``` * - * @category concatenating + * @see {@link prepend} for adding one element before the existing elements + * @see {@link appendAll} for appending all elements from another chunk + * + * @category combining * @since 2.0.0 */ export const append: { /** * Appends the specified element to the end of the `Chunk`. * - * @example + * **When to use** + * + * Use to add one element after the existing chunk elements and return a + * `NonEmptyChunk`. + * + * **Example** (Appending an element) + * * ```ts * import { Chunk } from "effect" * @@ -843,14 +858,23 @@ export const append: { * console.log(Chunk.toArray(singleElement)) // [42] * ``` * - * @category concatenating + * @see {@link prepend} for adding one element before the existing elements + * @see {@link appendAll} for appending all elements from another chunk + * + * @category combining * @since 2.0.0 */ (a: A2): (self: Chunk) => NonEmptyChunk /** * Appends the specified element to the end of the `Chunk`. * - * @example + * **When to use** + * + * Use to add one element after the existing chunk elements and return a + * `NonEmptyChunk`. + * + * **Example** (Appending an element) + * * ```ts * import { Chunk } from "effect" * @@ -864,16 +888,20 @@ export const append: { * console.log(Chunk.toArray(singleElement)) // [42] * ``` * - * @category concatenating + * @see {@link prepend} for adding one element before the existing elements + * @see {@link appendAll} for appending all elements from another chunk + * + * @category combining * @since 2.0.0 */ (self: Chunk, a: A2): NonEmptyChunk } = dual(2, (self: Chunk, a: A2): NonEmptyChunk => appendAll(self, of(a))) /** - * Prepend an element to the front of a `Chunk`, creating a new `NonEmptyChunk`. + * Prepends an element to the front of a `Chunk`, creating a new `NonEmptyChunk`. + * + * **Example** (Prepending an element) * - * @example * ```ts * import { Chunk } from "effect" * @@ -887,14 +915,15 @@ export const append: { * console.log(Chunk.toArray(singleElement)) // ["first"] * ``` * - * @category concatenating + * @category combining * @since 2.0.0 */ export const prepend: { /** - * Prepend an element to the front of a `Chunk`, creating a new `NonEmptyChunk`. + * Prepends an element to the front of a `Chunk`, creating a new `NonEmptyChunk`. + * + * **Example** (Prepending an element) * - * @example * ```ts * import { Chunk } from "effect" * @@ -908,14 +937,15 @@ export const prepend: { * console.log(Chunk.toArray(singleElement)) // ["first"] * ``` * - * @category concatenating + * @category combining * @since 2.0.0 */ (elem: B): (self: Chunk) => NonEmptyChunk /** - * Prepend an element to the front of a `Chunk`, creating a new `NonEmptyChunk`. + * Prepends an element to the front of a `Chunk`, creating a new `NonEmptyChunk`. + * + * **Example** (Prepending an element) * - * @example * ```ts * import { Chunk } from "effect" * @@ -929,7 +959,7 @@ export const prepend: { * console.log(Chunk.toArray(singleElement)) // ["first"] * ``` * - * @category concatenating + * @category combining * @since 2.0.0 */ (self: Chunk, elem: B): NonEmptyChunk @@ -938,14 +968,14 @@ export const prepend: { /** * Takes the first up to `n` elements from the chunk. * - * @example + * **Example** (Taking elements from the start) + * * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.take(chunk, 3) - * console.log(result) - * // { _id: 'Chunk', values: [ 1, 2, 3 ] } + * console.log(Chunk.toArray(result)) // [1, 2, 3] * ``` * * @category elements @@ -955,14 +985,14 @@ export const take: { /** * Takes the first up to `n` elements from the chunk. * - * @example + * **Example** (Taking elements from the start) + * * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.take(chunk, 3) - * console.log(result) - * // { _id: 'Chunk', values: [ 1, 2, 3 ] } + * console.log(Chunk.toArray(result)) // [1, 2, 3] * ``` * * @category elements @@ -972,14 +1002,14 @@ export const take: { /** * Takes the first up to `n` elements from the chunk. * - * @example + * **Example** (Taking elements from the start) + * * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.take(chunk, 3) - * console.log(result) - * // { _id: 'Chunk', values: [ 1, 2, 3 ] } + * console.log(Chunk.toArray(result)) // [1, 2, 3] * ``` * * @category elements @@ -1027,14 +1057,14 @@ export const take: { /** * Drops the first up to `n` elements from the chunk. * - * @example + * **Example** (Dropping elements from the start) + * * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.drop(chunk, 2) - * console.log(result) - * // { _id: 'Chunk', values: [ 3, 4, 5 ] } + * console.log(Chunk.toArray(result)) // [3, 4, 5] * ``` * * @category elements @@ -1044,14 +1074,14 @@ export const drop: { /** * Drops the first up to `n` elements from the chunk. * - * @example + * **Example** (Dropping elements from the start) + * * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.drop(chunk, 2) - * console.log(result) - * // { _id: 'Chunk', values: [ 3, 4, 5 ] } + * console.log(Chunk.toArray(result)) // [3, 4, 5] * ``` * * @category elements @@ -1061,14 +1091,14 @@ export const drop: { /** * Drops the first up to `n` elements from the chunk. * - * @example + * **Example** (Dropping elements from the start) + * * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.drop(chunk, 2) - * console.log(result) - * // { _id: 'Chunk', values: [ 3, 4, 5 ] } + * console.log(Chunk.toArray(result)) // [3, 4, 5] * ``` * * @category elements @@ -1115,14 +1145,14 @@ export const drop: { /** * Drops the last `n` elements. * - * @example + * **Example** (Dropping elements from the end) + * * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.dropRight(chunk, 2) - * console.log(result) - * // { _id: 'Chunk', values: [ 1, 2, 3 ] } + * console.log(Chunk.toArray(result)) // [1, 2, 3] * ``` * * @category elements @@ -1132,14 +1162,14 @@ export const dropRight: { /** * Drops the last `n` elements. * - * @example + * **Example** (Dropping elements from the end) + * * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.dropRight(chunk, 2) - * console.log(result) - * // { _id: 'Chunk', values: [ 1, 2, 3 ] } + * console.log(Chunk.toArray(result)) // [1, 2, 3] * ``` * * @category elements @@ -1149,14 +1179,14 @@ export const dropRight: { /** * Drops the last `n` elements. * - * @example + * **Example** (Dropping elements from the end) + * * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.dropRight(chunk, 2) - * console.log(result) - * // { _id: 'Chunk', values: [ 1, 2, 3 ] } + * console.log(Chunk.toArray(result)) // [1, 2, 3] * ``` * * @category elements @@ -1168,14 +1198,14 @@ export const dropRight: { /** * Drops all elements so long as the predicate returns true. * - * @example + * **Example** (Dropping elements while a predicate matches) + * * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.dropWhile(chunk, (n) => n < 3) - * console.log(result) - * // { _id: 'Chunk', values: [ 3, 4, 5 ] } + * console.log(Chunk.toArray(result)) // [3, 4, 5] * ``` * * @category elements @@ -1185,14 +1215,14 @@ export const dropWhile: { /** * Drops all elements so long as the predicate returns true. * - * @example + * **Example** (Dropping elements while a predicate matches) + * * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.dropWhile(chunk, (n) => n < 3) - * console.log(result) - * // { _id: 'Chunk', values: [ 3, 4, 5 ] } + * console.log(Chunk.toArray(result)) // [3, 4, 5] * ``` * * @category elements @@ -1202,14 +1232,14 @@ export const dropWhile: { /** * Drops all elements so long as the predicate returns true. * - * @example + * **Example** (Dropping elements while a predicate matches) + * * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.dropWhile(chunk, (n) => n < 3) - * console.log(result) - * // { _id: 'Chunk', values: [ 3, 4, 5 ] } + * console.log(Chunk.toArray(result)) // [3, 4, 5] * ``` * * @category elements @@ -1230,7 +1260,7 @@ export const dropWhile: { * Prepends the specified prefix chunk to the beginning of the specified chunk. * If either chunk is non-empty, the result is also a non-empty chunk. * - * @example + * **Example** (Prepending all elements) * * ```ts * import { Chunk } from "effect" @@ -1244,7 +1274,7 @@ export const dropWhile: { * // [ "a", "b", 1, 2 ] * ``` * - * @category concatenating + * @category combining * @since 2.0.0 */ export const prependAll: { @@ -1252,7 +1282,7 @@ export const prependAll: { * Prepends the specified prefix chunk to the beginning of the specified chunk. * If either chunk is non-empty, the result is also a non-empty chunk. * - * @example + * **Example** (Prepending all elements) * * ```ts * import { Chunk } from "effect" @@ -1266,7 +1296,7 @@ export const prependAll: { * // [ "a", "b", 1, 2 ] * ``` * - * @category concatenating + * @category combining * @since 2.0.0 */ , T extends Chunk>(that: T): (self: S) => Chunk.OrNonEmpty | Chunk.Infer> @@ -1274,7 +1304,7 @@ export const prependAll: { * Prepends the specified prefix chunk to the beginning of the specified chunk. * If either chunk is non-empty, the result is also a non-empty chunk. * - * @example + * **Example** (Prepending all elements) * * ```ts * import { Chunk } from "effect" @@ -1288,7 +1318,7 @@ export const prependAll: { * // [ "a", "b", 1, 2 ] * ``` * - * @category concatenating + * @category combining * @since 2.0.0 */ (self: Chunk, that: NonEmptyChunk): NonEmptyChunk @@ -1296,7 +1326,7 @@ export const prependAll: { * Prepends the specified prefix chunk to the beginning of the specified chunk. * If either chunk is non-empty, the result is also a non-empty chunk. * - * @example + * **Example** (Prepending all elements) * * ```ts * import { Chunk } from "effect" @@ -1310,7 +1340,7 @@ export const prependAll: { * // [ "a", "b", 1, 2 ] * ``` * - * @category concatenating + * @category combining * @since 2.0.0 */ (self: NonEmptyChunk, that: Chunk): NonEmptyChunk @@ -1318,7 +1348,7 @@ export const prependAll: { * Prepends the specified prefix chunk to the beginning of the specified chunk. * If either chunk is non-empty, the result is also a non-empty chunk. * - * @example + * **Example** (Prepending all elements) * * ```ts * import { Chunk } from "effect" @@ -1332,7 +1362,7 @@ export const prependAll: { * // [ "a", "b", 1, 2 ] * ``` * - * @category concatenating + * @category combining * @since 2.0.0 */ (self: Chunk, that: Chunk): Chunk @@ -1342,7 +1372,12 @@ export const prependAll: { * Concatenates two chunks, combining their elements. * If either chunk is non-empty, the result is also a non-empty chunk. * - * @example + * **When to use** + * + * Use to concatenate two chunks when the second chunk's elements should come + * after the first. + * + * **Example** (Appending all elements) * * ```ts * import { Chunk } from "effect" @@ -1356,7 +1391,10 @@ export const prependAll: { * // [ 1, 2, "a", "b" ] * ``` * - * @category concatenating + * @see {@link prependAll} for concatenating chunks in the opposite order + * @see {@link append} for adding a single element to the end + * + * @category combining * @since 2.0.0 */ export const appendAll: { @@ -1364,7 +1402,12 @@ export const appendAll: { * Concatenates two chunks, combining their elements. * If either chunk is non-empty, the result is also a non-empty chunk. * - * @example + * **When to use** + * + * Use to concatenate two chunks when the second chunk's elements should come + * after the first. + * + * **Example** (Appending all elements) * * ```ts * import { Chunk } from "effect" @@ -1378,7 +1421,10 @@ export const appendAll: { * // [ 1, 2, "a", "b" ] * ``` * - * @category concatenating + * @see {@link prependAll} for concatenating chunks in the opposite order + * @see {@link append} for adding a single element to the end + * + * @category combining * @since 2.0.0 */ , T extends Chunk>(that: T): (self: S) => Chunk.OrNonEmpty | Chunk.Infer> @@ -1386,7 +1432,12 @@ export const appendAll: { * Concatenates two chunks, combining their elements. * If either chunk is non-empty, the result is also a non-empty chunk. * - * @example + * **When to use** + * + * Use to concatenate two chunks when the second chunk's elements should come + * after the first. + * + * **Example** (Appending all elements) * * ```ts * import { Chunk } from "effect" @@ -1400,7 +1451,10 @@ export const appendAll: { * // [ 1, 2, "a", "b" ] * ``` * - * @category concatenating + * @see {@link prependAll} for concatenating chunks in the opposite order + * @see {@link append} for adding a single element to the end + * + * @category combining * @since 2.0.0 */ (self: Chunk, that: NonEmptyChunk): NonEmptyChunk @@ -1408,7 +1462,12 @@ export const appendAll: { * Concatenates two chunks, combining their elements. * If either chunk is non-empty, the result is also a non-empty chunk. * - * @example + * **When to use** + * + * Use to concatenate two chunks when the second chunk's elements should come + * after the first. + * + * **Example** (Appending all elements) * * ```ts * import { Chunk } from "effect" @@ -1422,7 +1481,10 @@ export const appendAll: { * // [ 1, 2, "a", "b" ] * ``` * - * @category concatenating + * @see {@link prependAll} for concatenating chunks in the opposite order + * @see {@link append} for adding a single element to the end + * + * @category combining * @since 2.0.0 */ (self: NonEmptyChunk, that: Chunk): NonEmptyChunk @@ -1430,7 +1492,12 @@ export const appendAll: { * Concatenates two chunks, combining their elements. * If either chunk is non-empty, the result is also a non-empty chunk. * - * @example + * **When to use** + * + * Use to concatenate two chunks when the second chunk's elements should come + * after the first. + * + * **Example** (Appending all elements) * * ```ts * import { Chunk } from "effect" @@ -1444,7 +1511,10 @@ export const appendAll: { * // [ 1, 2, "a", "b" ] * ``` * - * @category concatenating + * @see {@link prependAll} for concatenating chunks in the opposite order + * @see {@link append} for adding a single element to the end + * + * @category combining * @since 2.0.0 */ (self: Chunk, that: Chunk): Chunk @@ -1461,7 +1531,12 @@ export const appendAll: { * Concatenates two chunks, combining their elements. * If either chunk is non-empty, the result is also a non-empty chunk. * - * @example + * **When to use** + * + * Use to concatenate two chunks when the second chunk's elements should come + * after the first. + * + * **Example** (Appending all elements) * * ```ts * import { Chunk } from "effect" @@ -1475,7 +1550,10 @@ export const appendAll: { * // [ 1, 2, "a", "b" ] * ``` * - * @category concatenating + * @see {@link prependAll} for concatenating chunks in the opposite order + * @see {@link append} for adding a single element to the end + * + * @category combining * @since 2.0.0 */ A | B>({ _tag: "IConcat", left: self, right: that }); @@ -1513,10 +1591,10 @@ export const appendAll: { /** * Returns a filtered and mapped subset of the elements. * - * @example + * **Example** (Filtering and mapping values) + * * ```ts - * import { Chunk } from "effect" - * import * as Result from "effect/Result" + * import { Chunk, Result } from "effect" * * const chunk = Chunk.make("1", "2", "hello", "3", "world") * const numbers = Chunk.filterMap(chunk, (str) => { @@ -1533,17 +1611,17 @@ export const appendAll: { * console.log(Chunk.toArray(evenIndexNumbers)) // [1] * ``` * - * @since 2.0.0 * @category filtering + * @since 2.0.0 */ export const filterMap: { /** * Returns a filtered and mapped subset of the elements. * - * @example + * **Example** (Filtering and mapping values) + * * ```ts - * import { Chunk } from "effect" - * import * as Result from "effect/Result" + * import { Chunk, Result } from "effect" * * const chunk = Chunk.make("1", "2", "hello", "3", "world") * const numbers = Chunk.filterMap(chunk, (str) => { @@ -1560,17 +1638,17 @@ export const filterMap: { * console.log(Chunk.toArray(evenIndexNumbers)) // [1] * ``` * - * @since 2.0.0 * @category filtering + * @since 2.0.0 */ (f: (input: A, i: number) => Result): (self: Chunk) => Chunk /** * Returns a filtered and mapped subset of the elements. * - * @example + * **Example** (Filtering and mapping values) + * * ```ts - * import { Chunk } from "effect" - * import * as Result from "effect/Result" + * import { Chunk, Result } from "effect" * * const chunk = Chunk.make("1", "2", "hello", "3", "world") * const numbers = Chunk.filterMap(chunk, (str) => { @@ -1587,8 +1665,8 @@ export const filterMap: { * console.log(Chunk.toArray(evenIndexNumbers)) // [1] * ``` * - * @since 2.0.0 * @category filtering + * @since 2.0.0 */ (self: Chunk, f: (input: A, i: number) => Result): Chunk } = dual( @@ -1609,7 +1687,8 @@ export const filterMap: { /** * Returns a filtered subset of the elements. * - * @example + * **Example** (Filtering values) + * * ```ts * import { Chunk } from "effect" * @@ -1623,14 +1702,15 @@ export const filterMap: { * console.log(Chunk.toArray(numbers)) // [42, 100] * ``` * - * @since 2.0.0 * @category filtering + * @since 2.0.0 */ export const filter: { /** * Returns a filtered subset of the elements. * - * @example + * **Example** (Filtering values) + * * ```ts * import { Chunk } from "effect" * @@ -1644,14 +1724,15 @@ export const filter: { * console.log(Chunk.toArray(numbers)) // [42, 100] * ``` * - * @since 2.0.0 * @category filtering + * @since 2.0.0 */ (refinement: Refinement, B>): (self: Chunk) => Chunk /** * Returns a filtered subset of the elements. * - * @example + * **Example** (Filtering values) + * * ```ts * import { Chunk } from "effect" * @@ -1665,14 +1746,15 @@ export const filter: { * console.log(Chunk.toArray(numbers)) // [42, 100] * ``` * - * @since 2.0.0 * @category filtering + * @since 2.0.0 */ (predicate: Predicate>): (self: Chunk) => Chunk /** * Returns a filtered subset of the elements. * - * @example + * **Example** (Filtering values) + * * ```ts * import { Chunk } from "effect" * @@ -1686,14 +1768,15 @@ export const filter: { * console.log(Chunk.toArray(numbers)) // [42, 100] * ``` * - * @since 2.0.0 * @category filtering + * @since 2.0.0 */ (self: Chunk, refinement: Refinement): Chunk /** * Returns a filtered subset of the elements. * - * @example + * **Example** (Filtering values) + * * ```ts * import { Chunk } from "effect" * @@ -1707,8 +1790,8 @@ export const filter: { * console.log(Chunk.toArray(numbers)) // [42, 100] * ``` * - * @since 2.0.0 * @category filtering + * @since 2.0.0 */ (self: Chunk, predicate: Predicate): Chunk } = dual( @@ -1719,10 +1802,10 @@ export const filter: { /** * Transforms all elements of the chunk for as long as the specified function succeeds. * - * @example + * **Example** (Filtering and mapping while values match) + * * ```ts - * import { Chunk } from "effect" - * import * as Result from "effect/Result" + * import { Chunk, Result } from "effect" * * const chunk = Chunk.make("1", "2", "hello", "3", "4") * const result = Chunk.filterMapWhile(chunk, (s) => { @@ -1740,17 +1823,17 @@ export const filter: { * console.log(Chunk.toArray(allNumbers)) // [1, 2, 3, 4] * ``` * - * @since 2.0.0 * @category filtering + * @since 2.0.0 */ export const filterMapWhile: { /** * Transforms all elements of the chunk for as long as the specified function succeeds. * - * @example + * **Example** (Filtering and mapping while values match) + * * ```ts - * import { Chunk } from "effect" - * import * as Result from "effect/Result" + * import { Chunk, Result } from "effect" * * const chunk = Chunk.make("1", "2", "hello", "3", "4") * const result = Chunk.filterMapWhile(chunk, (s) => { @@ -1768,17 +1851,17 @@ export const filterMapWhile: { * console.log(Chunk.toArray(allNumbers)) // [1, 2, 3, 4] * ``` * - * @since 2.0.0 * @category filtering + * @since 2.0.0 */ (f: Filter.Filter): (self: Chunk) => Chunk /** * Transforms all elements of the chunk for as long as the specified function succeeds. * - * @example + * **Example** (Filtering and mapping while values match) + * * ```ts - * import { Chunk } from "effect" - * import * as Result from "effect/Result" + * import { Chunk, Result } from "effect" * * const chunk = Chunk.make("1", "2", "hello", "3", "4") * const result = Chunk.filterMapWhile(chunk, (s) => { @@ -1796,8 +1879,8 @@ export const filterMapWhile: { * console.log(Chunk.toArray(allNumbers)) // [1, 2, 3, 4] * ``` * - * @since 2.0.0 * @category filtering + * @since 2.0.0 */ (self: Chunk, f: Filter.Filter): Chunk } = dual(2, (self: Chunk, f: Filter.Filter): Chunk => { @@ -1814,17 +1897,16 @@ export const filterMapWhile: { }) /** - * Filter out optional values + * Filters out optional values + * + * **Example** (Compacting optional values) * - * @example * ```ts - * import { Chunk } from "effect" - * import * as Option from "effect/Option" + * import { Chunk, Option } from "effect" * * const chunk = Chunk.make(Option.some(1), Option.none(), Option.some(3)) * const result = Chunk.compact(chunk) - * console.log(result) - * // { _id: 'Chunk', values: [ 1, 3 ] } + * console.log(Chunk.toArray(result)) // [1, 3] * ``` * * @category filtering @@ -1843,7 +1925,8 @@ export const compact = (self: Chunk>): Chunk => { /** * Applies a function to each element in a chunk and returns a new chunk containing the concatenated mapped elements. * - * @example + * **Example** (Flat mapping chunks) + * * ```ts * import { Chunk } from "effect" * @@ -1864,14 +1947,15 @@ export const compact = (self: Chunk>): Chunk => { * console.log(Chunk.toArray(indexed)) // [1, 3, 5] * ``` * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ export const flatMap: { /** * Applies a function to each element in a chunk and returns a new chunk containing the concatenated mapped elements. * - * @example + * **Example** (Flat mapping chunks) + * * ```ts * import { Chunk } from "effect" * @@ -1892,14 +1976,15 @@ export const flatMap: { * console.log(Chunk.toArray(indexed)) // [1, 3, 5] * ``` * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ , T extends Chunk>(f: (a: Chunk.Infer, i: number) => T): (self: S) => Chunk.AndNonEmpty> /** * Applies a function to each element in a chunk and returns a new chunk containing the concatenated mapped elements. * - * @example + * **Example** (Flat mapping chunks) + * * ```ts * import { Chunk } from "effect" * @@ -1920,14 +2005,15 @@ export const flatMap: { * console.log(Chunk.toArray(indexed)) // [1, 3, 5] * ``` * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ (self: NonEmptyChunk, f: (a: A, i: number) => NonEmptyChunk): NonEmptyChunk /** * Applies a function to each element in a chunk and returns a new chunk containing the concatenated mapped elements. * - * @example + * **Example** (Flat mapping chunks) + * * ```ts * import { Chunk } from "effect" * @@ -1948,8 +2034,8 @@ export const flatMap: { * console.log(Chunk.toArray(indexed)) // [1, 3, 5] * ``` * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ (self: Chunk, f: (a: A, i: number) => Chunk): Chunk } = dual(2, (self: Chunk, f: (a: A, i: number) => Chunk) => { @@ -1974,7 +2060,8 @@ export const flatMap: { * instead, it is primarily used for side effects, such as logging or * accumulating data in an external variable. * - * @example + * **Example** (Iterating over chunk values) + * * ```ts * import { Chunk } from "effect" * @@ -1997,8 +2084,8 @@ export const flatMap: { * // Index 3: 4 * ``` * - * @since 2.0.0 * @category combinators + * @since 2.0.0 */ export const forEach: { /** @@ -2011,7 +2098,8 @@ export const forEach: { * instead, it is primarily used for side effects, such as logging or * accumulating data in an external variable. * - * @example + * **Example** (Iterating over chunk values) + * * ```ts * import { Chunk } from "effect" * @@ -2034,8 +2122,8 @@ export const forEach: { * // Index 3: 4 * ``` * - * @since 2.0.0 * @category combinators + * @since 2.0.0 */ (f: (a: A, index: number) => B): (self: Chunk) => void /** @@ -2048,7 +2136,8 @@ export const forEach: { * instead, it is primarily used for side effects, such as logging or * accumulating data in an external variable. * - * @example + * **Example** (Iterating over chunk values) + * * ```ts * import { Chunk } from "effect" * @@ -2071,8 +2160,8 @@ export const forEach: { * // Index 3: 4 * ``` * - * @since 2.0.0 * @category combinators + * @since 2.0.0 */ (self: Chunk, f: (a: A, index: number) => B): void } = dual(2, (self: Chunk, f: (a: A) => B): void => toReadonlyArray(self).forEach(f)) @@ -2080,7 +2169,8 @@ export const forEach: { /** * Flattens a chunk of chunks into a single chunk by concatenating all chunks. * - * @example + * **Example** (Flattening nested chunks) + * * ```ts * import { Chunk } from "effect" * @@ -2101,15 +2191,30 @@ export const forEach: { * console.log(Chunk.toArray(Chunk.flatten(withEmpty))) // [1, 2, 3, 4] * ``` * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ export const flatten: >>(self: S) => Chunk.Flatten = flatMap(identity) as any /** * Groups elements in chunks of up to `n` elements. * - * @example + * **When to use** + * + * Use to divide a chunk into ordered, non-overlapping chunks with at most `n` + * elements each. + * + * **Details** + * + * The final chunk may contain fewer than `n` elements. Empty input produces an + * empty chunk of chunks. + * + * **Gotchas** + * + * Values of `n` less than or equal to zero produce singleton chunks. + * + * **Example** (Splitting into fixed-size chunks) + * * ```ts * import { Chunk } from "effect" * @@ -2126,14 +2231,31 @@ export const flatten: >>(self: S) => Chunk.Flatten * // [[1, 2], [3, 4], [5]] * ``` * - * @since 2.0.0 + * @see {@link split} for splitting into a target number of chunks instead of a fixed chunk size + * * @category elements + * @since 2.0.0 */ export const chunksOf: { /** * Groups elements in chunks of up to `n` elements. * - * @example + * **When to use** + * + * Use to divide a chunk into ordered, non-overlapping chunks with at most `n` + * elements each. + * + * **Details** + * + * The final chunk may contain fewer than `n` elements. Empty input produces an + * empty chunk of chunks. + * + * **Gotchas** + * + * Values of `n` less than or equal to zero produce singleton chunks. + * + * **Example** (Splitting into fixed-size chunks) + * * ```ts * import { Chunk } from "effect" * @@ -2150,14 +2272,31 @@ export const chunksOf: { * // [[1, 2], [3, 4], [5]] * ``` * - * @since 2.0.0 + * @see {@link split} for splitting into a target number of chunks instead of a fixed chunk size + * * @category elements + * @since 2.0.0 */ (n: number): (self: Chunk) => Chunk> /** * Groups elements in chunks of up to `n` elements. * - * @example + * **When to use** + * + * Use to divide a chunk into ordered, non-overlapping chunks with at most `n` + * elements each. + * + * **Details** + * + * The final chunk may contain fewer than `n` elements. Empty input produces an + * empty chunk of chunks. + * + * **Gotchas** + * + * Values of `n` less than or equal to zero produce singleton chunks. + * + * **Example** (Splitting into fixed-size chunks) + * * ```ts * import { Chunk } from "effect" * @@ -2174,8 +2313,10 @@ export const chunksOf: { * // [[1, 2], [3, 4], [5]] * ``` * - * @since 2.0.0 + * @see {@link split} for splitting into a target number of chunks instead of a fixed chunk size + * * @category elements + * @since 2.0.0 */ (self: Chunk, n: number): Chunk> } = dual(2, (self: Chunk, n: number) => { @@ -2195,11 +2336,14 @@ export const chunksOf: { }) /** - * Creates a Chunk of unique values that are included in all given Chunks. + * Creates a `Chunk` of values that are included in both chunks. * - * The order and references of result values are determined by the Chunk. + * **Details** + * + * The order and references of result values are determined by the first chunk. + * + * **Example** (Intersecting chunks) * - * @example * ```ts * import { Chunk } from "effect" * @@ -2219,16 +2363,19 @@ export const chunksOf: { * console.log(Chunk.toArray(Chunk.intersection(chunk3, chunk4))) // [] * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ export const intersection: { /** - * Creates a Chunk of unique values that are included in all given Chunks. + * Creates a `Chunk` of values that are included in both chunks. * - * The order and references of result values are determined by the Chunk. + * **Details** + * + * The order and references of result values are determined by the first chunk. + * + * **Example** (Intersecting chunks) * - * @example * ```ts * import { Chunk } from "effect" * @@ -2248,16 +2395,19 @@ export const intersection: { * console.log(Chunk.toArray(Chunk.intersection(chunk3, chunk4))) // [] * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ (that: Chunk): (self: Chunk) => Chunk /** - * Creates a Chunk of unique values that are included in all given Chunks. + * Creates a `Chunk` of values that are included in both chunks. + * + * **Details** * - * The order and references of result values are determined by the Chunk. + * The order and references of result values are determined by the first chunk. + * + * **Example** (Intersecting chunks) * - * @example * ```ts * import { Chunk } from "effect" * @@ -2277,8 +2427,8 @@ export const intersection: { * console.log(Chunk.toArray(Chunk.intersection(chunk3, chunk4))) // [] * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ (self: Chunk, that: Chunk): Chunk } = dual( @@ -2290,7 +2440,8 @@ export const intersection: { /** * Determines if the chunk is empty. * - * @example + * **Example** (Checking for empty chunks) + * * ```ts * import { Chunk } from "effect" * @@ -2306,7 +2457,8 @@ export const isEmpty = (self: Chunk): boolean => self.length === 0 /** * Determines if the chunk is not empty. * - * @example + * **Example** (Checking for non-empty chunks) + * * ```ts * import { Chunk } from "effect" * @@ -2320,9 +2472,10 @@ export const isEmpty = (self: Chunk): boolean => self.length === 0 export const isNonEmpty = (self: Chunk): self is NonEmptyChunk => self.length > 0 /** - * Returns the first element of this chunk if it exists. + * Returns the first element of this chunk safely if it exists. + * + * **Example** (Getting the first element) * - * @example * ```ts * import { Chunk } from "effect" * @@ -2338,11 +2491,19 @@ export const head: (self: Chunk) => Option = get(0) /** * Returns the first element of this chunk. * - * It will throw an error if the chunk is empty. + * **When to use** + * + * Use when you know the chunk is non-empty and need the first element directly + * without handling `Option.none`. + * + * **Gotchas** + * + * Throws an error if the chunk is empty. + * + * **Example** (Getting the first element unsafely) * - * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk, Option } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4) * console.log(Chunk.headUnsafe(chunk)) // 1 @@ -2350,23 +2511,20 @@ export const head: (self: Chunk) => Option = get(0) * const singleElement = Chunk.make("hello") * console.log(Chunk.headUnsafe(singleElement)) // "hello" * - * // Warning: This will throw for empty chunks - * try { - * Chunk.headUnsafe(Chunk.empty()) - * } catch (error) { - * console.log((error as Error).message) // "Index out of bounds" - * } + * // Use Chunk.head when the chunk may be empty + * console.log(Option.isNone(Chunk.head(Chunk.empty()))) // true * ``` * - * @since 2.0.0 * @category unsafe + * @since 4.0.0 */ export const headUnsafe = (self: Chunk): A => getUnsafe(self, 0) /** * Returns the first element of this non empty chunk. * - * @example + * **Example** (Getting the first element of a non-empty chunk) + * * ```ts * import { Chunk } from "effect" * @@ -2380,15 +2538,16 @@ export const headUnsafe = (self: Chunk): A => getUnsafe(self, 0) * // Chunk.headNonEmpty(Chunk.empty()) // TypeScript error * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ export const headNonEmpty: (self: NonEmptyChunk) => A = headUnsafe /** - * Returns the last element of this chunk if it exists. + * Returns the last element of this chunk safely if it exists. + * + * **Example** (Getting the last element) * - * @example * ```ts * import { Chunk } from "effect" * @@ -2404,11 +2563,19 @@ export const last = (self: Chunk): Option => get(self, self.length - 1) /** * Returns the last element of this chunk. * - * It will throw an error if the chunk is empty. + * **When to use** + * + * Use when you know the chunk is non-empty and need the last element directly + * without handling `Option.none`. + * + * **Gotchas** + * + * Throws an error if the chunk is empty. + * + * **Example** (Getting the last element unsafely) * - * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk, Option } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4) * console.log(Chunk.lastUnsafe(chunk)) // 4 @@ -2416,23 +2583,20 @@ export const last = (self: Chunk): Option => get(self, self.length - 1) * const singleElement = Chunk.make("hello") * console.log(Chunk.lastUnsafe(singleElement)) // "hello" * - * // Warning: This will throw for empty chunks - * try { - * Chunk.lastUnsafe(Chunk.empty()) - * } catch (error) { - * console.log((error as Error).message) // "Index out of bounds" - * } + * // Use Chunk.last when the chunk may be empty + * console.log(Option.isNone(Chunk.last(Chunk.empty()))) // true * ``` * - * @since 2.0.0 * @category unsafe + * @since 4.0.0 */ export const lastUnsafe = (self: Chunk): A => getUnsafe(self, self.length - 1) /** * Returns the last element of this non empty chunk. * - * @example + * **Example** (Getting the last element of a non-empty chunk) + * * ```ts * import { Chunk } from "effect" * @@ -2446,15 +2610,16 @@ export const lastUnsafe = (self: Chunk): A => getUnsafe(self, self.length * // Chunk.lastNonEmpty(Chunk.empty()) // TypeScript error * ``` * - * @since 3.4.0 * @category elements + * @since 3.4.0 */ export const lastNonEmpty: (self: NonEmptyChunk) => A = lastUnsafe /** * A namespace containing utility types for Chunk operations. * - * @example + * **Example** (Working with Chunk utility types) + * * ```ts * import type { Chunk } from "effect" * @@ -2467,14 +2632,14 @@ export const lastNonEmpty: (self: NonEmptyChunk) => A = lastUnsafe * type WithString = Chunk.Chunk.With // Chunk.NonEmptyChunk * ``` * - * @category types * @since 2.0.0 */ export declare namespace Chunk { /** * Infers the element type of a Chunk. * - * @example + * **Example** (Inferring element types) + * * ```ts * import type { Chunk } from "effect" * @@ -2493,7 +2658,8 @@ export declare namespace Chunk { /** * Constructs a Chunk type preserving non-emptiness. * - * @example + * **Example** (Preserving non-emptiness) + * * ```ts * import type { Chunk } from "effect" * @@ -2512,7 +2678,8 @@ export declare namespace Chunk { /** * Creates a non-empty Chunk if either input is non-empty. * - * @example + * **Example** (Preserving non-emptiness from either input) + * * ```ts * import type { Chunk } from "effect" * @@ -2547,7 +2714,8 @@ export declare namespace Chunk { /** * Creates a non-empty Chunk only if both inputs are non-empty. * - * @example + * **Example** (Requiring non-emptiness from both inputs) + * * ```ts * import type { Chunk } from "effect" * @@ -2582,7 +2750,8 @@ export declare namespace Chunk { /** * Flattens a nested Chunk type. * - * @example + * **Example** (Flattening nested chunk types) + * * ```ts * import type { Chunk } from "effect" * @@ -2605,76 +2774,72 @@ export declare namespace Chunk { * Transforms the elements of a chunk using the specified mapping function. * If the input chunk is non-empty, the resulting chunk will also be non-empty. * - * @example + * **Example** (Mapping values) * * ```ts * import { Chunk } from "effect" * * const result = Chunk.map(Chunk.make(1, 2), (n) => n + 1) * - * console.log(result) - * // { _id: 'Chunk', values: [ 2, 3 ] } + * console.log(Chunk.toArray(result)) // [2, 3] * ``` * - * @since 2.0.0 * @category mapping + * @since 2.0.0 */ export const map: { /** * Transforms the elements of a chunk using the specified mapping function. * If the input chunk is non-empty, the resulting chunk will also be non-empty. * - * @example + * **Example** (Mapping values) * * ```ts * import { Chunk } from "effect" * * const result = Chunk.map(Chunk.make(1, 2), (n) => n + 1) * - * console.log(result) - * // { _id: 'Chunk', values: [ 2, 3 ] } + * console.log(Chunk.toArray(result)) // [2, 3] * ``` * - * @since 2.0.0 * @category mapping + * @since 2.0.0 */ , B>(f: (a: Chunk.Infer, i: number) => B): (self: S) => Chunk.With /** * Transforms the elements of a chunk using the specified mapping function. * If the input chunk is non-empty, the resulting chunk will also be non-empty. * - * @example + * **Example** (Mapping values) * * ```ts * import { Chunk } from "effect" * * const result = Chunk.map(Chunk.make(1, 2), (n) => n + 1) * - * console.log(result) - * // { _id: 'Chunk', values: [ 2, 3 ] } + * console.log(Chunk.toArray(result)) // [2, 3] * ``` * - * @since 2.0.0 * @category mapping + * @since 2.0.0 */ (self: NonEmptyChunk, f: (a: A, i: number) => B): NonEmptyChunk /** * Transforms the elements of a chunk using the specified mapping function. * If the input chunk is non-empty, the resulting chunk will also be non-empty. * - * @example + * **Example** (Mapping values) * * ```ts * import { Chunk } from "effect" * * const result = Chunk.map(Chunk.make(1, 2), (n) => n + 1) * - * console.log(result) - * // { _id: 'Chunk', values: [ 2, 3 ] } + * console.log(Chunk.toArray(result)) // [2, 3] * ``` * - * @since 2.0.0 * @category mapping + * @since 2.0.0 */ (self: Chunk, f: (a: A, i: number) => B): Chunk } = dual(2, (self: Chunk, f: (a: A, i: number) => B): Chunk => @@ -2683,9 +2848,10 @@ export const map: { fromArrayUnsafe(pipe(toReadonlyArray(self), RA.map((a, i) => f(a, i))))) /** - * Statefully maps over the chunk, producing new elements of type `B`. + * Maps over the chunk statefully, producing new elements of type `B`. + * + * **Example** (Mapping with accumulated state) * - * @example * ```ts * import { Chunk } from "effect" * @@ -2708,14 +2874,15 @@ export const map: { * console.log(Chunk.toArray(indexed)) // ["0: hello", "1: world", "2: effect"] * ``` * - * @since 2.0.0 * @category folding + * @since 2.0.0 */ export const mapAccum: { /** - * Statefully maps over the chunk, producing new elements of type `B`. + * Maps over the chunk statefully, producing new elements of type `B`. + * + * **Example** (Mapping with accumulated state) * - * @example * ```ts * import { Chunk } from "effect" * @@ -2738,14 +2905,15 @@ export const mapAccum: { * console.log(Chunk.toArray(indexed)) // ["0: hello", "1: world", "2: effect"] * ``` * - * @since 2.0.0 * @category folding + * @since 2.0.0 */ (s: S, f: (s: S, a: A) => readonly [S, B]): (self: Chunk) => [S, Chunk] /** - * Statefully maps over the chunk, producing new elements of type `B`. + * Maps over the chunk statefully, producing new elements of type `B`. + * + * **Example** (Mapping with accumulated state) * - * @example * ```ts * import { Chunk } from "effect" * @@ -2768,8 +2936,8 @@ export const mapAccum: { * console.log(Chunk.toArray(indexed)) // ["0: hello", "1: world", "2: effect"] * ``` * - * @since 2.0.0 * @category folding + * @since 2.0.0 */ (self: Chunk, s: S, f: (s: S, a: A) => readonly [S, B]): [S, Chunk] } = dual(3, (self: Chunk, s: S, f: (s: S, a: A) => readonly [S, B]): [S, Chunk] => { @@ -2780,10 +2948,12 @@ export const mapAccum: { /** * Splits a chunk using a `Filter` into failures and successes. * - * - Returns `[excluded, satisfying]`. - * - The filter receives `(element, index)`. + * **Details** + * + * Returns `[excluded, satisfying]`. The filter receives `(element, index)`. + * + * **Example** (Partitioning with a Result) * - * @example * ```ts * import { Chunk, Result } from "effect" * @@ -2802,10 +2972,12 @@ export const partition: { /** * Splits a chunk using a `Filter` into failures and successes. * - * - Returns `[excluded, satisfying]`. - * - The filter receives `(element, index)`. + * **Details** + * + * Returns `[excluded, satisfying]`. The filter receives `(element, index)`. + * + * **Example** (Partitioning with a Result) * - * @example * ```ts * import { Chunk, Result } from "effect" * @@ -2824,10 +2996,12 @@ export const partition: { /** * Splits a chunk using a `Filter` into failures and successes. * - * - Returns `[excluded, satisfying]`. - * - The filter receives `(element, index)`. + * **Details** + * + * Returns `[excluded, satisfying]`. The filter receives `(element, index)`. + * + * **Example** (Partitioning with a Result) * - * @example * ```ts * import { Chunk, Result } from "effect" * @@ -2855,12 +3029,18 @@ export const partition: { ) /** - * Partitions the elements of this chunk into two chunks. + * Separates a chunk of `Result` values into a chunk of failures and a chunk of + * successes. + * + * **Details** + * + * The returned tuple is `[failures, successes]`, preserving the original order + * within each side. + * + * **Example** (Separating failures and successes) * - * @example * ```ts - * import { Chunk } from "effect" - * import * as Result from "effect/Result" + * import { Chunk, Result } from "effect" * * const chunk = Chunk.make( * Result.succeed(1), @@ -2893,7 +3073,8 @@ export const separate = (self: Chunk>): [Chunk, Chunk] /** * Retrieves the size of the chunk. * - * @example + * **Example** (Getting chunk size) + * * ```ts * import { Chunk } from "effect" * @@ -2907,12 +3088,12 @@ export const separate = (self: Chunk>): [Chunk, Chunk] export const size = (self: Chunk): number => self.length /** - * Sort the elements of a Chunk in increasing order, creating a new Chunk. + * Sorts the elements of a `Chunk` in increasing order, creating a new `Chunk`. + * + * **Example** (Sorting chunks) * - * @example * ```ts - * import { Chunk } from "effect" - * import * as Order from "effect/Order" + * import { Chunk, Order } from "effect" * * const numbers = Chunk.make(3, 1, 4, 1, 5, 9, 2, 6) * const sorted = Chunk.sort(numbers, Order.Number) @@ -2928,17 +3109,17 @@ export const size = (self: Chunk): number => self.length * console.log(Chunk.toArray(sortedWords)) // ["apple", "banana", "cherry"] * ``` * - * @since 2.0.0 * @category sorting + * @since 2.0.0 */ export const sort: { /** - * Sort the elements of a Chunk in increasing order, creating a new Chunk. + * Sorts the elements of a `Chunk` in increasing order, creating a new `Chunk`. + * + * **Example** (Sorting chunks) * - * @example * ```ts - * import { Chunk } from "effect" - * import * as Order from "effect/Order" + * import { Chunk, Order } from "effect" * * const numbers = Chunk.make(3, 1, 4, 1, 5, 9, 2, 6) * const sorted = Chunk.sort(numbers, Order.Number) @@ -2954,17 +3135,17 @@ export const sort: { * console.log(Chunk.toArray(sortedWords)) // ["apple", "banana", "cherry"] * ``` * - * @since 2.0.0 * @category sorting + * @since 2.0.0 */ (O: Order.Order): (self: Chunk) => Chunk /** - * Sort the elements of a Chunk in increasing order, creating a new Chunk. + * Sorts the elements of a `Chunk` in increasing order, creating a new `Chunk`. + * + * **Example** (Sorting chunks) * - * @example * ```ts - * import { Chunk } from "effect" - * import * as Order from "effect/Order" + * import { Chunk, Order } from "effect" * * const numbers = Chunk.make(3, 1, 4, 1, 5, 9, 2, 6) * const sorted = Chunk.sort(numbers, Order.Number) @@ -2980,8 +3161,8 @@ export const sort: { * console.log(Chunk.toArray(sortedWords)) // ["apple", "banana", "cherry"] * ``` * - * @since 2.0.0 * @category sorting + * @since 2.0.0 */ (self: Chunk, O: Order.Order): Chunk } = dual( @@ -2990,12 +3171,12 @@ export const sort: { ) /** - * Sorts the elements of a Chunk based on a projection function. + * Sorts the elements of a `Chunk` based on a projection function. + * + * **Example** (Sorting chunks by a derived value) * - * @example * ```ts - * import { Chunk } from "effect" - * import * as Order from "effect/Order" + * import { Chunk, Order } from "effect" * * const people = Chunk.make( * { name: "Alice", age: 30 }, @@ -3019,17 +3200,17 @@ export const sort: { * console.log(Chunk.toArray(byLength)) // ["a", "ab", "abc"] * ``` * - * @since 2.0.0 * @category sorting + * @since 2.0.0 */ export const sortWith: { /** - * Sorts the elements of a Chunk based on a projection function. + * Sorts the elements of a `Chunk` based on a projection function. + * + * **Example** (Sorting chunks by a derived value) * - * @example * ```ts - * import { Chunk } from "effect" - * import * as Order from "effect/Order" + * import { Chunk, Order } from "effect" * * const people = Chunk.make( * { name: "Alice", age: 30 }, @@ -3053,17 +3234,17 @@ export const sortWith: { * console.log(Chunk.toArray(byLength)) // ["a", "ab", "abc"] * ``` * - * @since 2.0.0 * @category sorting + * @since 2.0.0 */ (f: (a: A) => B, order: Order.Order): (self: Chunk) => Chunk /** - * Sorts the elements of a Chunk based on a projection function. + * Sorts the elements of a `Chunk` based on a projection function. + * + * **Example** (Sorting chunks by a derived value) * - * @example * ```ts - * import { Chunk } from "effect" - * import * as Order from "effect/Order" + * import { Chunk, Order } from "effect" * * const people = Chunk.make( * { name: "Alice", age: 30 }, @@ -3087,8 +3268,8 @@ export const sortWith: { * console.log(Chunk.toArray(byLength)) // ["a", "ab", "abc"] * ``` * - * @since 2.0.0 * @category sorting + * @since 2.0.0 */ (self: Chunk, f: (a: A) => B, order: Order.Order): Chunk } = dual( @@ -3099,7 +3280,8 @@ export const sortWith: { /** * Returns two splits of this chunk at the specified index. * - * @example + * **Example** (Splitting at an index) + * * ```ts * import { Chunk } from "effect" * @@ -3119,14 +3301,15 @@ export const sortWith: { * console.log(Chunk.toArray(empty2)) // [] * ``` * - * @since 2.0.0 * @category splitting + * @since 2.0.0 */ export const splitAt: { /** * Returns two splits of this chunk at the specified index. * - * @example + * **Example** (Splitting at an index) + * * ```ts * import { Chunk } from "effect" * @@ -3146,14 +3329,15 @@ export const splitAt: { * console.log(Chunk.toArray(empty2)) // [] * ``` * - * @since 2.0.0 * @category splitting + * @since 2.0.0 */ (n: number): (self: Chunk) => [beforeIndex: Chunk, fromIndex: Chunk] /** * Returns two splits of this chunk at the specified index. * - * @example + * **Example** (Splitting at an index) + * * ```ts * import { Chunk } from "effect" * @@ -3173,17 +3357,24 @@ export const splitAt: { * console.log(Chunk.toArray(empty2)) // [] * ``` * - * @since 2.0.0 * @category splitting + * @since 2.0.0 */ (self: Chunk, n: number): [beforeIndex: Chunk, fromIndex: Chunk] } = dual(2, (self: Chunk, n: number): [Chunk, Chunk] => [take(self, n), drop(self, n)]) /** - * Splits a `NonEmptyChunk` into two segments, with the first segment containing a maximum of `n` elements. - * The value of `n` must be `>= 1`. + * Splits a `NonEmptyChunk` at `n`, returning a non-empty prefix and the + * remaining suffix. + * + * **Details** + * + * `n` is floored and normalized to at least `1`. If `n` is greater than or + * equal to the chunk length, the first result is the original chunk and the + * second result is empty. + * + * **Example** (Splitting non-empty chunks at an index) * - * @example * ```ts * import { Chunk } from "effect" * @@ -3206,10 +3397,17 @@ export const splitAt: { */ export const splitNonEmptyAt: { /** - * Splits a `NonEmptyChunk` into two segments, with the first segment containing a maximum of `n` elements. - * The value of `n` must be `>= 1`. + * Splits a `NonEmptyChunk` at `n`, returning a non-empty prefix and the + * remaining suffix. + * + * **Details** + * + * `n` is floored and normalized to at least `1`. If `n` is greater than or + * equal to the chunk length, the first result is the original chunk and the + * second result is empty. + * + * **Example** (Splitting non-empty chunks at an index) * - * @example * ```ts * import { Chunk } from "effect" * @@ -3232,10 +3430,17 @@ export const splitNonEmptyAt: { */ (n: number): (self: NonEmptyChunk) => [beforeIndex: NonEmptyChunk, fromIndex: Chunk] /** - * Splits a `NonEmptyChunk` into two segments, with the first segment containing a maximum of `n` elements. - * The value of `n` must be `>= 1`. + * Splits a `NonEmptyChunk` at `n`, returning a non-empty prefix and the + * remaining suffix. + * + * **Details** + * + * `n` is floored and normalized to at least `1`. If `n` is greater than or + * equal to the chunk length, the first result is the original chunk and the + * second result is empty. + * + * **Example** (Splitting non-empty chunks at an index) * - * @example * ```ts * import { Chunk } from "effect" * @@ -3265,9 +3470,15 @@ export const splitNonEmptyAt: { }) /** - * Splits this chunk into `n` equally sized chunks. + * Splits a chunk into up to `n` chunks, distributing elements in order. + * + * **Details** + * + * The chunk size is derived from the input length and `n`; the final chunk may + * contain fewer elements than the others. + * + * **Example** (Splitting chunks into groups) * - * @example * ```ts * import { Chunk } from "effect" * @@ -3288,14 +3499,20 @@ export const splitNonEmptyAt: { * // [[1, 2, 3, 4, 5, 6, 7, 8, 9]] * ``` * - * @since 2.0.0 * @category splitting + * @since 2.0.0 */ export const split: { /** - * Splits this chunk into `n` equally sized chunks. + * Splits a chunk into up to `n` chunks, distributing elements in order. + * + * **Details** + * + * The chunk size is derived from the input length and `n`; the final chunk may + * contain fewer elements than the others. + * + * **Example** (Splitting chunks into groups) * - * @example * ```ts * import { Chunk } from "effect" * @@ -3316,14 +3533,20 @@ export const split: { * // [[1, 2, 3, 4, 5, 6, 7, 8, 9]] * ``` * - * @since 2.0.0 * @category splitting + * @since 2.0.0 */ (n: number): (self: Chunk) => Chunk> /** - * Splits this chunk into `n` equally sized chunks. + * Splits a chunk into up to `n` chunks, distributing elements in order. + * + * **Details** + * + * The chunk size is derived from the input length and `n`; the final chunk may + * contain fewer elements than the others. + * + * **Example** (Splitting chunks into groups) * - * @example * ```ts * import { Chunk } from "effect" * @@ -3344,8 +3567,8 @@ export const split: { * // [[1, 2, 3, 4, 5, 6, 7, 8, 9]] * ``` * - * @since 2.0.0 * @category splitting + * @since 2.0.0 */ (self: Chunk, n: number): Chunk> } = dual(2, (self: Chunk, n: number) => chunksOf(self, Math.ceil(self.length / Math.floor(n)))) @@ -3354,7 +3577,8 @@ export const split: { * Splits this chunk on the first element that matches this predicate. * Returns a tuple containing two chunks: the first one is before the match, and the second one is from the match onward. * - * @example + * **Example** (Splitting at a matching element) + * * ```ts * import { Chunk } from "effect" * @@ -3382,7 +3606,8 @@ export const splitWhere: { * Splits this chunk on the first element that matches this predicate. * Returns a tuple containing two chunks: the first one is before the match, and the second one is from the match onward. * - * @example + * **Example** (Splitting at a matching element) + * * ```ts * import { Chunk } from "effect" * @@ -3410,7 +3635,8 @@ export const splitWhere: { * Splits this chunk on the first element that matches this predicate. * Returns a tuple containing two chunks: the first one is before the match, and the second one is from the match onward. * - * @example + * **Example** (Splitting at a matching element) + * * ```ts * import { Chunk } from "effect" * @@ -3447,9 +3673,10 @@ export const splitWhere: { }) /** - * Returns every elements after the first. + * Returns every element after the first safely, or `None` when the chunk is empty. + * + * **Example** (Getting the tail safely) * - * @example * ```ts * import { Chunk } from "effect" * @@ -3463,15 +3690,16 @@ export const splitWhere: { * console.log(Chunk.tail(empty)) // Option.none() * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ export const tail = (self: Chunk): O.Option> => self.length > 0 ? O.some(drop(self, 1)) : O.none() /** - * Returns every elements after the first. + * Returns every element after the first from a non-empty chunk. + * + * **Example** (Getting the tail of a non-empty chunk) * - * @example * ```ts * import { Chunk } from "effect" * @@ -3487,15 +3715,16 @@ export const tail = (self: Chunk): O.Option> => self.length > 0 ? * // Chunk.tailNonEmpty(Chunk.empty()) // TypeScript error * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ export const tailNonEmpty = (self: NonEmptyChunk): Chunk => drop(self, 1) /** * Takes the last `n` elements. * - * @example + * **Example** (Taking elements from the end) + * * ```ts * import { Chunk } from "effect" * @@ -3512,14 +3741,15 @@ export const tailNonEmpty = (self: NonEmptyChunk): Chunk => drop(self, * console.log(Chunk.toArray(none)) // [] * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ export const takeRight: { /** * Takes the last `n` elements. * - * @example + * **Example** (Taking elements from the end) + * * ```ts * import { Chunk } from "effect" * @@ -3536,14 +3766,15 @@ export const takeRight: { * console.log(Chunk.toArray(none)) // [] * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ (n: number): (self: Chunk) => Chunk /** * Takes the last `n` elements. * - * @example + * **Example** (Taking elements from the end) + * * ```ts * import { Chunk } from "effect" * @@ -3560,8 +3791,8 @@ export const takeRight: { * console.log(Chunk.toArray(none)) // [] * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ (self: Chunk, n: number): Chunk } = dual(2, (self: Chunk, n: number): Chunk => drop(self, self.length - n)) @@ -3569,7 +3800,8 @@ export const takeRight: { /** * Takes all elements so long as the predicate returns true. * - * @example + * **Example** (Taking elements while a predicate matches) + * * ```ts * import { Chunk } from "effect" * @@ -3587,14 +3819,15 @@ export const takeRight: { * console.log(Chunk.toArray(all)) // [1, 2, 3] * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ export const takeWhile: { /** * Takes all elements so long as the predicate returns true. * - * @example + * **Example** (Taking elements while a predicate matches) + * * ```ts * import { Chunk } from "effect" * @@ -3612,14 +3845,15 @@ export const takeWhile: { * console.log(Chunk.toArray(all)) // [1, 2, 3] * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ (refinement: Refinement, B>): (self: Chunk) => Chunk /** * Takes all elements so long as the predicate returns true. * - * @example + * **Example** (Taking elements while a predicate matches) + * * ```ts * import { Chunk } from "effect" * @@ -3637,14 +3871,15 @@ export const takeWhile: { * console.log(Chunk.toArray(all)) // [1, 2, 3] * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ (predicate: Predicate>): (self: Chunk) => Chunk /** * Takes all elements so long as the predicate returns true. * - * @example + * **Example** (Taking elements while a predicate matches) + * * ```ts * import { Chunk } from "effect" * @@ -3662,14 +3897,15 @@ export const takeWhile: { * console.log(Chunk.toArray(all)) // [1, 2, 3] * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ (self: Chunk, refinement: Refinement): Chunk /** * Takes all elements so long as the predicate returns true. * - * @example + * **Example** (Taking elements while a predicate matches) + * * ```ts * import { Chunk } from "effect" * @@ -3687,8 +3923,8 @@ export const takeWhile: { * console.log(Chunk.toArray(all)) // [1, 2, 3] * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ (self: Chunk, predicate: Predicate): Chunk } = dual(2, (self: Chunk, predicate: Predicate): Chunk => { @@ -3706,7 +3942,8 @@ export const takeWhile: { /** * Creates a Chunks of unique values, in order, from all given Chunks. * - * @example + * **Example** (Unioning chunks) + * * ```ts * import { Chunk } from "effect" * @@ -3722,14 +3959,15 @@ export const takeWhile: { * console.log(Chunk.toArray(unified)) // [1, 2, 3] * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ export const union: { /** * Creates a Chunks of unique values, in order, from all given Chunks. * - * @example + * **Example** (Unioning chunks) + * * ```ts * import { Chunk } from "effect" * @@ -3745,14 +3983,15 @@ export const union: { * console.log(Chunk.toArray(unified)) // [1, 2, 3] * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ (that: Chunk): (self: Chunk) => Chunk /** * Creates a Chunks of unique values, in order, from all given Chunks. * - * @example + * **Example** (Unioning chunks) + * * ```ts * import { Chunk } from "effect" * @@ -3768,8 +4007,8 @@ export const union: { * console.log(Chunk.toArray(unified)) // [1, 2, 3] * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ (self: Chunk, that: Chunk): Chunk } = dual( @@ -3778,9 +4017,11 @@ export const union: { ) /** - * Remove duplicates from an array, keeping the first occurrence of an element. + * Removes duplicate elements from a `Chunk`, preserving the first occurrence + * of each value. + * + * **Example** (Removing duplicate values) * - * @example * ```ts * import { Chunk } from "effect" * @@ -3799,15 +4040,16 @@ export const union: { * console.log(Chunk.toArray(uniqueDeduped)) // [1, 2, 3] * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ export const dedupe = (self: Chunk): Chunk => fromArrayUnsafe(RA.dedupe(toReadonlyArray(self))) /** * Deduplicates adjacent elements that are identical. * - * @example + * **Example** (Removing adjacent duplicates) + * * ```ts * import { Chunk } from "effect" * @@ -3821,17 +4063,20 @@ export const dedupe = (self: Chunk): Chunk => fromArrayUnsafe(RA.dedupe * console.log(Chunk.toArray(mixedResult)) // ["a", "b", "a"] * ``` * - * @since 2.0.0 * @category filtering + * @since 2.0.0 */ export const dedupeAdjacent = (self: Chunk): Chunk => fromArrayUnsafe(RA.dedupeAdjacent(self)) /** - * Takes a `Chunk` of pairs and return two corresponding `Chunk`s. + * Takes a `Chunk` of pairs and returns two corresponding `Chunk`s. + * + * **Details** + * + * This function is the reverse of `zip`. * - * Note: The function is reverse of `zip`. + * **Example** (Unzipping pairs) * - * @example * ```ts * import { Chunk } from "effect" * @@ -3851,8 +4096,8 @@ export const dedupeAdjacent = (self: Chunk): Chunk => fromArrayUnsafe(R * console.log(Chunk.toArray(emptyStrs)) // [] * ``` * - * @since 2.0.0 * @category elements + * @since 2.0.0 */ export const unzip = (self: Chunk): [Chunk, Chunk] => { const [left, right] = RA.unzip(self) @@ -3862,7 +4107,8 @@ export const unzip = (self: Chunk): [Chunk, Chunk] /** * Zips this chunk pointwise with the specified chunk using the specified combiner. * - * @example + * **Example** (Zipping chunks with a function) + * * ```ts * import { Chunk } from "effect" * @@ -3878,14 +4124,15 @@ export const unzip = (self: Chunk): [Chunk, Chunk] * console.log(Chunk.toArray(mixed)) // [[1, "a"], [2, "b"]] * ``` * - * @since 2.0.0 * @category zipping + * @since 2.0.0 */ export const zipWith: { /** * Zips this chunk pointwise with the specified chunk using the specified combiner. * - * @example + * **Example** (Zipping chunks with a function) + * * ```ts * import { Chunk } from "effect" * @@ -3901,14 +4148,15 @@ export const zipWith: { * console.log(Chunk.toArray(mixed)) // [[1, "a"], [2, "b"]] * ``` * - * @since 2.0.0 * @category zipping + * @since 2.0.0 */ (that: Chunk, f: (a: A, b: B) => C): (self: Chunk) => Chunk /** * Zips this chunk pointwise with the specified chunk using the specified combiner. * - * @example + * **Example** (Zipping chunks with a function) + * * ```ts * import { Chunk } from "effect" * @@ -3924,8 +4172,8 @@ export const zipWith: { * console.log(Chunk.toArray(mixed)) // [[1, "a"], [2, "b"]] * ``` * - * @since 2.0.0 * @category zipping + * @since 2.0.0 */ (self: Chunk, that: Chunk, f: (a: A, b: B) => C): Chunk } = dual( @@ -3937,7 +4185,8 @@ export const zipWith: { /** * Zips this chunk pointwise with the specified chunk. * - * @example + * **Example** (Zipping chunks) + * * ```ts * import { Chunk } from "effect" * @@ -3953,14 +4202,15 @@ export const zipWith: { * console.log(Chunk.toArray(zipped)) // [[1, "a"], [2, "b"]] * ``` * - * @since 2.0.0 * @category zipping + * @since 2.0.0 */ export const zip: { /** * Zips this chunk pointwise with the specified chunk. * - * @example + * **Example** (Zipping chunks) + * * ```ts * import { Chunk } from "effect" * @@ -3976,14 +4226,15 @@ export const zip: { * console.log(Chunk.toArray(zipped)) // [[1, "a"], [2, "b"]] * ``` * - * @since 2.0.0 * @category zipping + * @since 2.0.0 */ (that: Chunk): (self: Chunk) => Chunk<[A, B]> /** * Zips this chunk pointwise with the specified chunk. * - * @example + * **Example** (Zipping chunks) + * * ```ts * import { Chunk } from "effect" * @@ -3999,8 +4250,8 @@ export const zip: { * console.log(Chunk.toArray(zipped)) // [[1, "a"], [2, "b"]] * ``` * - * @since 2.0.0 * @category zipping + * @since 2.0.0 */ (self: Chunk, that: Chunk): Chunk<[A, B]> } = dual( @@ -4009,9 +4260,10 @@ export const zip: { ) /** - * Delete the element at the specified index, creating a new `Chunk`. + * Deletes the element at the specified index, creating a new `Chunk`. + * + * **Example** (Removing an element) * - * @example * ```ts * import { Chunk } from "effect" * @@ -4033,9 +4285,10 @@ export const zip: { */ export const remove: { /** - * Delete the element at the specified index, creating a new `Chunk`. + * Deletes the element at the specified index, creating a new `Chunk`. + * + * **Example** (Removing an element) * - * @example * ```ts * import { Chunk } from "effect" * @@ -4057,9 +4310,10 @@ export const remove: { */ (i: number): (self: Chunk) => Chunk /** - * Delete the element at the specified index, creating a new `Chunk`. + * Deletes the element at the specified index, creating a new `Chunk`. + * + * **Example** (Removing an element) * - * @example * ```ts * import { Chunk } from "effect" * @@ -4086,10 +4340,11 @@ export const remove: { ) /** - * Applies a function to the element at the specified index, creating a new `Chunk`, + * Applies a function to the element at the specified index safely, creating a new `Chunk`, * or returns `None` if the index is out of bounds. * - * @example + * **Example** (Modifying an element) + * * ```ts * import { Chunk } from "effect" * @@ -4111,10 +4366,11 @@ export const remove: { */ export const modify: { /** - * Applies a function to the element at the specified index, creating a new `Chunk`, + * Applies a function to the element at the specified index safely, creating a new `Chunk`, * or returns `None` if the index is out of bounds. * - * @example + * **Example** (Modifying an element) + * * ```ts * import { Chunk } from "effect" * @@ -4136,10 +4392,11 @@ export const modify: { */ (i: number, f: (a: A) => B): (self: Chunk) => O.Option> /** - * Applies a function to the element at the specified index, creating a new `Chunk`, + * Applies a function to the element at the specified index safely, creating a new `Chunk`, * or returns `None` if the index is out of bounds. * - * @example + * **Example** (Modifying an element) + * * ```ts * import { Chunk } from "effect" * @@ -4167,10 +4424,11 @@ export const modify: { ) /** - * Change the element at the specified index, creating a new `Chunk`, + * Changes the element at the specified index safely, creating a new `Chunk`, * or returns `None` if the index is out of bounds. * - * @example + * **Example** (Replacing an element) + * * ```ts * import { Chunk } from "effect" * @@ -4192,10 +4450,11 @@ export const modify: { */ export const replace: { /** - * Change the element at the specified index, creating a new `Chunk`, + * Changes the element at the specified index safely, creating a new `Chunk`, * or returns `None` if the index is out of bounds. * - * @example + * **Example** (Replacing an element) + * * ```ts * import { Chunk } from "effect" * @@ -4217,10 +4476,11 @@ export const replace: { */ (i: number, b: B): (self: Chunk) => O.Option> /** - * Change the element at the specified index, creating a new `Chunk`, + * Changes the element at the specified index safely, creating a new `Chunk`, * or returns `None` if the index is out of bounds. * - * @example + * **Example** (Replacing an element) + * * ```ts * import { Chunk } from "effect" * @@ -4244,17 +4504,19 @@ export const replace: { } = dual(3, (self: Chunk, i: number, b: B): O.Option> => modify(self, i, () => b)) /** - * Return a Chunk of length n with element i initialized with f(i). + * Returns a non-empty `Chunk` of length `n` with element `i` initialized by `f(i)`. + * + * **Details** + * + * `n` is normalized to an integer greater than or equal to `1`. * - * **Note**. `n` is normalized to an integer >= 1. + * **Example** (Generating chunks from indices) * - * @example * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.makeBy(5, (i) => i * 2) - * console.log(chunk) - * // { _id: 'Chunk', values: [ 0, 2, 4, 6, 8 ] } + * console.log(Chunk.toArray(chunk)) // [0, 2, 4, 6, 8] * ``` * * @category constructors @@ -4262,17 +4524,19 @@ export const replace: { */ export const makeBy: { /** - * Return a Chunk of length n with element i initialized with f(i). + * Returns a non-empty `Chunk` of length `n` with element `i` initialized by `f(i)`. + * + * **Details** * - * **Note**. `n` is normalized to an integer >= 1. + * `n` is normalized to an integer greater than or equal to `1`. + * + * **Example** (Generating chunks from indices) * - * @example * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.makeBy(5, (i) => i * 2) - * console.log(chunk) - * // { _id: 'Chunk', values: [ 0, 2, 4, 6, 8 ] } + * console.log(Chunk.toArray(chunk)) // [0, 2, 4, 6, 8] * ``` * * @category constructors @@ -4280,17 +4544,19 @@ export const makeBy: { */ (f: (i: number) => A): (n: number) => NonEmptyChunk /** - * Return a Chunk of length n with element i initialized with f(i). + * Returns a non-empty `Chunk` of length `n` with element `i` initialized by `f(i)`. + * + * **Details** + * + * `n` is normalized to an integer greater than or equal to `1`. * - * **Note**. `n` is normalized to an integer >= 1. + * **Example** (Generating chunks from indices) * - * @example * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.makeBy(5, (i) => i * 2) - * console.log(chunk) - * // { _id: 'Chunk', values: [ 0, 2, 4, 6, 8 ] } + * console.log(Chunk.toArray(chunk)) // [0, 2, 4, 6, 8] * ``` * * @category constructors @@ -4300,15 +4566,21 @@ export const makeBy: { } = dual(2, (n, f) => fromIterable(RA.makeBy(n, f))) /** - * Create a non empty `Chunk` containing a range of integers, including both endpoints. + * Creates a non-empty `Chunk` of consecutive integers from `start` through + * `end`, inclusive. + * + * **Details** + * + * If `start` is greater than `end`, returns a single-element chunk containing + * `start`. + * + * **Example** (Creating a range) * - * @example * ```ts * import { Chunk } from "effect" * * const chunk = Chunk.range(1, 5) - * console.log(chunk) - * // { _id: 'Chunk', values: [ 1, 2, 3, 4, 5 ] } + * console.log(Chunk.toArray(chunk)) // [1, 2, 3, 4, 5] * ``` * * @category constructors @@ -4324,7 +4596,8 @@ export const range = (start: number, end: number): NonEmptyChunk => /** * Returns a function that checks if a `Chunk` contains a given value using the default `Equivalence`. * - * @example + * **Example** (Checking membership) + * * ```ts * import { Chunk } from "effect" * @@ -4353,7 +4626,8 @@ export const contains: { /** * Returns a function that checks if a `Chunk` contains a given value using the default `Equivalence`. * - * @example + * **Example** (Checking membership) + * * ```ts * import { Chunk } from "effect" * @@ -4382,7 +4656,8 @@ export const contains: { /** * Returns a function that checks if a `Chunk` contains a given value using the default `Equivalence`. * - * @example + * **Example** (Checking membership) + * * ```ts * import { Chunk } from "effect" * @@ -4409,7 +4684,8 @@ export const contains: { /** * Returns a function that checks if a `Chunk` contains a given value using a provided `isEquivalent` function. * - * @example + * **Example** (Checking membership with custom equivalence) + * * ```ts * import { Chunk } from "effect" * @@ -4445,7 +4721,8 @@ export const containsWith: ( * Returns the first element that satisfies the specified * predicate, or `None` if no such element exists. * - * @example + * **Example** (Finding the first matching element) + * * ```ts * import { Chunk, Option } from "effect" * @@ -4475,7 +4752,8 @@ export const findFirst: { * Returns the first element that satisfies the specified * predicate, or `None` if no such element exists. * - * @example + * **Example** (Finding the first matching element) + * * ```ts * import { Chunk, Option } from "effect" * @@ -4505,7 +4783,8 @@ export const findFirst: { * Returns the first element that satisfies the specified * predicate, or `None` if no such element exists. * - * @example + * **Example** (Finding the first matching element) + * * ```ts * import { Chunk, Option } from "effect" * @@ -4535,7 +4814,8 @@ export const findFirst: { * Returns the first element that satisfies the specified * predicate, or `None` if no such element exists. * - * @example + * **Example** (Finding the first matching element) + * * ```ts * import { Chunk, Option } from "effect" * @@ -4565,7 +4845,8 @@ export const findFirst: { * Returns the first element that satisfies the specified * predicate, or `None` if no such element exists. * - * @example + * **Example** (Finding the first matching element) + * * ```ts * import { Chunk, Option } from "effect" * @@ -4594,9 +4875,10 @@ export const findFirst: { } = RA.findFirst /** - * Return the first index for which a predicate holds. + * Returns the first index for which a predicate holds. + * + * **Example** (Finding the first matching index) * - * @example * ```ts * import { Chunk } from "effect" * @@ -4618,9 +4900,10 @@ export const findFirst: { */ export const findFirstIndex: { /** - * Return the first index for which a predicate holds. + * Returns the first index for which a predicate holds. + * + * **Example** (Finding the first matching index) * - * @example * ```ts * import { Chunk } from "effect" * @@ -4642,9 +4925,10 @@ export const findFirstIndex: { */ (predicate: Predicate): (self: Chunk) => O.Option /** - * Return the first index for which a predicate holds. + * Returns the first index for which a predicate holds. + * + * **Example** (Finding the first matching index) * - * @example * ```ts * import { Chunk } from "effect" * @@ -4671,12 +4955,12 @@ export const findFirstIndex: { ) /** - * Find the last element for which a predicate holds. + * Finds the last element for which a predicate holds. + * + * **Example** (Finding the last matching element) * - * @example * ```ts - * import { Chunk } from "effect" - * import * as Option from "effect/Option" + * import { Chunk, Option } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.findLast(chunk, (n) => n < 4) @@ -4697,12 +4981,12 @@ export const findFirstIndex: { */ export const findLast: { /** - * Find the last element for which a predicate holds. + * Finds the last element for which a predicate holds. + * + * **Example** (Finding the last matching element) * - * @example * ```ts - * import { Chunk } from "effect" - * import * as Option from "effect/Option" + * import { Chunk, Option } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.findLast(chunk, (n) => n < 4) @@ -4723,12 +5007,12 @@ export const findLast: { */ (refinement: Refinement, B>): (self: Chunk) => Option /** - * Find the last element for which a predicate holds. + * Finds the last element for which a predicate holds. + * + * **Example** (Finding the last matching element) * - * @example * ```ts - * import { Chunk } from "effect" - * import * as Option from "effect/Option" + * import { Chunk, Option } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.findLast(chunk, (n) => n < 4) @@ -4749,12 +5033,12 @@ export const findLast: { */ (predicate: Predicate>): (self: Chunk) => Option /** - * Find the last element for which a predicate holds. + * Finds the last element for which a predicate holds. + * + * **Example** (Finding the last matching element) * - * @example * ```ts - * import { Chunk } from "effect" - * import * as Option from "effect/Option" + * import { Chunk, Option } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.findLast(chunk, (n) => n < 4) @@ -4775,12 +5059,12 @@ export const findLast: { */ (self: Chunk, refinement: Refinement): Option /** - * Find the last element for which a predicate holds. + * Finds the last element for which a predicate holds. + * + * **Example** (Finding the last matching element) * - * @example * ```ts - * import { Chunk } from "effect" - * import * as Option from "effect/Option" + * import { Chunk, Option } from "effect" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.findLast(chunk, (n) => n < 4) @@ -4803,9 +5087,10 @@ export const findLast: { } = RA.findLast /** - * Return the last index for which a predicate holds. + * Returns the last index for which a predicate holds. + * + * **Example** (Finding the last matching index) * - * @example * ```ts * import { Chunk } from "effect" * @@ -4827,9 +5112,10 @@ export const findLast: { */ export const findLastIndex: { /** - * Return the last index for which a predicate holds. + * Returns the last index for which a predicate holds. + * + * **Example** (Finding the last matching index) * - * @example * ```ts * import { Chunk } from "effect" * @@ -4851,9 +5137,10 @@ export const findLastIndex: { */ (predicate: Predicate): (self: Chunk) => O.Option /** - * Return the last index for which a predicate holds. + * Returns the last index for which a predicate holds. + * + * **Example** (Finding the last matching index) * - * @example * ```ts * import { Chunk } from "effect" * @@ -4880,9 +5167,10 @@ export const findLastIndex: { ) /** - * Check if a predicate holds true for every `Chunk` element. + * Checks whether a predicate holds true for every `Chunk` element. + * + * **Example** (Checking every element) * - * @example * ```ts * import { Chunk } from "effect" * @@ -4907,9 +5195,10 @@ export const findLastIndex: { */ export const every: { /** - * Check if a predicate holds true for every `Chunk` element. + * Checks whether a predicate holds true for every `Chunk` element. + * + * **Example** (Checking every element) * - * @example * ```ts * import { Chunk } from "effect" * @@ -4934,9 +5223,10 @@ export const every: { */ (refinement: Refinement, B>): (self: Chunk) => self is Chunk /** - * Check if a predicate holds true for every `Chunk` element. + * Checks whether a predicate holds true for every `Chunk` element. + * + * **Example** (Checking every element) * - * @example * ```ts * import { Chunk } from "effect" * @@ -4961,9 +5251,10 @@ export const every: { */ (predicate: Predicate): (self: Chunk) => boolean /** - * Check if a predicate holds true for every `Chunk` element. + * Checks whether a predicate holds true for every `Chunk` element. + * + * **Example** (Checking every element) * - * @example * ```ts * import { Chunk } from "effect" * @@ -4988,9 +5279,10 @@ export const every: { */ (self: Chunk, refinement: Refinement): self is Chunk /** - * Check if a predicate holds true for every `Chunk` element. + * Checks whether a predicate holds true for every `Chunk` element. + * + * **Example** (Checking every element) * - * @example * ```ts * import { Chunk } from "effect" * @@ -5021,9 +5313,10 @@ export const every: { ) /** - * Check if a predicate holds true for some `Chunk` element. + * Checks whether a predicate holds true for some `Chunk` element. + * + * **Example** (Checking for some matching element) * - * @example * ```ts * import { Chunk } from "effect" * @@ -5045,9 +5338,10 @@ export const every: { */ export const some: { /** - * Check if a predicate holds true for some `Chunk` element. + * Checks whether a predicate holds true for some `Chunk` element. + * + * **Example** (Checking for some matching element) * - * @example * ```ts * import { Chunk } from "effect" * @@ -5069,9 +5363,10 @@ export const some: { */ (predicate: Predicate>): (self: Chunk) => self is NonEmptyChunk /** - * Check if a predicate holds true for some `Chunk` element. + * Checks whether a predicate holds true for some `Chunk` element. + * + * **Example** (Checking for some matching element) * - * @example * ```ts * import { Chunk } from "effect" * @@ -5100,7 +5395,8 @@ export const some: { /** * Joins the elements together with "sep" in the middle. * - * @example + * **Example** (Joining chunks into a string) + * * ```ts * import { Chunk } from "effect" * @@ -5128,7 +5424,8 @@ export const join: { /** * Joins the elements together with "sep" in the middle. * - * @example + * **Example** (Joining chunks into a string) + * * ```ts * import { Chunk } from "effect" * @@ -5156,7 +5453,8 @@ export const join: { /** * Joins the elements together with "sep" in the middle. * - * @example + * **Example** (Joining chunks into a string) + * * ```ts * import { Chunk } from "effect" * @@ -5186,7 +5484,8 @@ export const join: { /** * Reduces the elements of a chunk from left to right. * - * @example + * **Example** (Reducing from the left) + * * ```ts * import { Chunk } from "effect" * @@ -5211,7 +5510,8 @@ export const reduce: { /** * Reduces the elements of a chunk from left to right. * - * @example + * **Example** (Reducing from the left) + * * ```ts * import { Chunk } from "effect" * @@ -5236,7 +5536,8 @@ export const reduce: { /** * Reduces the elements of a chunk from left to right. * - * @example + * **Example** (Reducing from the left) + * * ```ts * import { Chunk } from "effect" * @@ -5263,7 +5564,8 @@ export const reduce: { /** * Reduces the elements of a chunk from right to left. * - * @example + * **Example** (Reducing from the right) + * * ```ts * import { Chunk } from "effect" * @@ -5292,7 +5594,8 @@ export const reduceRight: { /** * Reduces the elements of a chunk from right to left. * - * @example + * **Example** (Reducing from the right) + * * ```ts * import { Chunk } from "effect" * @@ -5321,7 +5624,8 @@ export const reduceRight: { /** * Reduces the elements of a chunk from right to left. * - * @example + * **Example** (Reducing from the right) + * * ```ts * import { Chunk } from "effect" * @@ -5353,7 +5657,8 @@ export const reduceRight: { * Creates a `Chunk` of values not included in the other given `Chunk` using the provided `isEquivalent` function. * The order and references of result values are determined by the first `Chunk`. * - * @example + * **Example** (Computing difference with custom equivalence) + * * ```ts * import { Chunk } from "effect" * @@ -5394,7 +5699,8 @@ export const differenceWith = (isEquivalent: (self: A, that: A) => boolean): * Creates a `Chunk` of values not included in the other given `Chunk`. * The order and references of result values are determined by the first `Chunk`. * - * @example + * **Example** (Computing chunk difference) + * * ```ts * import { Chunk } from "effect" * @@ -5423,7 +5729,8 @@ export const difference: { * Creates a `Chunk` of values not included in the other given `Chunk`. * The order and references of result values are determined by the first `Chunk`. * - * @example + * **Example** (Computing chunk difference) + * * ```ts * import { Chunk } from "effect" * @@ -5452,7 +5759,8 @@ export const difference: { * Creates a `Chunk` of values not included in the other given `Chunk`. * The order and references of result values are determined by the first `Chunk`. * - * @example + * **Example** (Computing chunk difference) + * * ```ts * import { Chunk } from "effect" *