82 lines
1.8 KiB
ObjectPascal
82 lines
1.8 KiB
ObjectPascal
unit Myc.Lazy;
|
|
|
|
interface
|
|
|
|
uses
|
|
System.SysUtils,
|
|
Myc.Signals;
|
|
|
|
type
|
|
IMycLazy<T> = interface
|
|
{$REGION 'property access'}
|
|
function GetChanged: IMycState;
|
|
{$ENDREGION}
|
|
function Pop(out Res: T): Boolean;
|
|
property Changed: IMycState read GetChanged;
|
|
end;
|
|
|
|
TLazy<T> = record
|
|
private
|
|
FLazy: IMycLazy<T>;
|
|
function GetChanged: IMycState; inline;
|
|
class var
|
|
FNull: IMycLazy<T>;
|
|
class constructor CreateClass;
|
|
|
|
public
|
|
constructor Create(const ALazy: IMycLazy<T>);
|
|
|
|
class function Construct(const Changing: IMycState; const Proc: TFunc<T>): IMycLazy<T>; static;
|
|
|
|
class operator Implicit(const A: IMycLazy<T>): TLazy<T>; overload;
|
|
class operator Implicit(const A: TLazy<T>): IMycLazy<T>; overload;
|
|
|
|
function Pop(out Res: T): Boolean; inline;
|
|
|
|
property Changed: IMycState read GetChanged;
|
|
end;
|
|
|
|
implementation
|
|
|
|
uses
|
|
Myc.Core.Lazy;
|
|
|
|
constructor TLazy<T>.Create(const ALazy: IMycLazy<T>);
|
|
begin
|
|
FLazy := ALazy;
|
|
if not Assigned(FLazy) then
|
|
FLazy := FNull;
|
|
end;
|
|
|
|
class function TLazy<T>.Construct(const Changing: IMycState; const Proc: TFunc<T>): IMycLazy<T>;
|
|
begin
|
|
Result := TMycFuncLazy<T>.Create(Changing, Proc);
|
|
end;
|
|
|
|
class constructor TLazy<T>.CreateClass;
|
|
begin
|
|
FNull := TMycNullLazy<T>.Create;
|
|
end;
|
|
|
|
function TLazy<T>.GetChanged: IMycState;
|
|
begin
|
|
Result := FLazy.Changed;
|
|
end;
|
|
|
|
function TLazy<T>.Pop(out Res: T): Boolean;
|
|
begin
|
|
Result := FLazy.Pop(Res);
|
|
end;
|
|
|
|
class operator TLazy<T>.Implicit(const A: IMycLazy<T>): TLazy<T>;
|
|
begin
|
|
Result.Create(A);
|
|
end;
|
|
|
|
class operator TLazy<T>.Implicit(const A: TLazy<T>): IMycLazy<T>;
|
|
begin
|
|
Result := A.FLazy;
|
|
end;
|
|
|
|
end.
|