Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
37
Task/Function-composition/Delphi/function-composition.pas
Normal file
37
Task/Function-composition/Delphi/function-composition.pas
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
program AnonCompose;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
type
|
||||
TFunc = reference to function(Value: Integer): Integer;
|
||||
// Alternative: TFunc = TFunc<Integer,Integer>;
|
||||
|
||||
function Compose(F, G: TFunc): TFunc;
|
||||
begin
|
||||
Result:= function(Value: Integer): Integer
|
||||
begin
|
||||
Result:= F(G(Value));
|
||||
end
|
||||
end;
|
||||
|
||||
var
|
||||
Func1, Func2, Func3: TFunc;
|
||||
|
||||
begin
|
||||
Func1:=
|
||||
function(Value: Integer): Integer
|
||||
begin
|
||||
Result:= Value * 2;
|
||||
end;
|
||||
|
||||
Func2:=
|
||||
function(Value: Integer): Integer
|
||||
begin
|
||||
Result:= Value * 3;
|
||||
end;
|
||||
|
||||
Func3:= Compose(Func1, Func2);
|
||||
|
||||
Writeln(Func3(6)); // 36 = 6 * 3 * 2
|
||||
Readln;
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue