What is "FilterResult" type?

Edwin van Leeuwen via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Sep 8 04:21:47 PDT 2015


On Tuesday, 8 September 2015 at 11:08:59 UTC, Bahman Movaqar 
wrote:
> On Tuesday, 8 September 2015 at 10:08:03 UTC, cym13 wrote:
>> Filter is a template and returns a FilterResult range which is 
>> used to lazily compute the result. This behaviour is the same 
>> for map and the majority of functions in std.algorithm.

You can also use .array to (greedily) evaluate the results, which 
(for filter) will return a range of the same type as went in:

void main()
{
     import std.array : array;
     int[] arr = [1, 2, 3, 4, 5];
     int[] result = arr.filter!(x => x%2).array;
}


More information about the Digitalmars-d-learn mailing list