Thread overview
filtering a row of a jagged array
Aug 11
DanielG
Aug 11
ag0aep6g
Aug 11
DanielG
August 11
int[][] whatever = [
    [0],
    [0, 1, 2],
    [5, 6, 7, 8, 9, 10]
];
writeln(whatever[2]);                    // [5, 6, 7, 8, 9, 10]
writeln(typeid(whatever[2]));            // int[]
auto x = whatever[2].filter(x => x > 7); // error

Error: template std.algorithm.iteration.filter cannot deduce function from argument types !()(int[], void), candidates are: ...

Online example:
https://run.dlang.io/is/LUXFuF

...

I'm guessing I need to give the compiler some help understanding that this is an array of ints, but 1) how, and 2) why? [if typeid() seems to understand just fine?]

August 11
On 11.08.19 18:11, DanielG wrote:
> auto x = whatever[2].filter(x => x > 7); // error

You just forgot an exclamation mark here.

auto x = whatever[2].filter!(x => x > 7); // works
August 11
On Sunday, 11 August 2019 at 16:11:15 UTC, DanielG wrote:
> int[][] whatever = [
>     [0],
>     [0, 1, 2],
>     [5, 6, 7, 8, 9, 10]
> ];
> writeln(whatever[2]);                    // [5, 6, 7, 8, 9, 10]
> writeln(typeid(whatever[2]));            // int[]
> auto x = whatever[2].filter(x => x > 7); // error
>
> Error: template std.algorithm.iteration.filter cannot deduce function from argument types !()(int[], void), candidates are: ...
>
> Online example:
> https://run.dlang.io/is/LUXFuF
>
> ...
>
> I'm guessing I need to give the compiler some help understanding that this is an array of ints, but 1) how, and 2) why? [if typeid() seems to understand just fine?]

You're missing an exclamation mark after filter - it takes the predicate as a template argument. This compiles just fine:

    auto x = whatever[2].filter!(x => x > 7);

--
  Simen
August 11
Thank you both! Ugh, I have to roll my eyes at missing such a simple error. (This literally occurred in the context of a bunch of other code using 'map' and 'reduce' with the exclamation point, so I don't know why my brain turned off for 'filter')

Thanks again!

August 11
On 08/11/2019 09:43 AM, DanielG wrote:
> such a simple error

You're not alone. We want this bug fixed:

  https://issues.dlang.org/show_bug.cgi?id=17263

Ali