lookup

lookup :: Eq a => a -> [(a, b)] -> Maybe b
base Prelude, base Data.List
lookup key assocs looks up a key in an association list.
lookup :: HashTable key val -> key -> IO (Maybe val)
base Data.HashTable
Looks up the value of a key in the hash table.
lookup :: Key -> IntMap a -> Maybe a
containers Data.IntMap.Strict, containers Data.IntMap.Lazy
O(min(n,W)). Lookup the value at a key in the map. See also lookup.
lookup :: Ord k => k -> Map k a -> Maybe a
containers Data.Map.Lazy, containers Data.Map.Strict
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
lookupFM :: Ord a => FiniteMap a b -> a -> Maybe b
fgl Data.Graph.Inductive.Internal.FiniteMap
lookupGE :: Key -> IntMap a -> Maybe (Key, a)
containers Data.IntMap.Strict, containers Data.IntMap.Lazy
O(log n). Find smallest key greater or equal to the given one and return the corresponding (key, value) pair. > lookupGE 3 (fromList [(3,'a'), (5,'b')]) == Just (3, 'a') > lookupGE 4 (fromList [(3,'a'), (5,'b')]) == Just (5, 'b') > lookupGE 6 (fromList [(3,'a'), (5,'b')]) == Nothing
lookupGE :: Key -> IntSet -> Maybe Key
containers Data.IntSet
O(log n). Find smallest element greater or equal to the given one. > lookupGE 3 (fromList [3, 5]) == Just 3 > lookupGE 4 (fromList [3, 5]) == Just 5 > lookupGE 6 (fromList [3, 5]) == Nothing
lookupGE :: Ord a => a -> Set a -> Maybe a
containers Data.Set
O(log n). Find smallest element greater or equal to the given one. > lookupGE 3 (fromList [3, 5]) == Just 3 > lookupGE 4 (fromList [3, 5]) == Just 5 > lookupGE 6 (fromList [3, 5]) == Nothing
lookupGE :: Ord k => k -> Map k v -> Maybe (k, v)
containers Data.Map.Lazy, containers Data.Map.Strict
O(log n). Find smallest key greater or equal to the given one and return the corresponding (key, value) pair. > lookupGE 3 (fromList [(3,'a'), (5,'b')]) == Just (3, 'a') > lookupGE 4 (fromList [(3,'a'), (5,'b')]) == Just (5, 'b') > lookupGE 6 (fromList [(3,'a'), (5,'b')]) == Nothing
lookupGT :: Key -> IntMap a -> Maybe (Key, a)
containers Data.IntMap.Strict, containers Data.IntMap.Lazy
O(log n). Find smallest key greater than the given one and return the corresponding (key, value) pair. > lookupGT 4 (fromList [(3,'a'), (5,'b')]) == Just (5, 'b') > lookupGT 5 (fromList [(3,'a'), (5,'b')]) == Nothing
lookupGT :: Key -> IntSet -> Maybe Key
containers Data.IntSet
O(log n). Find smallest element greater than the given one. > lookupGT 4 (fromList [3, 5]) == Just 5 > lookupGT 5 (fromList [3, 5]) == Nothing
lookupGT :: Ord a => a -> Set a -> Maybe a
containers Data.Set
O(log n). Find smallest element greater than the given one. > lookupGT 4 (fromList [3, 5]) == Just 5 > lookupGT 5 (fromList [3, 5]) == Nothing
lookupGT :: Ord k => k -> Map k v -> Maybe (k, v)
containers Data.Map.Lazy, containers Data.Map.Strict
O(log n). Find smallest key greater than the given one and return the corresponding (key, value) pair. > lookupGT 4 (fromList [(3,'a'), (5,'b')]) == Just (5, 'b') > lookupGT 5 (fromList [(3,'a'), (5,'b')]) == Nothing
lookupHeader :: HeaderName -> [Header] -> Maybe String
HTTP Network.HTTP.Headers
lookupHeader hdr hdrs locates the first header matching hdr in the list hdrs.
lookupIndex :: Ord a => a -> Set a -> Maybe Int
containers Data.Set
O(log n). Lookup the index of an element, which is its zero-based index in the sorted sequence of elements. The index is a number from 0 up to, but not including, the size of the set. > isJust (lookupIndex 2 (fromList [5,3])) == False > fromJust (lookupIndex 3 (fromList [5,3])) == 0 > fromJust (lookupIndex 5 (fromList [5,3])) == 1 > isJust (lookupIndex 6 (fromList [5,3])) == False
lookupIndex :: Ord k => k -> Map k a -> Maybe Int
containers Data.Map.Lazy, containers Data.Map.Strict
O(log n). Lookup the index of a key, which is its zero-based index in the sequence sorted by keys. The index is a number from 0 up to, but not including, the size of the map. > isJust (lookupIndex 2 (fromList [(5,"a"), (3,"b")])) == False > fromJust (lookupIndex 3 (fromList [(5,"a"), (3,"b")])) == 0 > fromJust (lookupIndex 5 (fromList [(5,"a"), (3,"b")])) == 1 > isJust (lookupIndex 6 (fromList [(5,"a"), (3,"b")])) == False
lookupLE :: Key -> IntMap a -> Maybe (Key, a)
containers Data.IntMap.Strict, containers Data.IntMap.Lazy
O(log n). Find largest key smaller or equal to the given one and return the corresponding (key, value) pair. > lookupLE 2 (fromList [(3,'a'), (5,'b')]) == Nothing > lookupLE 4 (fromList [(3,'a'), (5,'b')]) == Just (3, 'a') > lookupLE 5 (fromList [(3,'a'), (5,'b')]) == Just (5, 'b')
lookupLE :: Key -> IntSet -> Maybe Key
containers Data.IntSet
O(log n). Find largest element smaller or equal to the given one. > lookupLE 2 (fromList [3, 5]) == Nothing > lookupLE 4 (fromList [3, 5]) == Just 3 > lookupLE 5 (fromList [3, 5]) == Just 5
lookupLE :: Ord a => a -> Set a -> Maybe a
containers Data.Set
O(log n). Find largest element smaller or equal to the given one. > lookupLE 2 (fromList [3, 5]) == Nothing > lookupLE 4 (fromList [3, 5]) == Just 3 > lookupLE 5 (fromList [3, 5]) == Just 5
lookupLE :: Ord k => k -> Map k v -> Maybe (k, v)
containers Data.Map.Lazy, containers Data.Map.Strict
O(log n). Find largest key smaller or equal to the given one and return the corresponding (key, value) pair. > lookupLE 2 (fromList [(3,'a'), (5,'b')]) == Nothing > lookupLE 4 (fromList [(3,'a'), (5,'b')]) == Just (3, 'a') > lookupLE 5 (fromList [(3,'a'), (5,'b')]) == Just (5, 'b')
lookupLT :: Key -> IntMap a -> Maybe (Key, a)
containers Data.IntMap.Strict, containers Data.IntMap.Lazy
O(log n). Find largest key smaller than the given one and return the corresponding (key, value) pair. > lookupLT 3 (fromList [(3,'a'), (5,'b')]) == Nothing > lookupLT 4 (fromList [(3,'a'), (5,'b')]) == Just (3, 'a')
lookupLT :: Key -> IntSet -> Maybe Key
containers Data.IntSet
O(log n). Find largest element smaller than the given one. > lookupLT 3 (fromList [3, 5]) == Nothing > lookupLT 5 (fromList [3, 5]) == Just 3
lookupLT :: Ord a => a -> Set a -> Maybe a
containers Data.Set
O(log n). Find largest element smaller than the given one. > lookupLT 3 (fromList [3, 5]) == Nothing > lookupLT 5 (fromList [3, 5]) == Just 3
lookupLT :: Ord k => k -> Map k v -> Maybe (k, v)
containers Data.Map.Lazy, containers Data.Map.Strict
O(log n). Find largest key smaller than the given one and return the corresponding (key, value) pair. > lookupLT 3 (fromList [(3,'a'), (5,'b')]) == Nothing > lookupLT 4 (fromList [(3,'a'), (5,'b')]) == Just (3, 'a')
lookupName :: Bool -> String -> Q (Maybe Name)
template-haskell Language.Haskell.TH.Syntax
lookupTypeName :: String -> Q (Maybe Name)
template-haskell Language.Haskell.TH.Syntax, template-haskell Language.Haskell.TH
Look up the given name in the (type namespace of the) current splice's scope. See Language.Haskell.TH.Syntax#namelookup for more details.
lookupValueName :: String -> Q (Maybe Name)
template-haskell Language.Haskell.TH.Syntax, template-haskell Language.Haskell.TH
Look up the given name in the (value namespace of the) current splice's scope. See Language.Haskell.TH.Syntax#namelookup for more details.
insertLookupWithKey :: (Key -> a -> a -> a) -> Key -> a -> IntMap a -> (Maybe a, IntMap a)
containers Data.IntMap.Strict, containers Data.IntMap.Lazy
O(min(n,W)). The expression (insertLookupWithKey f k x map) is a pair (lookup k map) and the second element equal to (insertWithKey f k x map). > let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value > insertLookupWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "5:xxx|a")]) > insertLookupWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "xxx")]) > insertLookupWithKey f 5 "xxx" empty == (Nothing, singleton 5 "xxx") This is how to define insertLookup using insertLookupWithKey: > let insertLookup kx x t = insertLookupWithKey (\_ a _ -> a) kx x t > insertLookup 5 "x" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "x")]) > insertLookup 7 "x" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "x")])
insertLookupWithKey :: Ord k => (k -> a -> a -> a) -> k -> a -> Map k a -> (Maybe a, Map k a)
containers Data.Map.Lazy, containers Data.Map.Strict
O(log n). Combines insert operation with old value retrieval. The expression (insertLookupWithKey f k x map) is a pair map</tt>) and the second element equal to (insertWithKey f k x map). > let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value > insertLookupWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "5:xxx|a")]) > insertLookupWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "xxx")]) > insertLookupWithKey f 5 "xxx" empty == (Nothing, singleton 5 "xxx") This is how to define insertLookup using insertLookupWithKey: > let insertLookup kx x t = insertLookupWithKey (\_ a _ -> a) kx x t > insertLookup 5 "x" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "x")]) > insertLookup 7 "x" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "x")])
insertLookupWithKey' :: Ord k => (k -> a -> a -> a) -> k -> a -> Map k a -> (Maybe a, Map k a)
containers Data.Map
Deprecated. As of version 0.5, replaced by insertLookupWithKey. O(log n). Same as insertLookupWithKey, but the value being inserted to the map is evaluated to WHNF beforehand.
qLookupName :: Quasi m => Bool -> String -> m (Maybe Name)
template-haskell Language.Haskell.TH.Syntax
splitLookup :: Key -> IntMap a -> (IntMap a, Maybe a, IntMap a)
containers Data.IntMap.Strict, containers Data.IntMap.Lazy
O(min(n,W)). Performs a split but also returns whether the pivot key was found in the original map. > splitLookup 2 (fromList [(5,"a"), (3,"b")]) == (empty, Nothing, fromList [(3,"b"), (5,"a")]) > splitLookup 3 (fromList [(5,"a"), (3,"b")]) == (empty, Just "b", singleton 5 "a") > splitLookup 4 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", Nothing, singleton 5 "a") > splitLookup 5 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", Just "a", empty) > splitLookup 6 (fromList [(5,"a"), (3,"b")]) == (fromList [(3,"b"), (5,"a")], Nothing, empty)
splitLookup :: Ord k => k -> Map k a -> (Map k a, Maybe a, Map k a)
containers Data.Map.Lazy, containers Data.Map.Strict
O(log n). The expression (splitLookup k map) splits a map just like split but also returns lookup k map. > splitLookup 2 (fromList [(5,"a"), (3,"b")]) == (empty, Nothing, fromList [(3,"b"), (5,"a")]) > splitLookup 3 (fromList [(5,"a"), (3,"b")]) == (empty, Just "b", singleton 5 "a") > splitLookup 4 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", Nothing, singleton 5 "a") > splitLookup 5 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", Just "a", empty) > splitLookup 6 (fromList [(5,"a"), (3,"b")]) == (fromList [(3,"b"), (5,"a")], Nothing, empty)
updateLookupWithKey :: (Key -> a -> Maybe a) -> Key -> IntMap a -> (Maybe a, IntMap a)
containers Data.IntMap.Strict, containers Data.IntMap.Lazy
O(min(n,W)). Lookup and update. The function returns original value, if it is updated. This is different behavior than updateLookupWithKey. Returns the original key value if the map entry is deleted. > let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing > updateLookupWithKey f 5 (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "5:new a")]) > updateLookupWithKey f 7 (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a")]) > updateLookupWithKey f 3 (fromList [(5,"a"), (3,"b")]) == (Just "b", singleton 5 "a")
updateLookupWithKey :: Ord k => (k -> a -> Maybe a) -> k -> Map k a -> (Maybe a, Map k a)
containers Data.Map.Lazy, containers Data.Map.Strict
O(log n). Lookup and update. See also updateWithKey. The function returns changed value, if it is updated. Returns the original key value if the map entry is deleted. > let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing > updateLookupWithKey f 5 (fromList [(5,"a"), (3,"b")]) == (Just "5:new a", fromList [(3, "b"), (5, "5:new a")]) > updateLookupWithKey f 7 (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a")]) > updateLookupWithKey f 3 (fromList [(5,"a"), (3,"b")]) == (Just "b", singleton 5 "a")