serokell-util-0.8.0: General-purpose functions by Serokell

Safe HaskellNone
LanguageHaskell2010

Serokell.Util.Group

Description

This module introduces functions for grouping.

Synopsis

Documentation

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])]

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.

>>> groupMapBy even [1,2,3,4,5,6]
fromList [(False,1),(True,2)]