I am trying to do the following:
processRights :: [Either a Int] -> Int
processRights xs = map (\Right x -> x, \Left x -> 0) xs
So, xs is a [Either a Int], and I wish to produce a mapped list of the same length where for each int there is the same int, 0 otherwise.
How can I acomplish that?
You can use the
either,idandconstfunctions:eitherruns the first function for anyLeft, the second function for anyRight.idreturns its argument.constignores its second argument and returns its first argument, its intended use is that e.g.const 0becomes a function that ignores its argument and just returns 0.