Logo

Programming-Idioms

History of Idiom 189 > diff from v16 to v17

Edit summary for version 17 by Bart:
New Pascal implementation by user [Bart]

Version 16

2019-10-02, 09:22:28

Version 17

2019-10-06, 11:32:22

Idiom #189 Filter and transform list

Produce a new list y containing the result of function T applied to all elements e of list x that match the predicate P.

Idiom #189 Filter and transform list

Produce a new list y containing the result of function T applied to all elements e of list x that match the predicate P.

Extra Keywords
map apply
Extra Keywords
map apply
Imports
classes
Code
type
  TListPredicate = function(e: pointer): Boolean;
  TListElementFunc = function(e: pointer): pointer;

function NewList(X: TList; P: TListPredicate; T: TListElementFunc): TList;
var
  e: pointer;
begin
  Result := TList.Create;
  for e in X do
  begin
    if P(e) then
      Result.Add(T(e));
  end;
end;