@@ -1,5 +1,5 @@
1module Dict (empty,singleton,insert,update
1module Dict (empty,singleton,insert,update
2− ,get,getSafe,getUnsafe
2+ ,get,getOrElse,getOrFail
3 ,remove,member
3 ,remove,member
@@ -19,7 +19,7 @@ Insert, remove, and query operations all take *O(log n)* time.
19@docs empty, singleton, insert, update, remove
19@docs empty, singleton, insert, update, remove
22−@docs member, get, getMaybe, getWithDefault
22+@docs member, get, getOrElse, getOrFail
25@docs union, intersect, diff
25@docs union, intersect, diff
@@ -96,7 +96,7 @@ dictionary.
96 get "Mouse" animals == Just Mouse
96 get "Mouse" animals == Just Mouse
97 get "Spike" animals == Nothing
97 get "Spike" animals == Nothing
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
100using the resulting `Maybe`.
100using the resulting `Maybe`.
102get : comparable -> Dict comparable v -> Maybe v
102get : comparable -> Dict comparable v -> Maybe v
@@ -114,41 +114,41 @@ return a default value.
115 animals = fromList [ ("Tom", Cat), ("Jerry", Mouse) ]
115 animals = fromList [ ("Tom", Cat), ("Jerry", Mouse) ]
117− getSafe Dog "Tom" animals == Cat
117+ getOrElse Dog "Tom" animals == Cat
118− getSafe Dog "Mouse" animals == Mouse
118+ getOrElse Dog "Mouse" animals == Mouse
119− getSafe Dog "Spike" animals == Dog
119+ getOrElse Dog "Spike" animals == Dog
121−getSafe : v -> comparable -> Dict comparable v -> v
121+getOrElse : v -> comparable -> Dict comparable v -> v
122−getSafe base k t =
122+getOrElse base k t =
123 case t of
123 case t of
124 RBEmpty LBlack -> base
124 RBEmpty LBlack -> base
125 RBNode _ k' v l r ->
125 RBNode _ k' v l r ->
126 case Native.Utils.compare k k' of
126 case Native.Utils.compare k k' of
127− LT -> getSafe base k l
127+ LT -> getOrElse base k l
129− GT -> getSafe base k r
129+ GT -> getOrElse base k r
131{-| Get the value associated with a key.
131{-| Get the value associated with a key.
133 animals = fromList [ ("Tom", Cat), ("Jerry", Mouse) ]
133 animals = fromList [ ("Tom", Cat), ("Jerry", Mouse) ]
135− get "Tom" animals == Cat
135+ getOrFail "Tom" animals == Cat
136− get "Mouse" animals == Mouse
136+ getOrFail "Mouse" animals == Mouse
137− get "Spike" animals == -- Runtime Error!
137+ getOrFail "Spike" animals == -- Runtime Error!
139Warning: this function will result in a runtime error if the key is not found,
139Warning: 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
140+so it is best to use `get` or `getOrElse` unless you are sure the key will be
141−will be found.
141+found.
143−getUnsafe : comparable -> Dict comparable v -> v
143+getOrFail : comparable -> Dict comparable v -> v
144−getUnsafe k t =
144+getOrFail k t =
145 case t of
145 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'"
147 RBNode _ k' v l r ->
147 RBNode _ k' v l r ->
148 case Native.Utils.compare k k' of
148 case Native.Utils.compare k k' of
149− LT -> getUnsafe k l
149+ LT -> getOrFail k l
151− GT -> getUnsafe k r
151+ GT -> getOrFail k r
153{-| Determine if a key is in a dictionary. -}
153{-| Determine if a key is in a dictionary. -}
154member : comparable -> Dict comparable v -> Bool
154member : comparable -> Dict comparable v -> Bool