[Haskell-cafe] Where do trivial functions on the usual containers live?
Henning Thielemann
lemming at henning-thielemann.de
Sun Dec 20 12:44:01 UTC 2020
On Sun, 20 Dec 2020, Ignat Insarov wrote:
> I am looking for a place where I can find or put some simple functions that I
> expect but do not find in the `containers` or elsewhere in the standard
> libraries.
I have my own utility library for such functions. However, it does not and
shall not depend on 'containers'.
> Some examples I have in mind:
>
> * Group a collection by an equivalence relation:
>
> classify ∷ Ord π ⇒ (a → π) → [a] →a]]
If the grouped elements must be consecutive then I have
Data.List.Key.group. But I guess, that Ord means that you want to group
all elements with the same key in one group. Then I would use Map anyway
for representing the result.
> * From a finite map, get a map from its range to its fibers:
>
> fibers ∷ (Ord k, Ord v) ⇒ Map k v → Map v (NonEmpty k)
>
> * Put a type into the diagonal of its square:
>
> diagonal = λx → (x, x)
I have Data.Tuple.HT.double. But recently the name 'dup' was discussed
here.
More information about the Haskell-Cafe
mailing list