This commit is contained in:
Michael Schimmel
2025-06-06 01:34:44 +02:00
parent c4d8607d17
commit f70cfe0ec1
2 changed files with 6 additions and 36 deletions
+4 -27
View File
@@ -62,7 +62,7 @@ type
protected
function GetValue: T; virtual; abstract;
public
constructor Create(const AChanged: TState);
constructor Create(const AChanged: TSignal);
destructor Destroy; override;
function Pop(out Res: T): Boolean;
end;
@@ -73,16 +73,7 @@ type
protected
function GetValue: T; override;
public
constructor Create(const AChanged: TState; const AProc: TFunc<T>);
end;
TMycChainedLazy<T> = class(TMycLazyBase<T>)
private
FValue: TLazy<T>.ILazy;
protected
function GetValue: T; override;
public
constructor Create(const AValue: TLazy<T>.ILazy);
constructor Create(const AChanged: TSignal.ISignal; const AProc: TFunc<T>);
end;
implementation
@@ -159,7 +150,7 @@ end;
{ TMycLazyBase<T> }
constructor TMycLazyBase<T>.Create(const AChanged: TState);
constructor TMycLazyBase<T>.Create(const AChanged: TSignal);
begin
inherited Create;
FChanged := TFlag.CreateFlag;
@@ -189,7 +180,7 @@ end;
{ TMycFuncLazy<T> }
constructor TMycFuncLazy<T>.Create(const AChanged: TState; const AProc: TFunc<T>);
constructor TMycFuncLazy<T>.Create(const AChanged: TSignal.ISignal; const AProc: TFunc<T>);
begin
inherited Create(AChanged);
FProc := AProc;
@@ -201,20 +192,6 @@ begin
Result := FProc();
end;
{ TMycChainedLazy<T> }
constructor TMycChainedLazy<T>.Create(const AValue: TLazy<T>.ILazy);
begin
inherited Create(AValue.Changed);
FValue := AValue;
end;
function TMycChainedLazy<T>.GetValue: T;
begin
if not FValue.Pop(Result) then
raise Exception.Create('Lazy chain already popped');
end;
constructor TMycFuncMutable<T>.Create(const AChanged: TSignal; const AProc: TFunc<T>);
begin
inherited Create(AChanged);
+2 -9
View File
@@ -73,9 +73,7 @@ type
class operator Implicit(const A: ILazy): TLazy<T>; overload;
class operator Implicit(const A: TLazy<T>): ILazy; overload;
class function Construct(const Changing: TState; const Proc: TFunc<T>): TLazy<T>; overload; static;
class function Construct(const Value: ILazy): TLazy<T>; overload; static;
class function Construct(const Changing: TSignal.ISignal; const Proc: TFunc<T>): TLazy<T>; overload; static;
class property Null: ILazy read FNull;
function Pop(out Res: T): Boolean; inline;
@@ -141,7 +139,7 @@ begin
FLazy := FNull;
end;
class function TLazy<T>.Construct(const Changing: TState; const Proc: TFunc<T>): TLazy<T>;
class function TLazy<T>.Construct(const Changing: TSignal.ISignal; const Proc: TFunc<T>): TLazy<T>;
begin
Result := TMycFuncLazy<T>.Create(Changing, Proc);
end;
@@ -151,11 +149,6 @@ begin
FNull := TMycNullLazy<T>.Create;
end;
class function TLazy<T>.Construct(const Value: ILazy): TLazy<T>;
begin
Result := TMycChainedLazy<T>.Create(Value);
end;
function TLazy<T>.GetChanged: TState;
begin
Result := FLazy.Changed;