TMutable
This commit is contained in:
+4
-27
@@ -62,7 +62,7 @@ type
|
|||||||
protected
|
protected
|
||||||
function GetValue: T; virtual; abstract;
|
function GetValue: T; virtual; abstract;
|
||||||
public
|
public
|
||||||
constructor Create(const AChanged: TState);
|
constructor Create(const AChanged: TSignal);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function Pop(out Res: T): Boolean;
|
function Pop(out Res: T): Boolean;
|
||||||
end;
|
end;
|
||||||
@@ -73,16 +73,7 @@ type
|
|||||||
protected
|
protected
|
||||||
function GetValue: T; override;
|
function GetValue: T; override;
|
||||||
public
|
public
|
||||||
constructor Create(const AChanged: TState; const AProc: TFunc<T>);
|
constructor Create(const AChanged: TSignal.ISignal; 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);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@@ -159,7 +150,7 @@ end;
|
|||||||
|
|
||||||
{ TMycLazyBase<T> }
|
{ TMycLazyBase<T> }
|
||||||
|
|
||||||
constructor TMycLazyBase<T>.Create(const AChanged: TState);
|
constructor TMycLazyBase<T>.Create(const AChanged: TSignal);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FChanged := TFlag.CreateFlag;
|
FChanged := TFlag.CreateFlag;
|
||||||
@@ -189,7 +180,7 @@ end;
|
|||||||
|
|
||||||
{ TMycFuncLazy<T> }
|
{ 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
|
begin
|
||||||
inherited Create(AChanged);
|
inherited Create(AChanged);
|
||||||
FProc := AProc;
|
FProc := AProc;
|
||||||
@@ -201,20 +192,6 @@ begin
|
|||||||
Result := FProc();
|
Result := FProc();
|
||||||
end;
|
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>);
|
constructor TMycFuncMutable<T>.Create(const AChanged: TSignal; const AProc: TFunc<T>);
|
||||||
begin
|
begin
|
||||||
inherited Create(AChanged);
|
inherited Create(AChanged);
|
||||||
|
|||||||
+2
-9
@@ -73,9 +73,7 @@ type
|
|||||||
class operator Implicit(const A: ILazy): TLazy<T>; overload;
|
class operator Implicit(const A: ILazy): TLazy<T>; overload;
|
||||||
class operator Implicit(const A: TLazy<T>): ILazy; 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 Changing: TSignal.ISignal; const Proc: TFunc<T>): TLazy<T>; overload; static;
|
||||||
class function Construct(const Value: ILazy): TLazy<T>; overload; static;
|
|
||||||
|
|
||||||
class property Null: ILazy read FNull;
|
class property Null: ILazy read FNull;
|
||||||
|
|
||||||
function Pop(out Res: T): Boolean; inline;
|
function Pop(out Res: T): Boolean; inline;
|
||||||
@@ -141,7 +139,7 @@ begin
|
|||||||
FLazy := FNull;
|
FLazy := FNull;
|
||||||
end;
|
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
|
begin
|
||||||
Result := TMycFuncLazy<T>.Create(Changing, Proc);
|
Result := TMycFuncLazy<T>.Create(Changing, Proc);
|
||||||
end;
|
end;
|
||||||
@@ -151,11 +149,6 @@ begin
|
|||||||
FNull := TMycNullLazy<T>.Create;
|
FNull := TMycNullLazy<T>.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TLazy<T>.Construct(const Value: ILazy): TLazy<T>;
|
|
||||||
begin
|
|
||||||
Result := TMycChainedLazy<T>.Create(Value);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TLazy<T>.GetChanged: TState;
|
function TLazy<T>.GetChanged: TState;
|
||||||
begin
|
begin
|
||||||
Result := FLazy.Changed;
|
Result := FLazy.Changed;
|
||||||
|
|||||||
Reference in New Issue
Block a user