Class TImmutableSet

Unit

Declaration

type generic TImmutableSet<TItem,TInfo> = class(specialize TReadOnlySet<TItem,TInfo>)

Description

Generic immutable set

Data in this set can be read (see ancestor TReadOnlySet) and modified by creating new sets.

Example:

type TImmutableSetString = specialize TImmutableSet<string, THAMTTypeInfo>;
var set1, set2, set3: TImmutableSetString;
  p: TImmutableSetString.PItem;
begin
  set1 := TImmutableSetString.create;
  set2 := set1.Insert('hello');
  set3 := set2.insert('foo');

  writeln(set1.contains('hello')); // false
  writeln(set1['foo']);            // false

  writeln(set2.contains('hello')); // true
  writeln(set2['foo']);            // false

  writeln(set3.contains('hello')); // true
  writeln(set3['foo']);            // true

  //enumerate all
  for p in set3 do
    writeln(pˆ);

  set1.free;
  set2.free;
  set3.free;
end.

Hierarchy

Overview

Methods

Public constructor Create;
Public constructor Create(other: specialize TReadOnlyCustomSet<TItem, TInfo>);
Public function include(const item: TItem; allowOverride: boolean = true): TImmutableSet; inline;
Public function exclude(const item: TItem): TImmutableSet; inline;
Public function insert(const item: TItem): TImmutableSet; inline;
Public function remove(const item: TItem): TImmutableSet; inline;
Public function clone: TImmutableSet;

Description

Methods

Public constructor Create;

Creates an empty set

Public constructor Create(other: specialize TReadOnlyCustomSet<TItem, TInfo>);

Creates a set equal to other. No data is copied, till either set is modified (copy-on-write).

Public function include(const item: TItem; allowOverride: boolean = true): TImmutableSet; inline;

Creates a new set containing item item. If the set does not contain item or allowOverride is true, item is inserted, otherwise the value is unchanged.

Returns

The new set

Public function exclude(const item: TItem): TImmutableSet; inline;

Removes an item

Returns

The new set without item

Public function insert(const item: TItem): TImmutableSet; inline;

Inserts an item, or raises an exception if the set already contains the item

Returns

The new set

Public function remove(const item: TItem): TImmutableSet; inline;

Creates a new set without item, or raises an exception if the set did not contain item

Returns

The new set without item

Public function clone: TImmutableSet;

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


Generated by PasDoc 0.16.0.