What is "FilterResult" type?

Sebastiaan Koppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Sep 9 00:59:55 PDT 2015


On Wednesday, 9 September 2015 at 07:19:06 UTC, Bahman Movaqar 
wrote:
> The only way to make it work is `.array.idup` the output of 
> `filter`.  For example:
>
>     auto result = reduce!(
>       (acc, num) => acc.filter!(
>         fb => (fb.x < num && fb.y < num) && (fb.x * fb.y > num)
>       ).array.idup
>     )(foobars, nums);
>
> Honestly, I cannot comprehend anything out of this; why I had 
> to realise the lazy value and `idup` it for it to become usable 
> by `reduce`?
> Does this mean that I am simply missing something obvious?

Reduce takes the seed, calls your function, and your function 
returns a new seed.

What is going wrong is that the types aren't the same. That is, 
the type of the seed you supplied - `typeof(foobars)` - isn't the 
type that your function returns - `typeof(acc.filter!...)`.

`array()` fixes that, no idea why you need `idup()` though.

OT: I wonder, is reduce able to call a different templated 
version of reduce?


More information about the Digitalmars-d-learn mailing list