Skip to content

TMap

41 exports Added in v2.0.0 Source

Constructors

empty

Added in v2.0.0 Source

Makes an empty TMap.

Signature

declare const empty: <K, V>() => STM.STM<TMap<K, V>>;

fromIterable

Added in v2.0.0 Source

Creates a new TMap from an iterable collection of key/value pairs.

Signature

declare const fromIterable: <K, V>(iterable: Iterable<readonly [K, V]>) => STM.STM<TMap<K, V>>;

make

Added in v2.0.0 Source

Makes a new TMap that is initialized with specified values.

Signature

declare const make: <K, V>(...entries: Array<readonly [K, V]>) => STM.STM<TMap<K, V>>;

Destructors

toArray

Added in v2.0.0 Source

Collects all bindings into an Array.

Signature

declare const toArray: <K, V>(self: TMap<K, V>) => STM.STM<Array<[K, V]>>;

toChunk

Added in v2.0.0 Source

Collects all bindings into a Chunk.

Signature

declare const toChunk: <K, V>(self: TMap<K, V>) => STM.STM<Chunk.Chunk<[K, V]>>;

toHashMap

Added in v2.0.0 Source

Collects all bindings into a HashMap.

Signature

declare const toHashMap: <K, V>(self: TMap<K, V>) => STM.STM<HashMap.HashMap<K, V>>;

toMap

Added in v2.0.0 Source

Collects all bindings into a Map.

Signature

declare const toMap: <K, V>(self: TMap<K, V>) => STM.STM<ReadonlyMap<K, V>>;

Elements

find

Added in v2.0.0 Source

Finds the key/value pair matching the specified predicate, and uses the provided function to extract a value out of it.

Signature

declare const find: {
  <K, V, A>(pf: (key: K, value: V) => Option<A>): (self: TMap<K, V>) => STM<Option<A>>;
  <K, V, A>(self: TMap<K, V>, pf: (key: K, value: V) => Option<A>): STM<Option<A>>;
};

findAll

Added in v2.0.0 Source

Finds all the key/value pairs matching the specified predicate, and uses the provided function to extract values out them.

Signature

declare const findAll: {
  <K, V, A>(pf: (key: K, value: V) => Option<A>): (self: TMap<K, V>) => STM<Array<A>>;
  <K, V, A>(self: TMap<K, V>, pf: (key: K, value: V) => Option<A>): STM<Array<A>>;
};

findAllSTM

Added in v2.0.0 Source

Finds all the key/value pairs matching the specified predicate, and uses the provided effectful function to extract values out of them..

Signature

declare const findAllSTM: {
  <K, V, A, E, R>(
    pf: (key: K, value: V) => STM<A, Option<E>, R>,
  ): (self: TMap<K, V>) => STM<Array<A>, E, R>;
  <K, V, A, E, R>(
    self: TMap<K, V>,
    pf: (key: K, value: V) => STM<A, Option<E>, R>,
  ): STM<Array<A>, E, R>;
};

findSTM

Added in v2.0.0 Source

Finds the key/value pair matching the specified predicate, and uses the provided effectful function to extract a value out of it.

Signature

declare const findSTM: {
  <K, V, A, E, R>(
    f: (key: K, value: V) => STM<A, Option<E>, R>,
  ): (self: TMap<K, V>) => STM<Option<A>, E, R>;
  <K, V, A, E, R>(
    self: TMap<K, V>,
    f: (key: K, value: V) => STM<A, Option<E>, R>,
  ): STM<Option<A>, E, R>;
};

forEach

Added in v2.0.0 Source

Atomically performs transactional-effect for each binding present in map.

Signature

declare const forEach: {
  <K, V, X, E, R>(f: (key: K, value: V) => STM<X, E, R>): (self: TMap<K, V>) => STM<void, E, R>;
  <K, V, X, E, R>(self: TMap<K, V>, f: (key: K, value: V) => STM<X, E, R>): STM<void, E, R>;
};

get

Added in v2.0.0 Source

Retrieves value associated with given key.

Signature

declare const get: {
  <K>(key: K): <V>(self: TMap<K, V>) => STM<Option<V>>;
  <K, V>(self: TMap<K, V>, key: K): STM<Option<V>>;
};

getOrElse

Added in v2.0.0 Source

Retrieves value associated with given key or default value, in case the key isn't present.

Signature

declare const getOrElse: {
  <K, V>(key: K, fallback: LazyArg<V>): (self: TMap<K, V>) => STM<V>;
  <K, V>(self: TMap<K, V>, key: K, fallback: LazyArg<V>): STM<V>;
};

has

Added in v2.0.0 Source

Tests whether or not map contains a key.

Signature

declare const has: {
  <K>(key: K): <V>(self: TMap<K, V>) => STM<boolean>;
  <K, V>(self: TMap<K, V>, key: K): STM<boolean>;
};

keys

Added in v2.0.0 Source

Collects all keys stored in map.

Signature

declare const keys: <K, V>(self: TMap<K, V>) => STM.STM<Array<K>>;

values

Added in v2.0.0 Source

Collects all values stored in map.

Signature

declare const values: <K, V>(self: TMap<K, V>) => STM.STM<Array<V>>;

Folding

reduce

Added in v2.0.0 Source

Atomically folds using a pure function.

Signature

declare const reduce: {
  <Z, K, V>(zero: Z, f: (acc: Z, value: V, key: K) => Z): (self: TMap<K, V>) => STM<Z>;
  <K, V, Z>(self: TMap<K, V>, zero: Z, f: (acc: Z, value: V, key: K) => Z): STM<Z>;
};

reduceSTM

Added in v2.0.0 Source

Atomically folds using a transactional function.

Signature

declare const reduceSTM: {
  <Z, V, K, R, E>(
    zero: Z,
    f: (acc: Z, value: V, key: K) => STM<Z, E, R>,
  ): (self: TMap<K, V>) => STM<Z, E, R>;
  <Z, V, K, R, E>(
    self: TMap<K, V>,
    zero: Z,
    f: (acc: Z, value: V, key: K) => STM<Z, E, R>,
  ): STM<Z, E, R>;
};

Getters

isEmpty

Added in v2.0.0 Source

Tests if the map is empty or not.

Signature

declare const isEmpty: <K, V>(self: TMap<K, V>) => STM.STM<boolean>;

size

Added in v2.0.0 Source

Returns the number of bindings.

Signature

declare const size: <K, V>(self: TMap<K, V>) => STM.STM<number>;

Models

TMap interface

Added in v2.0.0 Source

Transactional map implemented on top of TRef and TArray. Resolves conflicts via chaining.

Signature

interface TMap<in out K, in out V> extends Variance<K, V> {}

Mutations

merge

Added in v2.0.0 Source

If the key is not already associated with a value, stores the provided value, otherwise merge the existing value with the new one using function f and store the result.

Signature

declare const merge: {
  <K, V>(key: K, value: V, f: (x: V, y: V) => V): (self: TMap<K, V>) => STM<V>;
  <K, V>(self: TMap<K, V>, key: K, value: V, f: (x: V, y: V) => V): STM<V>;
};

remove

Added in v2.0.0 Source

Removes binding for given key.

Signature

declare const remove: {
  <K>(key: K): <V>(self: TMap<K, V>) => STM<void>;
  <K, V>(self: TMap<K, V>, key: K): STM<void>;
};

removeAll

Added in v2.0.0 Source

Deletes all entries associated with the specified keys.

Signature

declare const removeAll: {
  <K>(keys: Iterable<K>): <V>(self: TMap<K, V>) => STM<void>;
  <K, V>(self: TMap<K, V>, keys: Iterable<K>): STM<void>;
};

removeIf

Added in v2.0.0 Source

Removes entries from a TMap that satisfy the specified predicate and returns the removed entries (or void if discard = true).

Signature

declare const removeIf: {
  <K, V>(
    predicate: (key: K, value: V) => boolean,
    options: {
      readonly discard: true;
    },
  ): (self: TMap<K, V>) => STM<void>;
  <K, V>(
    predicate: (key: K, value: V) => boolean,
    options?: {
      readonly discard: false;
    },
  ): (self: TMap<K, V>) => STM<Array<[K, V]>>;
  <K, V>(
    self: TMap<K, V>,
    predicate: (key: K, value: V) => boolean,
    options: {
      readonly discard: true;
    },
  ): STM<void>;
  <K, V>(
    self: TMap<K, V>,
    predicate: (key: K, value: V) => boolean,
    options?: {
      readonly discard: false;
    },
  ): STM<Array<[K, V]>>;
};

retainIf

Added in v2.0.0 Source

Retains entries in a TMap that satisfy the specified predicate and returns the removed entries (or void if discard = true).

Signature

declare const retainIf: {
  <K, V>(
    predicate: (key: K, value: V) => boolean,
    options: {
      readonly discard: true;
    },
  ): (self: TMap<K, V>) => STM<void>;
  <K, V>(
    predicate: (key: K, value: V) => boolean,
    options?: {
      readonly discard: false;
    },
  ): (self: TMap<K, V>) => STM<Array<[K, V]>>;
  <K, V>(
    self: TMap<K, V>,
    predicate: (key: K, value: V) => boolean,
    options: {
      readonly discard: true;
    },
  ): STM<void>;
  <K, V>(
    self: TMap<K, V>,
    predicate: (key: K, value: V) => boolean,
    options?: {
      readonly discard: false;
    },
  ): STM<Array<[K, V]>>;
};

set

Added in v2.0.0 Source

Stores new binding into the map.

Signature

declare const set: {
  <K, V>(key: K, value: V): (self: TMap<K, V>) => STM<void>;
  <K, V>(self: TMap<K, V>, key: K, value: V): STM<void>;
};

setIfAbsent

Added in v2.0.0 Source

Stores new binding in the map if it does not already exist.

Signature

declare const setIfAbsent: {
  <K, V>(key: K, value: V): (self: TMap<K, V>) => STM<void>;
  <K, V>(self: TMap<K, V>, key: K, value: V): STM<void>;
};

takeFirst

Added in v2.0.0 Source

Takes the first matching value, or retries until there is one.

Signature

declare const takeFirst: {
  <K, V, A>(pf: (key: K, value: V) => Option<A>): (self: TMap<K, V>) => STM<A>;
  <K, V, A>(self: TMap<K, V>, pf: (key: K, value: V) => Option<A>): STM<A>;
};

takeFirstSTM

Added in v2.0.0 Source

Takes the first matching value, or retries until there is one.

Signature

declare const takeFirstSTM: {
  <K, V, A, E, R>(
    pf: (key: K, value: V) => STM<A, Option<E>, R>,
  ): (self: TMap<K, V>) => STM<A, E, R>;
  <K, V, A, E, R>(self: TMap<K, V>, pf: (key: K, value: V) => STM<A, Option<E>, R>): STM<A, E, R>;
};

takeSome

Added in v2.0.0 Source

Takes all matching values, or retries until there is at least one.

Signature

declare const takeSome: {
  <K, V, A>(pf: (key: K, value: V) => Option<A>): (self: TMap<K, V>) => STM<[A, ...Array<A>]>;
  <K, V, A>(self: TMap<K, V>, pf: (key: K, value: V) => Option<A>): STM<[A, ...Array<A>]>;
};

takeSomeSTM

Added in v2.0.0 Source

Takes all matching values, or retries until there is at least one.

Signature

declare const takeSomeSTM: {
  <K, V, A, E, R>(
    pf: (key: K, value: V) => STM<A, Option<E>, R>,
  ): (self: TMap<K, V>) => STM<[A, ...Array<A>], E, R>;
  <K, V, A, E, R>(
    self: TMap<K, V>,
    pf: (key: K, value: V) => STM<A, Option<E>, R>,
  ): STM<[A, ...Array<A>], E, R>;
};

transform

Added in v2.0.0 Source

Atomically updates all bindings using a pure function.

Signature

declare const transform: {
  <K, V>(f: (key: K, value: V) => readonly [K, V]): (self: TMap<K, V>) => STM<void>;
  <K, V>(self: TMap<K, V>, f: (key: K, value: V) => readonly [K, V]): STM<void>;
};

transformSTM

Added in v2.0.0 Source

Atomically updates all bindings using a transactional function.

Signature

declare const transformSTM: {
  <K, V, R, E>(
    f: (key: K, value: V) => STM<readonly [K, V], E, R>,
  ): (self: TMap<K, V>) => STM<void, E, R>;
  <K, V, R, E>(
    self: TMap<K, V>,
    f: (key: K, value: V) => STM<readonly [K, V], E, R>,
  ): STM<void, E, R>;
};

Atomically updates all values using a pure function.

Signature

declare const transformValues: {
  <V>(f: (value: V) => V): <K>(self: TMap<K, V>) => STM<void>;
  <K, V>(self: TMap<K, V>, f: (value: V) => V): STM<void>;
};

Atomically updates all values using a transactional function.

Signature

declare const transformValuesSTM: {
  <V, R, E>(f: (value: V) => STM<V, E, R>): <K>(self: TMap<K, V>) => STM<void, E, R>;
  <K, V, R, E>(self: TMap<K, V>, f: (value: V) => STM<V, E, R>): STM<void, E, R>;
};

updateWith

Added in v2.0.0 Source

Updates the mapping for the specified key with the specified function, which takes the current value of the key as an input, if it exists, and either returns Some with a new value to indicate to update the value in the map or None to remove the value from the map. Returns Some with the updated value or None if the value was removed from the map.

Signature

declare const updateWith: {
  <K, V>(key: K, f: (value: Option<V>) => Option<V>): (self: TMap<K, V>) => STM<Option<V>>;
  <K, V>(self: TMap<K, V>, key: K, f: (value: Option<V>) => Option<V>): STM<Option<V>>;
};

Other

TMap

Added in v2.0.0 Source

Symbols

TMapTypeId

Added in v2.0.0 Source

Signature

declare const TMapTypeId: unique symbol;

TMapTypeId type

Added in v2.0.0 Source

Signature

type TMapTypeId = typeof TMapTypeId;