@@ -1,5 +1,5 @@
11module Dict (empty,singleton,insert,update
2− ,get,getSafe,getUnsafe
2+ ,get,getOrElse,getOrFail
33 ,remove,member
44 ,filter
55 ,partition
@@ -19,7 +19,7 @@ Insert, remove, and query operations all take *O(log n)* time.
1919@docs empty, singleton, insert, update, remove
2020
2121# Query
22−@docs member, get, getMaybe, getWithDefault
22+@docs member, get, getOrElse, getOrFail
2323
2424# Combine
2525@docs union, intersect, diff
@@ -96,7 +96,7 @@ dictionary.
9696 get "Mouse" animals == Just Mouse
9797 get "Spike" animals == Nothing
9898
99−The `getSafe` and `getUnsafe` are built-in ways to handle common ways of
99+The `getOrElse` and `getOrFail` are built-in ways to handle common ways of
100100using the resulting `Maybe`.
101101-}
102102get : comparable -> Dict comparable v -> Maybe v
@@ -114,41 +114,41 @@ return a default value.
114114
115115 animals = fromList [ ("Tom", Cat), ("Jerry", Mouse) ]
116116
117− getSafe Dog "Tom" animals == Cat
118− getSafe Dog "Mouse" animals == Mouse
119− getSafe Dog "Spike" animals == Dog
117+ getOrElse Dog "Tom" animals == Cat
118+ getOrElse Dog "Mouse" animals == Mouse
119+ getOrElse Dog "Spike" animals == Dog
120120-}
121−getSafe : v -> comparable -> Dict comparable v -> v
122−getSafe base k t =
121+getOrElse : v -> comparable -> Dict comparable v -> v
122+getOrElse base k t =
123123 case t of
124124 RBEmpty LBlack -> base
125125 RBNode _ k' v l r ->
126126 case Native.Utils.compare k k' of
127− LT -> getSafe base k l
127+ LT -> getOrElse base k l
128128 EQ -> v
129− GT -> getSafe base k r
129+ GT -> getOrElse base k r
130130
131131{-| Get the value associated with a key.
132132
133133 animals = fromList [ ("Tom", Cat), ("Jerry", Mouse) ]
134134
135− get "Tom" animals == Cat
136− get "Mouse" animals == Mouse
137− get "Spike" animals == -- Runtime Error!
135+ getOrFail "Tom" animals == Cat
136+ getOrFail "Mouse" animals == Mouse
137+ getOrFail "Spike" animals == -- Runtime Error!
138138
139139Warning: this function will result in a runtime error if the key is not found,
140−so it is best to use `get` or `getSafe` unless you are very confident the key
141−will be found.
140+so it is best to use `get` or `getOrElse` unless you are sure the key will be
141+found.
142142-}
143−getUnsafe : comparable -> Dict comparable v -> v
144−getUnsafe k t =
143+getOrFail : comparable -> Dict comparable v -> v
144+getOrFail k t =
145145 case t of
146− RBEmpty LBlack -> Native.Error.raise "key not found when using 'getUnsafe'"
146+ RBEmpty LBlack -> Native.Error.raise "key not found when using 'getOrFail'"
147147 RBNode _ k' v l r ->
148148 case Native.Utils.compare k k' of
149− LT -> getUnsafe k l
149+ LT -> getOrFail k l
150150 EQ -> v
151− GT -> getUnsafe k r
151+ GT -> getOrFail k r
152152
153153{-| Determine if a key is in a dictionary. -}
154154member : comparable -> Dict comparable v -> Bool