Hoogle Search

Within LTS Haskell 24.6 (ghc-9.10.2)

Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.

  1. fromListWith :: (Eq k, Hashable k) => (v -> v -> v) -> [(k, v)] -> HashMap k v

    unordered-containers Data.HashMap.Internal

    Construct a map from a list of elements. Uses the provided function f to merge duplicate entries with (f newVal oldVal).

    Examples

    Given a list xs, create a map with the number of occurrences of each element in xs:
    let xs = ['a', 'b', 'a']
    in fromListWith (+) [ (x, 1) | x <- xs ]
    
    = fromList [('a', 2), ('b', 1)]
    
    Given a list of key-value pairs xs :: [(k, v)], group all values by their keys and return a HashMap k [v].
    let xs = [('a', 1), ('b', 2), ('a', 3)]
    in fromListWith (++) [ (k, [v]) | (k, v) <- xs ]
    
    = fromList [('a', [3, 1]), ('b', [2])]
    
    Note that the lists in the resulting map contain elements in reverse order from their occurrences in the original list. More generally, duplicate entries are accumulated as follows; this matters when f is not commutative or not associative.
    fromListWith f [(k, a), (k, b), (k, c), (k, d)]
    = fromList [(k, f d (f c (f b a)))]
    

  2. fromListWithKey :: (Eq k, Hashable k) => (k -> v -> v -> v) -> [(k, v)] -> HashMap k v

    unordered-containers Data.HashMap.Internal

    Construct a map from a list of elements. Uses the provided function to merge duplicate entries.

    Examples

    Given a list of key-value pairs where the keys are of different flavours, e.g:
    data Key = Div | Sub
    
    and the values need to be combined differently when there are duplicates, depending on the key:
    combine Div = div
    combine Sub = (-)
    
    then fromListWithKey can be used as follows:
    fromListWithKey combine [(Div, 2), (Div, 6), (Sub, 2), (Sub, 3)]
    = fromList [(Div, 3), (Sub, 1)]
    
    More generally, duplicate entries are accumulated as follows;
    fromListWith f [(k, a), (k, b), (k, c), (k, d)]
    = fromList [(k, f k d (f k c (f k b a)))]
    

  3. toList :: HashMap k v -> [(k, v)]

    unordered-containers Data.HashMap.Internal

    Return a list of this map's elements. The list is produced lazily. The order of its elements is unspecified.

  4. fromList :: Int -> [a] -> Array a

    unordered-containers Data.HashMap.Internal.Array

    No documentation available.

  5. fromList' :: Int -> [a] -> Array a

    unordered-containers Data.HashMap.Internal.Array

    No documentation available.

  6. toList :: Array a -> [a]

    unordered-containers Data.HashMap.Internal.Array

    No documentation available.

  7. fromList :: (Eq k, Hashable k) => [(k, v)] -> HashMap k v

    unordered-containers Data.HashMap.Internal.Strict

    Construct a map with the supplied mappings. If the list contains duplicate mappings, the later mappings take precedence.

  8. fromListWith :: (Eq k, Hashable k) => (v -> v -> v) -> [(k, v)] -> HashMap k v

    unordered-containers Data.HashMap.Internal.Strict

    Construct a map from a list of elements. Uses the provided function f to merge duplicate entries with (f newVal oldVal).

    Examples

    Given a list xs, create a map with the number of occurrences of each element in xs:
    let xs = ['a', 'b', 'a']
    in fromListWith (+) [ (x, 1) | x <- xs ]
    
    = fromList [('a', 2), ('b', 1)]
    
    Given a list of key-value pairs xs :: [(k, v)], group all values by their keys and return a HashMap k [v].
    let xs = ('a', 1), ('b', 2), ('a', 3)]
    in fromListWith (++) [ (k, [v]) | (k, v) <- xs ]
    
    = fromList [('a', [3, 1]), ('b', [2])]
    
    Note that the lists in the resulting map contain elements in reverse order from their occurrences in the original list. More generally, duplicate entries are accumulated as follows; this matters when f is not commutative or not associative.
    fromListWith f [(k, a), (k, b), (k, c), (k, d)]
    = fromList [(k, f d (f c (f b a)))]
    

  9. fromListWithKey :: (Eq k, Hashable k) => (k -> v -> v -> v) -> [(k, v)] -> HashMap k v

    unordered-containers Data.HashMap.Internal.Strict

    Construct a map from a list of elements. Uses the provided function to merge duplicate entries.

    Examples

    Given a list of key-value pairs where the keys are of different flavours, e.g:
    data Key = Div | Sub
    
    and the values need to be combined differently when there are duplicates, depending on the key:
    combine Div = div
    combine Sub = (-)
    
    then fromListWithKey can be used as follows:
    fromListWithKey combine [(Div, 2), (Div, 6), (Sub, 2), (Sub, 3)]
    = fromList [(Div, 3), (Sub, 1)]
    
    More generally, duplicate entries are accumulated as follows;
    fromListWith f [(k, a), (k, b), (k, c), (k, d)]
    = fromList [(k, f k d (f k c (f k b a)))]
    

  10. toList :: HashMap k v -> [(k, v)]

    unordered-containers Data.HashMap.Internal.Strict

    Return a list of this map's elements. The list is produced lazily. The order of its elements is unspecified.

Page 50 of many | Previous | Next