Skip to content

Instantly share code, notes, and snippets.

@k-bx

k-bx/foldl.hs Secret

Created February 10, 2015 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k-bx/b6b4659875de7e11fe4d to your computer and use it in GitHub Desktop.
Save k-bx/b6b4659875de7e11fe4d to your computer and use it in GitHub Desktop.
countViewsFold :: (Hashable k, Eq k)
=> (Event -> Maybe k)
-> L.Fold Event (MonoidalHashMap k (Sum Integer))
countViewsFold keyF = L.Fold s mempty id
where
s m ev@(Event _ _ _ _ (ThresholdEvent _ _)) =
maybe m (\k -> M.modify (+1) k m) (keyF ev)
s m _ = m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment