Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-export lookup for Map #284

Open
Sorokin-Anton opened this issue Dec 16, 2022 · 0 comments
Open

Re-export lookup for Map #284

Sorokin-Anton opened this issue Dec 16, 2022 · 0 comments

Comments

@Sorokin-Anton
Copy link
Contributor

Sorokin-Anton commented Dec 16, 2022

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant