Skip to content

Chunk

86 exports Added in v2.0.0 Source

Combinators

forEach

Added in v2.0.0 Source

Iterates over each element of a Chunk and applies a function to it.

Details

This function processes every element of the given Chunk, calling the provided function f on each element. It does not return a new value; instead, it is primarily used for side effects, such as logging or accumulating data in an external variable.

Signature

declare const forEach: {
  <A, B>(f: (a: A, index: number) => B): (self: Chunk<A>) => void;
  <A, B>(self: Chunk<A>, f: (a: A, index: number) => B): void;
};

Concatenating

append

Added in v2.0.0 Source

Appends the specified element to the end of the Chunk.

Signature

declare const append: {
  <A2>(a: A2): <A>(self: Chunk<A>) => NonEmptyChunk<A2 | A>;
  <A, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<A | A2>;
};

appendAll

Added in v2.0.0 Source

Concatenates two chunks, combining their elements. If either chunk is non-empty, the result is also a non-empty chunk.

Signature

declare const appendAll: {
  <S extends Chunk<any>, T extends Chunk<any>>(
    that: T,
  ): (self: S) => OrNonEmpty<S, T, Infer<S> | Infer<T>>;
  <A, B>(self: Chunk<A>, that: NonEmptyChunk<B>): NonEmptyChunk<A | B>;
  <A, B>(self: NonEmptyChunk<A>, that: Chunk<B>): NonEmptyChunk<A | B>;
  <A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<A | B>;
};

Example

import { Chunk } from "effect"

const result = Chunk.make(1, 2).pipe(Chunk.appendAll(Chunk.make("a", "b")), Chunk.toArray)

console.log(result)
// [ 1, 2, "a", "b" ]

prepend

Added in v2.0.0 Source

Prepend an element to the front of a Chunk, creating a new NonEmptyChunk.

Signature

declare const prepend: {
  <B>(elem: B): <A>(self: Chunk<A>) => NonEmptyChunk<B | A>;
  <A, B>(self: Chunk<A>, elem: B): NonEmptyChunk<A | B>;
};

prependAll

Added in v2.0.0 Source

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.

Signature

declare const prependAll: {
  <S extends Chunk<any>, T extends Chunk<any>>(
    that: T,
  ): (self: S) => OrNonEmpty<S, T, Infer<S> | Infer<T>>;
  <A, B>(self: Chunk<A>, that: NonEmptyChunk<B>): NonEmptyChunk<A | B>;
  <A, B>(self: NonEmptyChunk<A>, that: Chunk<B>): NonEmptyChunk<A | B>;
  <A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<A | B>;
};

Example

import { Chunk } from "effect"

const result = Chunk.make(1, 2).pipe(Chunk.prependAll(Chunk.make("a", "b")), Chunk.toArray)

console.log(result)
// [ "a", "b", 1, 2 ]

Constructors

empty

Added in v2.0.0 Source

Signature

declare const empty: <A = never>() => Chunk<A>;

fromIterable

Added in v2.0.0 Source

Creates a new Chunk from an iterable collection of values.

Signature

declare function fromIterable<A>(self: Iterable<A>): Chunk<A>;

isChunk

Added in v2.0.0 Source

Checks if u is a Chunk<unknown>

Signature

declare const isChunk: {
  <A>(u: Iterable<A>): u is Chunk<A>;
  (u: unknown): u is Chunk<unknown>;
};

make

Added in v2.0.0 Source

Builds a NonEmptyChunk from an non-empty collection of elements.

Signature

declare function make<As extends readonly [any, any]>(...as: As): NonEmptyChunk<As[number]>;

makeBy

Added in v2.0.0 Source

Return a Chunk of length n with element i initialized with f(i).

Note. n is normalized to an integer >= 1.

Signature

declare const makeBy: {
  <A>(f: (i: number) => A): (n: number) => NonEmptyChunk<A>;
  <A>(n: number, f: (i: number) => A): NonEmptyChunk<A>;
};

of

Added in v2.0.0 Source

Builds a NonEmptyChunk from a single element.

Signature

declare function of<A>(a: A): NonEmptyChunk<A>;

range

Added in v2.0.0 Source

Create a non empty Chunk containing a range of integers, including both endpoints.

Signature

declare function range(start: number, end: number): NonEmptyChunk<number>;

Conversions

toArray

Added in v2.0.0 Source

Converts a Chunk into an Array. If the provided Chunk is non-empty (NonEmptyChunk), the function will return a NonEmptyArray, ensuring the non-empty property is preserved.

Signature

declare const toArray: <S extends Chunk<any>>(
  self: S,
) => S extends NonEmptyChunk<any> ? RA.NonEmptyArray<Chunk.Infer<S>> : Array<Chunk.Infer<S>>;

Converts a Chunk into a ReadonlyArray. If the provided Chunk is non-empty (NonEmptyChunk), the function will return a NonEmptyReadonlyArray, ensuring the non-empty property is preserved.

Signature

declare const toReadonlyArray: <S extends Chunk<any>>(
  self: S,
) => S extends NonEmptyChunk<any>
  ? RA.NonEmptyReadonlyArray<Chunk.Infer<S>>
  : ReadonlyArray<Chunk.Infer<S>>;

Elements

chunksOf

Added in v2.0.0 Source

Groups elements in chunks of up to n elements.

Signature

declare const chunksOf: {
  (n: number): <A>(self: Chunk<A>) => Chunk<Chunk<A>>;
  <A>(self: Chunk<A>, n: number): Chunk<Chunk<A>>;
};

contains

Added in v2.0.0 Source

Returns a function that checks if a Chunk contains a given value using the default Equivalence.

Signature

declare const contains: {
  <A>(a: A): (self: Chunk<A>) => boolean;
  <A>(self: Chunk<A>, a: A): boolean;
};

containsWith

Added in v2.0.0 Source

Returns a function that checks if a Chunk contains a given value using a provided isEquivalent function.

Signature

declare const containsWith: <A>(isEquivalent: (self: A, that: A) => boolean) => {
  (a: A): (self: Chunk<A>) => boolean;
  (self: Chunk<A>, a: A): boolean;
};

dedupe

Added in v2.0.0 Source

Remove duplicates from an array, keeping the first occurrence of an element.

Signature

declare function dedupe<A>(self: Chunk<A>): Chunk<A>;

every

Added in v2.0.0 Source

Check if a predicate holds true for every Chunk element.

Signature

declare const every: {
  <A, B>(refinement: Refinement<NoInfer<A>, B>): (self: Chunk<A>) => self is Chunk<B>;
  <A>(predicate: Predicate<A>): (self: Chunk<A>) => boolean;
  <A, B>(self: Chunk<A>, refinement: Refinement<A, B>): self is Chunk<B>;
  <A>(self: Chunk<A>, predicate: Predicate<A>): boolean;
};

findFirst

Added in v2.0.0 Source

Returns the first element that satisfies the specified predicate, or None if no such element exists.

Signature

declare const findFirst: {
  <A, B>(refinement: Refinement<NoInfer<A>, B>): (self: Chunk<A>) => Option<B>;
  <A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => Option<A>;
  <A, B>(self: Chunk<A>, refinement: Refinement<A, B>): Option<B>;
  <A>(self: Chunk<A>, predicate: Predicate<A>): Option<A>;
};

Return the first index for which a predicate holds.

Signature

declare const findFirstIndex: {
  <A>(predicate: Predicate<A>): (self: Chunk<A>) => Option<number>;
  <A>(self: Chunk<A>, predicate: Predicate<A>): Option<number>;
};

findLast

Added in v2.0.0 Source

Find the last element for which a predicate holds.

Signature

declare const findLast: {
  <A, B>(refinement: Refinement<NoInfer<A>, B>): (self: Chunk<A>) => Option<B>;
  <A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => Option<A>;
  <A, B>(self: Chunk<A>, refinement: Refinement<A, B>): Option<B>;
  <A>(self: Chunk<A>, predicate: Predicate<A>): Option<A>;
};

Return the last index for which a predicate holds.

Signature

declare const findLastIndex: {
  <A>(predicate: Predicate<A>): (self: Chunk<A>) => Option<number>;
  <A>(self: Chunk<A>, predicate: Predicate<A>): Option<number>;
};

get

Added in v2.0.0 Source

This function provides a safe way to read a value at a particular index from a Chunk.

Signature

declare const get: {
  (index: number): <A>(self: Chunk<A>) => Option<A>;
  <A>(self: Chunk<A>, index: number): Option<A>;
};

headNonEmpty

Added in v2.0.0 Source

Returns the first element of this non empty chunk.

Signature

declare const headNonEmpty: <A>(self: NonEmptyChunk<A>) => A;

intersection

Added in v2.0.0 Source

Creates a Chunk of unique values that are included in all given Chunks.

The order and references of result values are determined by the Chunk.

Signature

declare const intersection: {
  <A>(that: Chunk<A>): <B>(self: Chunk<B>) => Chunk<A & B>;
  <A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<A & B>;
};

isEmpty

Added in v2.0.0 Source

Determines if the chunk is empty.

Signature

declare function isEmpty<A>(self: Chunk<A>): boolean;

isNonEmpty

Added in v2.0.0 Source

Determines if the chunk is not empty.

Signature

declare function isNonEmpty<A>(self: Chunk<A>): self is NonEmptyChunk<A>;

last

Added in v2.0.0 Source

Returns the last element of this chunk if it exists.

Signature

declare function last<A>(self: Chunk<A>): Option<A>;

lastNonEmpty

Added in v3.4.0 Source

Returns the last element of this non empty chunk.

Signature

declare const lastNonEmpty: <A>(self: NonEmptyChunk<A>) => A;

reverse

Added in v2.0.0 Source

Reverses the order of elements in a Chunk. Importantly, if the input chunk is a NonEmptyChunk, the reversed chunk will also be a NonEmptyChunk.

Signature

declare const reverse: <S extends Chunk<any>>(self: S) => Chunk.With<S, Chunk.Infer<S>>;

Example

import { Chunk } from "effect"

const chunk = Chunk.make(1, 2, 3)
const result = Chunk.reverse(chunk)

console.log(result)
// { _id: 'Chunk', values: [ 3, 2, 1 ] }

size

Added in v2.0.0 Source

Retireves the size of the chunk

Signature

declare function size<A>(self: Chunk<A>): number;

some

Added in v2.0.0 Source

Check if a predicate holds true for some Chunk element.

Signature

declare const some: {
  <A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => self is NonEmptyChunk<A>;
  <A>(self: Chunk<A>, predicate: Predicate<A>): self is NonEmptyChunk<A>;
};

tail

Added in v2.0.0 Source

Returns every elements after the first.

Signature

declare function tail<A>(self: Chunk<A>): Option<Chunk<A>>;

tailNonEmpty

Added in v2.0.0 Source

Returns every elements after the first.

Signature

declare function tailNonEmpty<A>(self: NonEmptyChunk<A>): Chunk<A>;

takeRight

Added in v2.0.0 Source

Takes the last n elements.

Signature

declare const takeRight: {
  (n: number): <A>(self: Chunk<A>) => Chunk<A>;
  <A>(self: Chunk<A>, n: number): Chunk<A>;
};

takeWhile

Added in v2.0.0 Source

Takes all elements so long as the predicate returns true.

Signature

declare const takeWhile: {
  <A, B>(refinement: Refinement<NoInfer<A>, B>): (self: Chunk<A>) => Chunk<B>;
  <A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => Chunk<A>;
  <A, B>(self: Chunk<A>, refinement: Refinement<A, B>): Chunk<B>;
  <A>(self: Chunk<A>, predicate: Predicate<A>): Chunk<A>;
};

union

Added in v2.0.0 Source

Creates a Chunks of unique values, in order, from all given Chunks.

Signature

declare const union: {
  <A>(that: Chunk<A>): <B>(self: Chunk<B>) => Chunk<A | B>;
  <A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<A | B>;
};

unzip

Added in v2.0.0 Source

Takes a Chunk of pairs and return two corresponding Chunks.

Note: The function is reverse of zip.

Signature

declare function unzip<A, B>(self: Chunk<readonly [A, B]>): [Chunk<A>, Chunk<B>];

Equivalence

Compares the two chunks of equal length using the specified function

Signature

declare function getEquivalence<A>(isEquivalent: Equivalence<A>): Equivalence<Chunk<A>>;

Filtering

compact

Added in v2.0.0 Source

Filter out optional values

Signature

declare function compact<A>(self: Chunk<Option<A>>): Chunk<A>;

Deduplicates adjacent elements that are identical.

Signature

declare function dedupeAdjacent<A>(self: Chunk<A>): Chunk<A>;

filter

Added in v2.0.0 Source

Returns a filtered and mapped subset of the elements.

Signature

declare const filter: {
  <A, B>(refinement: Refinement<NoInfer<A>, B>): (self: Chunk<A>) => Chunk<B>;
  <A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => Chunk<A>;
  <A, B>(self: Chunk<A>, refinement: Refinement<A, B>): Chunk<B>;
  <A>(self: Chunk<A>, predicate: Predicate<A>): Chunk<A>;
};

filterMap

Added in v2.0.0 Source

Returns a filtered and mapped subset of the elements.

Signature

declare const filterMap: {
  <A, B>(f: (a: A, i: number) => Option<B>): (self: Chunk<A>) => Chunk<B>;
  <A, B>(self: Chunk<A>, f: (a: A, i: number) => Option<B>): Chunk<B>;
};

Transforms all elements of the chunk for as long as the specified function returns some value

Signature

declare const filterMapWhile: {
  <A, B>(f: (a: A) => Option<B>): (self: Chunk<A>) => Chunk<B>;
  <A, B>(self: Chunk<A>, f: (a: A) => Option<B>): Chunk<B>;
};

partition

Added in v2.0.0 Source

Separate elements based on a predicate that also exposes the index of the element.

Signature

declare const partition: {
  <A, B>(
    refinement: (a: NoInfer<A>, i: number) => a is B,
  ): (self: Chunk<A>) => [excluded: Chunk<Exclude<A, B>>, satisfying: Chunk<B>];
  <A>(
    predicate: (a: NoInfer<A>, i: number) => boolean,
  ): (self: Chunk<A>) => [excluded: Chunk<A>, satisfying: Chunk<A>];
  <A, B>(
    self: Chunk<A>,
    refinement: (a: A, i: number) => a is B,
  ): [excluded: Chunk<Exclude<A, B>>, satisfying: Chunk<B>];
  <A>(
    self: Chunk<A>,
    predicate: (a: A, i: number) => boolean,
  ): [excluded: Chunk<A>, satisfying: Chunk<A>];
};

partitionMap

Added in v2.0.0 Source

Partitions the elements of this chunk into two chunks using f.

Signature

declare const partitionMap: {
  <A, B, C>(f: (a: A) => Either<C, B>): (self: Chunk<A>) => [left: Chunk<B>, right: Chunk<C>];
  <A, B, C>(self: Chunk<A>, f: (a: A) => Either<C, B>): [left: Chunk<B>, right: Chunk<C>];
};

separate

Added in v2.0.0 Source

Partitions the elements of this chunk into two chunks.

Signature

declare function separate<A, B>(self: Chunk<Either<B, A>>): [Chunk<A>, Chunk<B>];

Folding

join

Added in v2.0.0 Source

Joins the elements together with "sep" in the middle.

Signature

declare const join: {
  (sep: string): (self: Chunk<string>) => string;
  (self: Chunk<string>, sep: string): string;
};

mapAccum

Added in v2.0.0 Source

Statefully maps over the chunk, producing new elements of type B.

Signature

declare const mapAccum: {
  <S, A, B>(s: S, f: (s: S, a: A) => readonly [S, B]): (self: Chunk<A>) => [S, Chunk<B>];
  <S, A, B>(self: Chunk<A>, s: S, f: (s: S, a: A) => readonly [S, B]): [S, Chunk<B>];
};

reduce

Added in v2.0.0 Source

Signature

declare const reduce: {
  <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => B;
  <A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): B;
};

reduceRight

Added in v2.0.0 Source

Signature

declare const reduceRight: {
  <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => B;
  <A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): B;
};

Mapping

map

Added in v2.0.0 Source

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.

Signature

declare const map: {
  <S extends Chunk<any>, B>(f: (a: Infer<S>, i: number) => B): (self: S) => With<S, B>;
  <A, B>(self: NonEmptyChunk<A>, f: (a: A, i: number) => B): NonEmptyChunk<B>;
  <A, B>(self: Chunk<A>, f: (a: A, i: number) => B): Chunk<B>;
};

Example

import { Chunk } from "effect"

const result = Chunk.map(Chunk.make(1, 2), (n) => n + 1)

console.log(result)
// { _id: 'Chunk', values: [ 2, 3 ] }

Model

NonEmptyChunk interface

Added in v2.0.0 Source

Signature

interface NonEmptyChunk<out A> extends Chunk<A>, NonEmptyIterable<A> {}

Models

Chunk interface

Added in v2.0.0 Source

Signature

interface Chunk<out A> extends Iterable<A>, Equal, Pipeable, Inspectable {
  readonly [TypeId]: {
    readonly _A: Covariant<A>;
  };
  readonly length: number;
}

Other

Chunk

Added in v2.0.0 Source

difference

Added in v3.2.0 Source

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.

Signature

declare const difference: {
  <A>(that: Chunk<A>): (self: Chunk<A>) => Chunk<A>;
  <A>(self: Chunk<A>, that: Chunk<A>): Chunk<A>;
};

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.

Signature

declare function differenceWith<A>(isEquivalent: (self: A, that: A) => boolean): {
  (that: Chunk<A>): (self: Chunk<A>) => Chunk<A>;
  (self: Chunk<A>, that: Chunk<A>): Chunk<A>;
};

drop

Added in v2.0.0 Source

Drops the first up to n elements from the chunk

Signature

declare const drop: {
  (n: number): <A>(self: Chunk<A>) => Chunk<A>;
  <A>(self: Chunk<A>, n: number): Chunk<A>;
};

dropRight

Added in v2.0.0 Source

Drops the last n elements.

Signature

declare const dropRight: {
  (n: number): <A>(self: Chunk<A>) => Chunk<A>;
  <A>(self: Chunk<A>, n: number): Chunk<A>;
};

dropWhile

Added in v2.0.0 Source

Drops all elements so long as the predicate returns true.

Signature

declare const dropWhile: {
  <A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => Chunk<A>;
  <A>(self: Chunk<A>, predicate: Predicate<A>): Chunk<A>;
};

modify

Added in v2.0.0 Source

Apply a function to the element at the specified index, creating a new Chunk, or returning the input if the index is out of bounds.

Signature

declare const modify: {
  <A, B>(i: number, f: (a: A) => B): (self: Chunk<A>) => Chunk<A | B>;
  <A, B>(self: Chunk<A>, i: number, f: (a: A) => B): Chunk<A | B>;
};

modifyOption

Added in v2.0.0 Source

Signature

declare const modifyOption: {
  <A, B>(i: number, f: (a: A) => B): (self: Chunk<A>) => Option<Chunk<A | B>>;
  <A, B>(self: Chunk<A>, i: number, f: (a: A) => B): Option<Chunk<A | B>>;
};

remove

Added in v2.0.0 Source

Delete the element at the specified index, creating a new Chunk.

Signature

declare const remove: {
  (i: number): <A>(self: Chunk<A>) => Chunk<A>;
  <A>(self: Chunk<A>, i: number): Chunk<A>;
};

removeOption

Added in v3.16.0 Source

Signature

declare const removeOption: {
  (i: number): <A>(self: Chunk<A>) => Option<Chunk<A>>;
  <A>(self: Chunk<A>, i: number): Option<Chunk<A>>;
};

replace

Added in v2.0.0 Source

Change the element at the specified index, creating a new Chunk, or returning the input if the index is out of bounds.

Signature

declare const replace: {
  <B>(i: number, b: B): <A>(self: Chunk<A>) => Chunk<B | A>;
  <A, B>(self: Chunk<A>, i: number, b: B): Chunk<A | B>;
};

Signature

declare const replaceOption: {
  <B>(i: number, b: B): <A>(self: Chunk<A>) => Option<Chunk<B | A>>;
  <A, B>(self: Chunk<A>, i: number, b: B): Option<Chunk<A | B>>;
};

take

Added in v2.0.0 Source

Takes the first up to n elements from the chunk

Signature

declare const take: {
  (n: number): <A>(self: Chunk<A>) => Chunk<A>;
  <A>(self: Chunk<A>, n: number): Chunk<A>;
};

Sequencing

flatMap

Added in v2.0.0 Source

Applies a function to each element in a chunk and returns a new chunk containing the concatenated mapped elements.

Signature

declare const flatMap: {
  <S extends Chunk<any>, T extends Chunk<any>>(
    f: (a: Infer<S>, i: number) => T,
  ): (self: S) => AndNonEmpty<S, T, Infer<T>>;
  <A, B>(self: NonEmptyChunk<A>, f: (a: A, i: number) => NonEmptyChunk<B>): NonEmptyChunk<B>;
  <A, B>(self: Chunk<A>, f: (a: A, i: number) => Chunk<B>): Chunk<B>;
};

flatten

Added in v2.0.0 Source

Flattens a chunk of chunks into a single chunk by concatenating all chunks.

Signature

declare const flatten: <S extends Chunk<Chunk<any>>>(self: S) => Chunk.Flatten<S>;

Sorting

sort

Added in v2.0.0 Source

Sort the elements of a Chunk in increasing order, creating a new Chunk.

Signature

declare const sort: {
  <B>(O: Order<B>): <A>(self: Chunk<A>) => Chunk<A>;
  <A, B>(self: Chunk<A>, O: Order<B>): Chunk<A>;
};

sortWith

Added in v2.0.0 Source

Signature

declare const sortWith: {
  <A, B>(f: (a: A) => B, order: Order<B>): (self: Chunk<A>) => Chunk<A>;
  <A, B>(self: Chunk<A>, f: (a: A) => B, order: Order<B>): Chunk<A>;
};

Splitting

split

Added in v2.0.0 Source

Splits this chunk into n equally sized chunks.

Signature

declare const split: {
  (n: number): <A>(self: Chunk<A>) => Chunk<Chunk<A>>;
  <A>(self: Chunk<A>, n: number): Chunk<Chunk<A>>;
};

splitAt

Added in v2.0.0 Source

Returns two splits of this chunk at the specified index.

Signature

declare const splitAt: {
  (n: number): <A>(self: Chunk<A>) => [beforeIndex: Chunk<A>, fromIndex: Chunk<A>];
  <A>(self: Chunk<A>, n: number): [beforeIndex: Chunk<A>, fromIndex: Chunk<A>];
};

Splits a NonEmptyChunk into two segments, with the first segment containing a maximum of n elements. The value of n must be >= 1.

Signature

declare const splitNonEmptyAt: {
  (n: number): <A>(self: NonEmptyChunk<A>) => [beforeIndex: NonEmptyChunk<A>, fromIndex: Chunk<A>];
  <A>(self: NonEmptyChunk<A>, n: number): [beforeIndex: NonEmptyChunk<A>, fromIndex: Chunk<A>];
};

splitWhere

Added in v2.0.0 Source

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.

Signature

declare const splitWhere: {
  <A>(
    predicate: Predicate<NoInfer<A>>,
  ): (self: Chunk<A>) => [beforeMatch: Chunk<A>, fromMatch: Chunk<A>];
  <A>(self: Chunk<A>, predicate: Predicate<A>): [beforeMatch: Chunk<A>, fromMatch: Chunk<A>];
};

Symbol

TypeId type

Added in v2.0.0 Source

Signature

type TypeId = typeof TypeId;

Type Lambdas

ChunkTypeLambda interface

Added in v2.0.0 Source

Signature

interface ChunkTypeLambda extends TypeLambda {
  readonly type: Chunk<unknown>;
}

Unsafe

Wraps an array into a chunk without copying, unsafe on mutable arrays

Signature

declare function unsafeFromArray<A>(self: readonly Array<A>): Chunk<A>

Wraps an array into a chunk without copying, unsafe on mutable arrays

Signature

declare function unsafeFromNonEmptyArray<A>(self: readonly [A, A]): NonEmptyChunk<A>;

unsafeGet

Added in v2.0.0 Source

Gets an element unsafely, will throw on out of bounds

Signature

declare const unsafeGet: {
  (index: number): <A>(self: Chunk<A>) => A;
  <A>(self: Chunk<A>, index: number): A;
};

unsafeHead

Added in v2.0.0 Source

Returns the first element of this chunk.

It will throw an error if the chunk is empty.

Signature

declare function unsafeHead<A>(self: Chunk<A>): A;

unsafeLast

Added in v2.0.0 Source

Returns the last element of this chunk.

It will throw an error if the chunk is empty.

Signature

declare function unsafeLast<A>(self: Chunk<A>): A;

Zipping

zip

Added in v2.0.0 Source

Zips this chunk pointwise with the specified chunk.

Signature

declare const zip: {
  <B>(that: Chunk<B>): <A>(self: Chunk<A>) => Chunk<[A, B]>;
  <A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<[A, B]>;
};

zipWith

Added in v2.0.0 Source

Zips this chunk pointwise with the specified chunk using the specified combiner.

Signature

declare const zipWith: {
  <A, B, C>(that: Chunk<B>, f: (a: A, b: B) => C): (self: Chunk<A>) => Chunk<C>;
  <A, B, C>(self: Chunk<A>, that: Chunk<B>, f: (a: A, b: B) => C): Chunk<C>;
};