The Iterate Pattern Revisited

The Iterate Pattern Revisited
Consider the previous pattern for iteration that I put forth:

        int[] ia = new int[] { 5, 4, 3, 2, 1};
        iterate ia |i| { Console.WriteLine(i); };

I was thinking the other night that it would be nice to provide a criteria for selection of elements for processing as it might be very likely that you may not want to apply code to every element.  My thoughts extend this to the following code snippet:

        int[] ia = new int[] { 5, 4, 3, 2, 1};
        iterate ia |i| do { Console.WriteLine(i); } where { i < 3; };

The do keyword precedes a code block (anonymous method / delegate) that is applied to all elements that match the criteria specified by the code block specified after the where keyword.

Functionally, I would think the runtime would iterate across each element, applying the where code block to each, and in the case of a true condition, then apply the do code to that element.  Additionally, perhaps it might be better to process the where code on all element first build a set of items to process, and then iterate across all of the result set with the do code block.

About the author

I'm a .NET, XAML, and iOS polyglot that loves playing with new things and making cool and innovative stuff.  I am also a Mac junkie.

I am Principal Technologist for SunGard Global Services in NYC, in their Advanced Technologies practice, and I work extensively with SunGard's energy and financial customers.

Note the the posting on this blog are my own and do not represent the position, strategies or opinions of SGS.

Widget TwitterFeed not found.

The file '/widgets/TwitterFeed/widget.ascx' does not exist.X

Recent Comments

None

Month List