Skip to content

Re-export lookup for Map #284

@Sorokin-Anton

Description

@Sorokin-Anton

Problem

We're re-exporting Map from containers and HashMap from unordered-containers, but there is no way to efficiently lookup a value by key without adding new dependencies, e.g. we're not reexporting Map.lookup and Map.!?

Note that we already have ToPairs t typeclass that have Key t and Val t type synonyms, and there are instances for Map and HashMap

Possible solutions

  • export lookupMap for Map and lookupHashMap fro HashMap (I don't like it, since I like the current classy-approach).
  • Add lookup and !? to ToPairs t class with Prelude.lookup . toPairs default implementation. Use proper functions for Map and HashMap instances, adding necessary (Ord/Hashable k, Eq v) constraints to those instances. I like this approach, but one can accidentally use lookup for [(a,b)], which is slow enough if compare to Map/HashMap.
  • Add new class ToPairs t => Lookup t where lookup :: t -> Key t -> Maybe (Val t), make instances for Map and HashMap.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions