[Haskell-cafe] PrefixMap: code review request

Lennart Augustsson lennart at augustsson.net
Mon Feb 27 23:26:18 EST 2006


David F.Place wrote:
> partList :: Ord k => [([k],v)]->[k]->[(k,[([k],v)])]
> partList pairs alphabet = reverse . fst $ foldl' f ([],pairs) alphabet
>     where f (result,pairs) l = (result',rest)
>               where (part,rest) = span ((==l) . head . fst) pairs
>             result' = if null part
>                      then result
>                      else (l,part):result
> 

I would write something like:
...
      where f (result, pairs) l =
          case span ((==l) . head . fst) pairs of
          ([],   rest) -> (          result, rest)
          (part, rest) -> ((l, part):result, rest)

    -- Lennart


More information about the Haskell-Cafe mailing list