Skip to content

Composing maps? #647

@alexfmpe

Description

@alexfmpe

I was surprised that I couldn't find a Map composition function in containers. It seems it could be done with something no worse than O(n * log m), where n is the size of the initial/source map.

composition :: (Ord a, Ord b) => Map.Map b c -> Map.Map a b -> Map.Map a c
composition bc ab = flip Map.mapMaybe ab $ flip Map.lookup bc

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