Proposal #2717: Add nubWith, nubOrd
Isaac Dupree
isaacdupree at charter.net
Wed Oct 22 15:56:33 EDT 2008
Mitchell, Neil wrote:
> Hi
>
>> Were we to keep it, do you have a better naming suggestion?
>
> [Warning: untested code]
>
> filterAccum :: (acc -> x -> (acc,Bool)) -> acc -> [x] -> (acc, [x])
> filterAccum f a [] = (a, [])
> filterAccum f a (x:xs) = (an, [x|b]++rest)
> where (a2,b) = f a x
> (an,rest) = filterAccum f a2 xs
>
> This follows the type of mapAccumL, and is more general than your
> function.
can we call it filterAccumL then? It took me a while to
figure out from the code whether it was truly an "L" or "R"
version, and in principle there could be filterAccumR
(although I don't know why we'd want it)
> You could change the utility function to be (acc -> x ->
> (acc,Maybe y)) to get a variant that is more general than both mapAccum
> and filterAccum.
in which case the result type would be (acc, [y]), and it
would have a similar type and semantics to
Data.Maybe.mapMaybe :: (a -> Maybe b) -> [a] -> [b]
.. maybeAccumL? :-)
-Isaac
More information about the Libraries
mailing list