
24 Oct
2017
24 Oct
'17
6:18 a.m.
Hello all, How can I do something to each element of a list, but only modify one element at at time, so the result is a list of lists, where each sublist is the original list with one element altered. Something like type Each a = (a->a) -> [a] -> [[a]] I came up with: each :: Each a each f [] = [] each f (x:xs) = (f x : xs) : (map (x:) $ each f xs) λ> each (*10) [1..3] [[10,2,3],[1,20,3],[1,2,30]] but I wonder if there is a more standard way of doing this