I've release a library that allows you to iterate through a collection of items without using loops. It actually uses a loop but you don't use it directly.

I've release a library that allows you to iterate through a collection of items without using loops. It actually uses a loop but you don't use it directly.

By coincidence, it uses roughly the same syntax as proposed by Stefan Glienke in a comment he made in this post https://plus.google.com/105481197125997414290/posts/JvgTFbS6K3y

Using Stefan Glienke 's example, the code using my library would look like this:

function IsEven(num: Integer): Boolean;
begin
  Result := num mod 2 = 0;
end;

function Add17(num: Integer): Integer;
begin
  Result := num + 17;
end;

procedure CastingSomeMagic;
var
  numbers: TArray;
begin
  numbers := [2, 3, 4, 5];
  TSeq.From(numbers)
    .Select(Add17)
    .Where(IsEven)
    .Take(3)
    .ForEach(Writeln);
end;

The library is still fairly brand new and only implements a few higher order functions (eg Map(Select), Filter(Where), Fold, Skip, Take, etc).

Its based around twp main record types TSeq and TSeq and can attach any collection whether it be a TArray, TEnumerable, TStrings, string, TDataSet. Any other collection type can easily be added to it.

Hope you find it interesting.
https://github.com/colinj/Functional

Comments