lookup

lookup key assocs looks up a key in an association list. For the result to be Nothing, the list must be finite.

Examples

>>> lookup 2 []
Nothing
>>> lookup 2 [(1, "first")]
Nothing
>>> lookup 2 [(1, "first"), (2, "second"), (3, "third")]
Just "second"
Look up the value at a key in the map. See also lookup.
Look up 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
The element at the specified position, counting from 0. If the specified position is negative or at least the length of the sequence, lookup returns Nothing.
0 <= i < length xs ==> lookup i xs == Just (toList xs !! i)
i < 0 || i >= length xs ==> lookup i xs = Nothing
Unlike index, this can be used to retrieve an element without forcing it. For example, to insert the fifth element of a sequence xs into a Map m at key k, you could use
case lookup 5 xs of
Nothing -> m
Just x -> insert k x m
Return the value to which the specified key is mapped, or Nothing if this map contains no mapping for the key.
Return the value to which the specified key is mapped, or Nothing if this map contains no mapping for the key.
lookup key assocs looks up a key in an association list. For the result to be Nothing, the list must be finite.
>>> lookup 2 []
Nothing

>>> lookup 2 [(1, "first")]
Nothing

>>> lookup 2 [(1, "first"), (2, "second"), (3, "third")]
Just "second"
Lookup the value at a key in the map. See also lookup.
Search a metadata with the given key.
Retrieve a field in the given record by name. The result is empty if the field is missing or if the value cannot be converted to the desired type.
(lookup a) returns the element paired with the first matching item, or Nothing if none matches
Look up the value of a given HTTP header field. Example:
ghci> :set -XOverloadedStrings
ghci> H.lookup "host" $ H.fromList [("Host", "localhost")]
Just "localhost"
ghci> H.lookup "Accept" $ H.fromList [("Host", "localhost")]
Nothing
Looks up a key-value mapping in a hash table. O(n) worst case, (O(1) for cuckoo hash), O(1) amortized.
See the documentation for this function in lookup.
See the documentation for this function in lookup.
See the documentation for this function in Data.HashTable.Class#v:lookup.
Look up a given filepath in the TarIndex. It may return a TarFileEntry containing the TarEntryOffset of the file within the tar file, or if the filepath identifies a directory then it returns a TarDir containing the list of files within that directory. Given the TarEntryOffset you can then use one of the I/O operations:
The lookup function looks up IPRTable with a key of AddrRange. If a routing information in IPRTable matches the key, its value is returned.
>>> let v4 = ["133.4.0.0/16","133.5.0.0/16","133.5.16.0/24","133.5.23.0/24"] :: [AddrRange IPv4]

>>> let rt = fromList $ zip v4 v4

>>> lookup "127.0.0.1" rt
Nothing

>>> lookup "133.3.0.1" rt
Nothing

>>> lookup "133.4.0.0" rt
Just 133.4.0.0/16

>>> lookup "133.4.0.1" rt
Just 133.4.0.0/16

>>> lookup "133.5.16.0" rt
Just 133.5.16.0/24

>>> lookup "133.5.16.1" rt
Just 133.5.16.0/24
lookup key assocs looks up a key in an association list.
>>> lookup 2 [(1, "first"), (2, "second"), (3, "third")]
Just "second"
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