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.
Problem
We're re-exporting
MapfromcontainersandHashMapfromunordered-containers, but there is no way to efficiently lookup a value by key without adding new dependencies, e.g. we're not reexportingMap.lookupandMap.!?Note that we already have
ToPairs ttypeclass that haveKey tandVal ttype synonyms, and there are instances forMapandHashMapPossible solutions
lookupMapforMapandlookupHashMapfroHashMap(I don't like it, since I like the current classy-approach).lookupand!?toToPairs tclass withPrelude.lookup . toPairsdefault implementation. Use proper functions forMapandHashMapinstances, adding necessary (Ord/Hashable k, Eq v) constraints to those instances. I like this approach, but one can accidentally uselookupfor[(a,b)], which is slow enough if compare toMap/HashMap.class ToPairs t => Lookup t where lookup :: t -> Key t -> Maybe (Val t), make instances forMapandHashMap.