Hoogle Search

Within LTS Haskell 24.45 (ghc-9.10.3)

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

  1. insertMapMin :: Key -> a -> IntMap a -> NEIntMap a

    nonempty-containers Data.IntMap.NonEmpty

    O(1) Convert a IntMap into an NEIntMap by adding a key-value pair where the key is strictly less than all keys in the input map. The keys in the original map must all be strictly greater than the new key. The precondition is not checked.

    insertMapMin 2 "c" (Data.IntMap.fromList [(5,"a"), (3,"b")]) == fromList ((2,"c") :| [(3,"b"), (5,"a")])
    valid (insertMapMin 2 "c" (Data.IntMap.fromList [(5,"a"), (3,"b")])) == True
    valid (insertMapMin 7 "c" (Data.IntMap.fromList [(5,"a"), (3,"b")])) == False
    valid (insertMapMin 3 "c" (Data.IntMap.fromList [(5,"a"), (3,"b")])) == False
    

  2. insertMapWith :: (a -> a -> a) -> Key -> a -> IntMap a -> NEIntMap a

    nonempty-containers Data.IntMap.NonEmpty

    O(log n). Convert a IntMap into an NEIntMap by adding a key-value pair. Because of this, we know that the map must have at least one element, and so therefore cannot be empty. Uses a combining function with the new value as the first argument if the key is already present.

    insertMapWith (++) 4 "c" (Data.IntMap.fromList [(5,"a"), (3,"b")]) == fromList ((3,"b") :| [(4,"c"), (5,"a")])
    insertMapWith (++) 5 "c" (Data.IntMap.fromList [(5,"a"), (3,"b")]) == fromList ((3,"b") :| [(5,"ca")])
    

  3. insertMapWithKey :: (Key -> a -> a -> a) -> Key -> a -> IntMap a -> NEIntMap a

    nonempty-containers Data.IntMap.NonEmpty

    O(log n). Convert a IntMap into an NEIntMap by adding a key-value pair. Because of this, we know that the map must have at least one element, and so therefore cannot be empty. Uses a combining function with the key and new value as the first and second arguments if the key is already present.

    let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value
    insertWithKey f 5 "xxx" (Data.IntMap.fromList [(5,"a"), (3,"b")]) == fromList ((3, "b") :| [(5, "5:xxx|a")])
    insertWithKey f 7 "xxx" (Data.IntMap.fromList [(5,"a"), (3,"b")]) == fromList ((3, "b") :| [(5, "a"), (7, "xxx")])
    insertWithKey f 5 "xxx" Data.IntMap.empty                         == singleton 5 "xxx"
    

  4. isProperSubmapOf :: Eq a => NEIntMap a -> NEIntMap a -> Bool

    nonempty-containers Data.IntMap.NonEmpty

    O(m*log(n/m + 1)), m <= n. Is this a proper submap? (ie. a submap but not equal). Defined as (isProperSubmapOf = isProperSubmapOfBy (==)).

  5. isProperSubmapOfBy :: (a -> b -> Bool) -> NEIntMap a -> NEIntMap b -> Bool

    nonempty-containers Data.IntMap.NonEmpty

    O(m*log(n/m + 1)), m <= n. Is this a proper submap? (ie. a submap but not equal). The expression (isProperSubmapOfBy f m1 m2) returns True when m1 and m2 are not equal, all keys in m1 are in m2, and when f returns True when applied to their respective values. For example, the following expressions are all True:

    isProperSubmapOfBy (==) (singleton 1 1) (fromList ((1,1) :| [(2,2)]))
    isProperSubmapOfBy (<=) (singleton 1 1) (fromList ((1,1) :| [(2,2)]))
    
    But the following are all False:
    isProperSubmapOfBy (==) (fromList ((1,1) :| [(2,2)])) (fromList ((1,1) :| [(2,2)]))
    isProperSubmapOfBy (==) (fromList ((1,1) :| [(2,2)])) (singleton 1 1))
    isProperSubmapOfBy (<)  (singleton 1 1)               (fromList ((1,1) :| [(2,2)]))
    

  6. isSubmapOf :: Eq a => NEIntMap a -> NEIntMap a -> Bool

    nonempty-containers Data.IntMap.NonEmpty

    O(m*log(n/m + 1)), m <= n. This function is defined as (isSubmapOf = isSubmapOfBy (==)).

  7. isSubmapOfBy :: (a -> b -> Bool) -> NEIntMap a -> NEIntMap b -> Bool

    nonempty-containers Data.IntMap.NonEmpty

    O(m*log(n/m + 1)), m <= n. The expression (isSubmapOfBy f t1 t2) returns True if all keys in t1 are in tree t2, and when f returns True when applied to their respective values. For example, the following expressions are all True:

    isSubmapOfBy (==) (singleton 'a' 1) (fromList (('a',1) :| [('b',2)]))
    isSubmapOfBy (<=) (singleton 'a' 1) (fromList (('a',1) :| [('b',2)]))
    isSubmapOfBy (==) (fromList (('a',1) :| [('b',2)])) (fromList (('a',1) :| [('b',2)]))
    
    But the following are all False:
    isSubmapOfBy (==) (singleton 'a' 2) (fromList (('a',1) :| [('b',2)]))
    isSubmapOfBy (<)  (singleton 'a' 1) (fromList (('a',1) :| [('b',2)]))
    isSubmapOfBy (==) (fromList (('a',1) :| [('b',2)])) (singleton 'a' 1)
    

  8. nonEmptyMap :: IntMap a -> Maybe (NEIntMap a)

    nonempty-containers Data.IntMap.NonEmpty

    O(log n). Smart constructor for an NEIntMap from a IntMap. Returns Nothing if the IntMap was originally actually empty, and Just n with an NEIntMap, if the IntMap was not empty. nonEmptyMap and maybe empty toMap form an isomorphism: they are perfect structure-preserving inverses of eachother. See IsNonEmpty for a pattern synonym that lets you "match on" the possiblity of a IntMap being an NEIntMap.

    nonEmptyMap (Data.IntMap.fromList [(3,"a"), (5,"b")]) == Just (fromList ((3,"a") :| [(5,"b")]))
    

  9. toMap :: NEIntMap a -> IntMap a

    nonempty-containers Data.IntMap.NonEmpty

    O(log n). Convert a non-empty map back into a normal possibly-empty map, for usage with functions that expect IntMap. Can be thought of as "obscuring" the non-emptiness of the map in its type. See the IsNotEmpty pattern. nonEmptyMap and maybe empty toMap form an isomorphism: they are perfect structure-preserving inverses of eachother.

    toMap (fromList ((3,"a") :| [(5,"b")])) == Data.IntMap.fromList [(3,"a"), (5,"b")]
    

  10. unsafeFromMap :: IntMap a -> NEIntMap a

    nonempty-containers Data.IntMap.NonEmpty

    O(log n). Unsafe version of nonEmptyMap. Coerces a IntMap into an NEIntMap, but is undefined (throws a runtime exception when evaluation is attempted) for an empty IntMap.

Page 956 of many | Previous | Next