relude-1.0.0.0: Safe, performant, user-friendly and lightweight Haskell Standard Library
Copyright(c) 2018-2021 Kowainik
LicenseMIT
MaintainerKowainik <xrom.xkov@gmail.com>
StabilityExperimental
PortabilityPortable
Safe HaskellTrustworthy
LanguageHaskell2010

Relude.Extra.Map

Contents

Description

Contains implementation of polymorphic type classes for data types Set and Map.

Synopsis

Documentation

class StaticMap t where Source #

Read-only map or set. Contains polymorphic functions which work for both sets and maps.

Since: 0.1.0

Associated Types

type Key t :: Type Source #

type Val t :: Type Source #

Methods

size :: t -> Int Source #

lookup :: Key t -> t -> Maybe (Val t) Source #

member :: Key t -> t -> Bool Source #

Instances

Instances details
StaticMap IntSet Source #

Since: 0.1.0

Instance details

Defined in Relude.Extra.Map

Associated Types

type Key IntSet Source #

type Val IntSet Source #

StaticMap (IntMap v) Source #

Since: 0.1.0

Instance details

Defined in Relude.Extra.Map

Associated Types

type Key (IntMap v) Source #

type Val (IntMap v) Source #

Methods

size :: IntMap v -> Int Source #

lookup :: Key (IntMap v) -> IntMap v -> Maybe (Val (IntMap v)) Source #

member :: Key (IntMap v) -> IntMap v -> Bool Source #

Ord a => StaticMap (Set a) Source #

Since: 0.1.0

Instance details

Defined in Relude.Extra.Map

Associated Types

type Key (Set a) Source #

type Val (Set a) Source #

Methods

size :: Set a -> Int Source #

lookup :: Key (Set a) -> Set a -> Maybe (Val (Set a)) Source #

member :: Key (Set a) -> Set a -> Bool Source #

(Eq a, Hashable a) => StaticMap (HashSet a) Source #

Since: 0.1.0

Instance details

Defined in Relude.Extra.Map

Associated Types

type Key (HashSet a) Source #

type Val (HashSet a) Source #

Methods

size :: HashSet a -> Int Source #

lookup :: Key (HashSet a) -> HashSet a -> Maybe (Val (HashSet a)) Source #

member :: Key (HashSet a) -> HashSet a -> Bool Source #

Ord k => StaticMap (Map k v) Source #

Since: 0.1.0

Instance details

Defined in Relude.Extra.Map

Associated Types

type Key (Map k v) Source #

type Val (Map k v) Source #

Methods

size :: Map k v -> Int Source #

lookup :: Key (Map k v) -> Map k v -> Maybe (Val (Map k v)) Source #

member :: Key (Map k v) -> Map k v -> Bool Source #

(Eq k, Hashable k) => StaticMap (HashMap k v) Source #

Since: 0.1.0

Instance details

Defined in Relude.Extra.Map

Associated Types

type Key (HashMap k v) Source #

type Val (HashMap k v) Source #

Methods

size :: HashMap k v -> Int Source #

lookup :: Key (HashMap k v) -> HashMap k v -> Maybe (Val (HashMap k v)) Source #

member :: Key (HashMap k v) -> HashMap k v -> Bool Source #

class StaticMap t => DynamicMap t where Source #

Modifiable Map.

Since: 0.1.0

Methods

insert :: Key t -> Val t -> t -> t Source #

insertWith :: (Val t -> Val t -> Val t) -> Key t -> Val t -> t -> t Source #

delete :: Key t -> t -> t Source #

alter :: (Maybe (Val t) -> Maybe (Val t)) -> Key t -> t -> t Source #

Instances

Instances details
DynamicMap (IntMap v) Source #

Since: 0.1.0

Instance details

Defined in Relude.Extra.Map

Methods

insert :: Key (IntMap v) -> Val (IntMap v) -> IntMap v -> IntMap v Source #

insertWith :: (Val (IntMap v) -> Val (IntMap v) -> Val (IntMap v)) -> Key (IntMap v) -> Val (IntMap v) -> IntMap v -> IntMap v Source #

delete :: Key (IntMap v) -> IntMap v -> IntMap v Source #

alter :: (Maybe (Val (IntMap v)) -> Maybe (Val (IntMap v))) -> Key (IntMap v) -> IntMap v -> IntMap v Source #

Ord k => DynamicMap (Map k v) Source #

Since: 0.1.0

Instance details

Defined in Relude.Extra.Map

Methods

insert :: Key (Map k v) -> Val (Map k v) -> Map k v -> Map k v Source #

insertWith :: (Val (Map k v) -> Val (Map k v) -> Val (Map k v)) -> Key (Map k v) -> Val (Map k v) -> Map k v -> Map k v Source #

delete :: Key (Map k v) -> Map k v -> Map k v Source #

alter :: (Maybe (Val (Map k v)) -> Maybe (Val (Map k v))) -> Key (Map k v) -> Map k v -> Map k v Source #

(Eq k, Hashable k) => DynamicMap (HashMap k v) Source #

Since: 0.1.0

Instance details

Defined in Relude.Extra.Map

Methods

insert :: Key (HashMap k v) -> Val (HashMap k v) -> HashMap k v -> HashMap k v Source #

insertWith :: (Val (HashMap k v) -> Val (HashMap k v) -> Val (HashMap k v)) -> Key (HashMap k v) -> Val (HashMap k v) -> HashMap k v -> HashMap k v Source #

delete :: Key (HashMap k v) -> HashMap k v -> HashMap k v Source #

alter :: (Maybe (Val (HashMap k v)) -> Maybe (Val (HashMap k v))) -> Key (HashMap k v) -> HashMap k v -> HashMap k v Source #

(!?) :: StaticMap t => t -> Key t -> Maybe (Val t) infixl 9 Source #

Operator version of lookup function.

>>> let myHashMap = HashMap.fromList [('a', "xxx"), ('b', "yyy")]
>>> myHashMap !? 'b'
Just "yyy"
>>> myHashMap !? 'd'
Nothing

Since: 0.1.0

notMember :: StaticMap t => Key t -> t -> Bool Source #

Inverse of member function.

>>> let myHashMap = HashMap.fromList [('a', "xxx"), ('b', "yyy")]
>>> notMember 'b' myHashMap
False
>>> notMember 'c' myHashMap
True

Since: 0.1.0

lookupDefault Source #

Arguments

:: StaticMap t 
=> Val t

Default value to return.

-> Key t

Key to search

-> t

Container to search

-> Val t 

Return the value to which the specified key is mapped, or the default value if this map contains no mapping for the key.

>>> let myHashMap = HashMap.fromList [('a', "xxx"), ('b', "yyy")]
>>> lookupDefault "zzz" 'b' myHashMap
"yyy"
>>> lookupDefault "zzz" 'c' myHashMap
"zzz"

Since: 0.1.0

To pairs

toPairs :: (IsList t, Item t ~ (a, b)) => t -> [(a, b)] Source #

Converts the structure to the list of the key-value pairs.

>>> toPairs (HashMap.fromList [('a', "xxx"), ('b', "yyy")])
[('a',"xxx"),('b',"yyy")]

Since: 0.1.0

keys :: (IsList t, Item t ~ (a, b)) => t -> [a] Source #

Converts the structure to the list of the keys.

>>> keys (HashMap.fromList [('a', "xxx"), ('b', "yyy")])
"ab"

Since: 0.1.0

elems :: (IsList t, Item t ~ (a, b)) => t -> [b] Source #

Converts the structure to the list of the values.

>>> elems (HashMap.fromList [('a', "xxx"), ('b', "yyy")])
["xxx","yyy"]

Since: 0.1.0