Relude.Extra.Group

relude-1.2.2.0: Safe, performant, user-friendly and lightweight Haskell Standard Library

Copyright | (c) 2018-2023 Kowainik
License | MIT
Maintainer | Kowainik <xrom.xkov@gmail.com>
Stability | Stable
Portability | Portable
Safe Haskell | Safe
Language | Haskell2010

Relude.Extra.Group

Description

Polymorphic grouping functions.

Since: 0.1.0

Synopsis

- groupBy :: (Foldable f, DynamicMap t, Val t ~ NonEmpty a, Monoid t) => (a -> Key t) -> f a -> t
- groupOneBy :: (Foldable f, DynamicMap t, Val t ~ a, Monoid t) => (a -> Key t) -> f a -> t

# Documentation

groupBy :: (Foldable f, DynamicMap t, Val t ~ NonEmpty a, Monoid t) => (a -> Key t) -> f a -> t #

Groups elements using results of the given function as keys.

    >>> groupBy even [1..6] :: HashMap Bool (NonEmpty Int)
    fromList [(False,5 :| [3,1]),(True,6 :| [4,2])]

Since: 0.1.0

groupOneBy :: (Foldable f, DynamicMap t, Val t ~ a, Monoid t) => (a -> Key t) -> f a -> t #

Similar to `groupBy` but keeps only one element as value.

    >>> groupOneBy even [1 .. 6] :: HashMap Bool Int
    fromList [(False,1),(True,2)]

Since: 0.1.0