serokell-util-0.10.0: General-purpose functions by Serokell
Serokell.Util.Group
Description
This module introduces functions for grouping.
groupBy :: forall t a b. (Container t, Element t ~ a, Eq b, Hashable b) => (a -> b) -> t -> HashMap b (NonEmpty a) Source #
Groups elements using results of the given function as keys.
>>> groupBy even [1,2,3,4,5,6] fromList [(False,5 :| [3,1]),(True,6 :| [4,2])]
>>>
groupBy even [1,2,3,4,5,6]
groupMapBy :: forall t a b. (Container t, Element t ~ a, Eq b, Hashable b) => (a -> b) -> t -> HashMap b a Source #
Similar to groupBy but keeps only one element as value.
groupBy
>>> groupMapBy even [1,2,3,4,5,6] fromList [(False,1),(True,2)]
groupMapBy even [1,2,3,4,5,6]