a b c -> b -> c
Runs a Reader and extracts the final value from it. (The inverse of reader.)
Evaluate a state computation with the given initial state and return the final value, discarding the final state.
* m s = fst (runState m
>
O(log n). Find the value at a key. Calls error when the element can not be found.
> fromList [(5,'a'), (3,'b')] ! 1 Error: element not in the map
> fromList [(5,'a'), (3,'b')] ! 5 == 'a'
The underlying computation, as a function of the environment.
The value at the given index in an array.
Returns the element of an immutable array at the specified index.
O(log n). The expression (findWithDefault def k map) returns the value at key k or returns default value def when the key is not in the map.
> findWithDefault 'x' 1 (fromList [(5,'a'), (3,'b')]) == 'x'
> findWithDefault 'x' 5 (fromList [(5,'a'), (3,'b')]) == 'a'
O(log n). Lookup the value at a key in the map.
The function will return the corresponding value as (Just value), or Nothing if the key isn't in the map.
An example of using lookup:
> import Prelude hiding (lookup)
> import Data.Map
>
> employeeDept = fromList([("John","Sales"), ("Bob","IT")])
> deptCountry = fromList([("IT","USA"), ("Sales","France")])
> countryCurrency = fromList([("USA", "Dollar"), ("France", "Euro")])
>
> employeeCurrency :: String -> Maybe String
> employeeCurrency name = do
> dept <- lookup name employeeDept
> country <- lookup dept deptCountry
> lookup country countryCurrency
>
> main = do
> putStrLn $ "John's currency: " ++ (show (employeeCurrency "John"))
> putStrLn $ "Pete's currency: " ++ (show (employeeCurrency "Pete"))
The output of this program:
> John's currency: Just "Euro"
> Pete's currency: Nothing
Evaluate a state computation with the given initial state and return the final state, discarding the final value.
* m s = snd (runState m
>
Remove an entry from the hash table.
The inward-bound degree of the Node.
The outward-bound degree of the Node.
O(log n). Return the index of a key. The index is a number from 0 up to, but not including, the size of the map. Calls error when the key is not a member of the map.
> findIndex 2 (fromList [(5,"a"), (3,"b")]) Error: element is not in the map
> findIndex 3 (fromList [(5,"a"), (3,"b")]) == 0
> findIndex 5 (fromList [(5,"a"), (3,"b")]) == 1
> findIndex 6 (fromList [(5,"a"), (3,"b")]) Error: element is not in the map
O(log n). Is the key a member of the map? See also notMember.
> member 5 (fromList [(5,'a'), (3,'b')]) == True
> member 1 (fromList [(5,'a'), (3,'b')]) == False
O(log n). Is the key not a member of the map? See also member.
> notMember 5 (fromList [(5,'a'), (3,'b')]) == False
> notMember 1 (fromList [(5,'a'), (3,'b')]) == True
Read an element from a mutable array
Show more results