Skip to content

TxChunk

Stores a Chunk inside transactional state.

A TxChunk<A> keeps its current Chunk<A> in a TxRef, so reads and updates can be committed atomically with other transactional operations. This module offers a transactional version of common chunk workflows, including creating collections, reading or replacing the current chunk, adding or removing values, checking size, slicing, mapping, filtering, and combining chunks.

22 exports Added in v4.0.0 Source

Combinators

append

Added in v4.0.0 Source

Appends an element to the end of the TxChunk.

Details

This function mutates the original TxChunk by adding the element to the end. It does not return a new TxChunk reference.

Signature

declare const append: {
  <A>(element: A): (self: TxChunk<A>) => Effect<void>;
  <A>(self: TxChunk<A>, element: A): Effect<void>;
};

appendAll

Added in v4.0.0 Source

Concatenates another chunk to the end of the TxChunk.

Details

This function mutates the original TxChunk by appending all elements from the other chunk. It does not return a new TxChunk reference.

Signature

declare const appendAll: {
  <A>(other: Chunk<A>): (self: TxChunk<A>) => Effect<void>;
  <A>(self: TxChunk<A>, other: Chunk<A>): Effect<void>;
};

concat

Added in v4.0.0 Source

Concatenates another TxChunk to the end of this TxChunk.

Details

This function mutates the original TxChunk by appending all elements from the other TxChunk. It does not return a new TxChunk reference.

Signature

declare const concat: {
  <A>(other: TxChunk<A>): (self: TxChunk<A>) => Effect<void>;
  <A>(self: TxChunk<A>, other: TxChunk<A>): Effect<void>;
};

drop

Added in v4.0.0 Source

Drops the first n elements from the TxChunk.

Details

This function mutates the original TxChunk by removing the first n elements. It does not return a new TxChunk reference.

Signature

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

filter

Added in v4.0.0 Source

Filters the TxChunk keeping only elements that satisfy the predicate.

Details

This function mutates the original TxChunk by removing elements that don't match the predicate. It does not return a new TxChunk reference.

Signature

declare const filter: {
  <A, B>(refinement: (a: A) => a is B): (self: TxChunk<A>) => Effect<void>;
  <A>(predicate: (a: A) => boolean): (self: TxChunk<A>) => Effect<void>;
  <A, B>(self: TxChunk<A>, refinement: (a: A) => a is B): Effect<void>;
  <A>(self: TxChunk<A>, predicate: (a: A) => boolean): Effect<void>;
};

get

Added in v4.0.0 Source

Reads the current chunk from the TxChunk.

Signature

declare function get<A>(self: TxChunk<A>): Effect<Chunk<A>>;

map

Added in v4.0.0 Source

Maps each element of the TxChunk using a function that returns the same element type.

Details

This function mutates the original TxChunk by transforming each element in place. It does not return a new TxChunk reference.

Signature

declare const map: {
  <A>(f: (a: NoInfer<A>) => A): (self: TxChunk<A>) => Effect<void>;
  <A>(self: TxChunk<A>, f: (a: A) => A): Effect<void>;
};

modify

Added in v4.0.0 Source

Modifies the value of the TxChunk using the provided function.

Details

This function mutates the original TxChunk by updating its internal state. It does not return a new TxChunk reference.

Signature

declare const modify: {
  <A, R>(
    f: (current: Chunk<NoInfer<A>>) => [returnValue: R, newValue: Chunk<A>],
  ): (self: TxChunk<A>) => Effect<R>;
  <A, R>(
    self: TxChunk<A>,
    f: (current: Chunk<A>) => [returnValue: R, newValue: Chunk<A>],
  ): Effect<R>;
};

prepend

Added in v4.0.0 Source

Prepends an element to the beginning of the TxChunk.

Details

This function mutates the original TxChunk by adding the element to the beginning. It does not return a new TxChunk reference.

Signature

declare const prepend: {
  <A>(element: A): (self: TxChunk<A>) => Effect<void>;
  <A>(self: TxChunk<A>, element: A): Effect<void>;
};

prependAll

Added in v4.0.0 Source

Concatenates another chunk to the beginning of the TxChunk.

Details

This function mutates the original TxChunk by prepending all elements from the other chunk. It does not return a new TxChunk reference.

Signature

declare const prependAll: {
  <A>(other: Chunk<A>): (self: TxChunk<A>) => Effect<void>;
  <A>(self: TxChunk<A>, other: Chunk<A>): Effect<void>;
};

set

Added in v4.0.0 Source

Sets the value of the TxChunk.

Details

This function mutates the original TxChunk by replacing its internal state with the provided chunk. It does not return a new TxChunk reference.

Signature

declare const set: {
  <A>(chunk: Chunk<A>): (self: TxChunk<A>) => Effect<void>;
  <A>(self: TxChunk<A>, chunk: Chunk<A>): Effect<void>;
};

size

Added in v4.0.0 Source

Gets the size of the TxChunk.

Signature

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

slice

Added in v4.0.0 Source

Takes a slice of the TxChunk from start to end (exclusive).

Details

This function mutates the original TxChunk by keeping only the elements in the specified range. It does not return a new TxChunk reference.

Signature

declare const slice: {
  (start: number, end: number): <A>(self: TxChunk<A>) => Effect<void>;
  <A>(self: TxChunk<A>, start: number, end: number): Effect<void>;
};

take

Added in v4.0.0 Source

Takes the first n elements from the TxChunk.

Details

This function mutates the original TxChunk by keeping only the first n elements. It does not return a new TxChunk reference.

Signature

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

update

Added in v4.0.0 Source

Updates the value of the TxChunk using the provided function.

Details

This function mutates the original TxChunk by updating its internal state. It does not return a new TxChunk reference.

Signature

declare const update: {
  <A>(f: (current: Chunk<NoInfer<A>>) => Chunk<A>): (self: TxChunk<A>) => Effect<void>;
  <A>(self: TxChunk<A>, f: (current: Chunk<A>) => Chunk<A>): Effect<void>;
};

Constructors

empty

Added in v4.0.0 Source

Creates a new empty TxChunk.

Details

This function returns a new TxChunk reference that is initially empty. No existing TxChunk instances are modified.

Signature

declare function empty<A = never>(): Effect<TxChunk<A>>;

fromIterable

Added in v4.0.0 Source

Creates a new TxChunk from an iterable.

Details

This function returns a new TxChunk reference containing elements from the provided iterable. No existing TxChunk instances are modified.

Signature

declare function fromIterable<A>(iterable: Iterable<A>): Effect<TxChunk<A>>;

make

Added in v4.0.0 Source

Creates a new TxChunk with the specified initial chunk.

Details

This function returns a new TxChunk reference containing the provided initial chunk. No existing TxChunk instances are modified.

Signature

declare function make<A>(initial: Chunk<A>): Effect<TxChunk<A>>;

makeUnsafe

Added in v4.0.0 Source

Creates a new TxChunk with the specified TxRef.

Details

This function returns a new TxChunk reference wrapping the provided TxRef. No existing TxChunk instances are modified.

Signature

declare function makeUnsafe<A>(ref: TxRef<Chunk<A>>): TxChunk<A>;

Models

TxChunk interface

Added in v4.0.0 Source

TxChunk is a transactional chunk data structure that provides Software Transactional Memory (STM) semantics for chunk operations.

Details

Accessed values are tracked by the transaction in order to detect conflicts and to track changes. A transaction will retry whenever a conflict is detected or whenever the transaction explicitly calls Effect.txRetry and any of the accessed TxChunk values change.

Signature

interface TxChunk<in out A> extends Inspectable, Pipeable {
  readonly "~effect/transactions/TxChunk": "~effect/transactions/TxChunk";
  readonly ref: TxRef<Chunk<A>>;
}

Predicates

isEmpty

Added in v4.0.0 Source

Checks whether the TxChunk is empty.

Signature

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

isNonEmpty

Added in v4.0.0 Source

Checks whether the TxChunk is non-empty.

Signature

declare function isNonEmpty<A>(self: TxChunk<A>): Effect<boolean>;