How to map a function on the elements of a nested list
haskell
Solution
There's a few ways but the most obvious is:
Prelude> map (map (+1)) [[1,2,3],[4,5,6]]
[[2,3,4],[5,6,7]]
This would be the textbook answer.
Maybe you like to do the outer part with a list comprehension?
Prelude> [ map (+1) xs | xs <- [[1,2,3],[4,5,6]] ]
[[2,3,4],[5,6,7]]
Or even the whole thing?
Prelude> [ [ x + 1 | x <- xs ] | xs <- [[1,2,3],[4,5,6]] ]
[[2,3,4],[5,6,7]]
Problem
This is a trival question. But what is the standard way to map a function (`+1` in this example) on nested list? ``` map (\x -> map (+1) x) [[1,2,3],[4,5,6]] ``` I use the above way in my code, but what is a good way to do that? Is there something like a `mapNested (+1) [[1,2,3],[4,5,6]]` or similar? I used google and hoogle but got too much generic results.