I'm tempted to write an extension/wrapper for Spring4D where I can do this:
I'm tempted to write an extension/wrapper for Spring4D where I can do this:
*Messages:= MyIList.MoveTo(function(Item: IItem): boolean begin
Result:= true;
end);*
This will result in the following code:
TMyList = class(TInterfacedObject, IList, ....,IMyList)
...
function(const predicate ...): I;
begin
if (TypeOf(I) = TypeOf(IList)) then Result:= TCollections.CreateList;
if TypeOf(I) = ......
//the if typeofs are processed as implicits and are eliminated by the compiler as needed.
//It's a bit laborious, though
inherited MoveTo(Result, predicate);
end;
Now I can chain these and don't need to explicitly create collections myself.
Does this make sense, or am I making some logical error?
Hoping for some discussion, don't need help, but the discussion label has been axed.
*Messages:= MyIList.MoveTo
Result:= true;
end);*
This will result in the following code:
TMyList
...
function
begin
if (TypeOf(I) = TypeOf(IList)) then Result:= TCollections.CreateList;
if TypeOf(I) = ......
//the if typeofs are processed as implicits and are eliminated by the compiler as needed.
//It's a bit laborious, though
inherited MoveTo(Result, predicate);
end;
Now I can chain these and don't need to explicitly create collections myself.
Does this make sense, or am I making some logical error?
Hoping for some discussion, don't need help, but the discussion label has been axed.
Stefan Glienke so is this my right conclusion:
ReplyDeleteA.ExtractRange(B) extracts from B into A and
X.Add(Y.Extract(Y.First)) extracts the first item from Y into X
Now I don't get the meaning of:
N.ExtractAll(function(X: Integer): Boolean begin Result := True; end))
How would I get them into M if M is compatible with N?
Jeroen Wiert Pluimers
ReplyDeleteYour conclusion (or your wording) is not correct:
A.ExtractRange(B) extracts the first occurence of each item in B from A.
It is equal to (and in fact implemented as):
for x in B do
A.Extract(x);
Answer to your question:
M.AddRange(N.ExtractAll(x => true))
Stefan Glienke I'll probably need to write some examples to really get it as ExtractAll returns nothing.
ReplyDelete