Class TImmutableMap

Unit

Declaration

type generic TImmutableMap<TKey,TValue,TInfo> = class(specialize TReadOnlyMap<TKey,TValue,TInfo>)

Description

Generic immutable map

Data in this map can be read (see ancestor TReadOnlyMap) and modified by creating new maps.

Example:

type TImmutableMapStringString = specialize TImmutableMap<string, string, THAMTTypeInfo>;
var map, map2, map3: TImmutableMapStringString;
  p: TImmutableMapStringString.PPair;
begin
  map := TImmutableMapStringString.create;
  map2 := map.Insert('hello', 'world');
  map3 := map2.insert('foo', 'bar');

  writeln(map.get('hello', 'default')); // default
  writeln(map.get('foo', 'default')); // default

  writeln(map2.get('hello')); // world
  writeln(map2.get('foo', 'default')); // default

  writeln(map3['hello']); // world
  writeln(map3['foo']); // bar

  //enumerate all
  for p in map3 do
    writeln(pˆ.key, ': ', pˆ.value);

  map.free;
  map2.free;
  map3.free;
end.

Hierarchy

Overview

Methods

Public function include(const key: TKey; const value: TValue; allowOverride: boolean = true): TImmutableMap; inline; overload;
Public function exclude(const key: TKey): TImmutableMap; inline;
Public function insert(const key: TKey; const value: TValue): TImmutableMap; inline;
Public function remove(const key:TKey): TImmutableMap; inline;
Public function clone: TImmutableMap;

Description

Methods

Public function include(const key: TKey; const value: TValue; allowOverride: boolean = true): TImmutableMap; inline; overload;

Creates a new map containing (key, value). If the map does not contain key or allowOverride is true, the value associated with the key is value, otherwise the value is unchanged.

Returns

The new map

Public function exclude(const key: TKey): TImmutableMap; inline;

Creates a new map without key and its associated value

Returns

The new map

Public function insert(const key: TKey; const value: TValue): TImmutableMap; inline;

Creates a new map containing (key, value), or raises an exception if the map already contained key

Returns

The new map

Public function remove(const key:TKey): TImmutableMap; inline;

Creates a new map without key and its associated value, or raises an exception if the map did not contain key

Returns

The new map

Public function clone: TImmutableMap;

Creates a new map equal to self. No data is copied, till either map is modified (copy-on-write).


Generated by PasDoc 0.16.0.