I ran into an issue and I'm not sure if I'm missing something or if it's just really clunky in C#.
I have a 2D-array (Foo[,]
) and what I want to do is to map it to a Bar[,]
, using nothing but a Func<Foo, Bar>
. Basically, what I want is a functor instance for T[,]
for any given T
.
The "obvious" way is of course to simply build a new array from the ground up, iterating over each column row and column and manually applying the function to ever cell. I would really like to make use of LINQ for this though, because there is no reason whatsoever this should be more complicated than
from cell in matrix
select f(cell)
or the equivalent matrix.Select(f)
.
I can't help but to think that I can't be first one who wanted to do this, so I wonder if there's something similar built-in, or is my best bet to simply write my own LINQ extensions for 2D arrays?