Files
MycLib/Src/Data/Myc.Data.Tuple.pas
T
Michael Schimmel 991b998cb1 Tuples
2026-01-04 18:48:04 +01:00

46 lines
975 B
ObjectPascal

unit Myc.Data.Tuple;
interface
type
ITuple<T> = interface
{$region 'private'}
function GetItems(Idx: Integer): T;
function GetCount: Integer;
{$endregion}
property Items[Idx: Integer]: T read GetItems; default;
property Count: Integer read GetCount;
end;
// Concrete generic implementation
TTupleImpl<T> = class(TInterfacedObject, ITuple<T>)
private
FItems: TArray<T>;
function GetItems(Idx: Integer): T;
function GetCount: Integer;
public
constructor Create(const AItems: TArray<T>);
end;
implementation
{ TTupleImpl<T> }
constructor TTupleImpl<T>.Create(const AItems: TArray<T>);
begin
inherited Create;
FItems := AItems;
end;
function TTupleImpl<T>.GetCount: Integer;
begin
Result := Length(FItems);
end;
function TTupleImpl<T>.GetItems(Idx: Integer): T;
begin
Result := FItems[Idx];
end;
end.