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
Map
fromcontainers
andHashMap
fromunordered-containers
, but there is no way to efficiently lookup a value by key without adding new dependencies, e.g. we're not reexportingMap.lookup
andMap.!?
Note that we already have
ToPairs t
typeclass that haveKey t
andVal t
type synonyms, and there are instances forMap
andHashMap
Possible solutions
lookupMap
forMap
andlookupHashMap
froHashMap
(I don't like it, since I like the current classy-approach).lookup
and!?
toToPairs t
class withPrelude.lookup . toPairs
default implementation. Use proper functions forMap
andHashMap
instances, adding necessary (Ord/Hashable k, Eq v
) constraints to those instances. I like this approach, but one can accidentally uselookup
for[(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 forMap
andHashMap
.