Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Index function #78

Open
Open
@robertmassaioli

Description

@robertmassaioli

A nice helper function to add to the library might be:

uniqueIndex :: forall f a b. (Foldable f, Functor f, Ord b) => (a -> b) -> f a -> Map b a
uniqueIndex toKey = M.fromFoldable <<< map (\x -> Tuple (toKey x) x)

I got the idea from the equivalent method from Guava in Java land.

This is obviously a method that we could all re-write ourselves but it seems like a common enough pattern (and one that is easy enough to support) that it might be worth making it into the library.

An equivalent method can be written for StrMap; just replace all references to 'b' with 'String' and 'Map' with 'StrMap'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions