strict-non-empty-containers-2020.12.8: Strict non-empty container types
Copyright © 2018-2020 IOHK
License Apache-2.0
Safe Haskell Safe-Inferred
Language Haskell2010

Data.Map.Strict.NonEmptyMap

Description

Provides a strict implementation of a non-empty map.

This implementation is based on the implementation of Strict provided by the containers package, but provides an extra guarantee that the map contains at least one entry at all times.

Synopsis

Map type

data NonEmptyMap k v Source #

A non-empty map from keys of type k to values of type v .

Instances

Instances details
Functor ( NonEmptyMap k) Source #
Instance details

Defined in Data.Map.Strict.NonEmptyMap.Internal

Foldable ( NonEmptyMap k) Source #
Instance details

Defined in Data.Map.Strict.NonEmptyMap.Internal

Traversable ( NonEmptyMap k) Source #
Instance details

Defined in Data.Map.Strict.NonEmptyMap.Internal

( Eq k, Eq v) => Eq ( NonEmptyMap k v) Source #
Instance details

Defined in Data.Map.Strict.NonEmptyMap.Internal

( Read k, Read v, Ord k) => Read ( NonEmptyMap k v) Source #
Instance details

Defined in Data.Map.Strict.NonEmptyMap.Internal

( Show k, Show v) => Show ( NonEmptyMap k v) Source #
Instance details

Defined in Data.Map.Strict.NonEmptyMap.Internal

Generic ( NonEmptyMap k v) Source #
Instance details

Defined in Data.Map.Strict.NonEmptyMap.Internal

Associated Types

type Rep ( NonEmptyMap k v) :: Type -> Type Source #

( NFData k, NFData v) => NFData ( NonEmptyMap k v) Source #
Instance details

Defined in Data.Map.Strict.NonEmptyMap.Internal

( Hashable k, Hashable v) => Hashable ( NonEmptyMap k v) Source #
Instance details

Defined in Data.Map.Strict.NonEmptyMap.Internal

type Rep ( NonEmptyMap k v) Source #
Instance details

Defined in Data.Map.Strict.NonEmptyMap.Internal

type Rep ( NonEmptyMap k v) = D1 (' MetaData "NonEmptyMap" "Data.Map.Strict.NonEmptyMap.Internal" "strict-non-empty-containers-2020.12.8-EzSwiBLeHy9D9DK6mxAncD" ' False ) ( C1 (' MetaCons "NonEmptyMap" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "least") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 (k, v)) :*: S1 (' MetaSel (' Just "rest") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 ( Map k v))))

Construction

fromList :: Ord k => NonEmpty (k, v) -> NonEmptyMap k v Source #

Builds a non-empty map from a list of key-value pairs.

If the list contains more than one value for the same key, the last value for the key is retained.

fromMap :: Map k v -> Maybe ( NonEmptyMap k v) Source #

Builds a non-empty map from the given map.

If the given map is empty, this function returns Nothing .

singleton :: Ord k => k -> v -> NonEmptyMap k v Source #

Creates a map with a single element.

Deconstruction

toList :: NonEmptyMap k v -> NonEmpty (k, v) Source #

Converts a non-empty map to a list of key-value pairs.

toMap :: Ord k => NonEmptyMap k v -> Map k v Source #

Converts a non-empty map to an ordinary map.

Insertion

insert :: Ord k => k -> v -> NonEmptyMap k v -> NonEmptyMap k v Source #

Inserts a new key and value in the map.

If the key is already present in the map, the associated value is replaced with the supplied value.

Deletion

delete :: Ord k => k -> NonEmptyMap k a -> Maybe ( NonEmptyMap k a) Source #

Deletes a key and its value from the map.

When the key is not a member of the map, the original map is returned.

This function returns Nothing if the delete operation reduces the number of elements to zero.

Lookup

lookup :: Ord k => k -> NonEmptyMap k v -> Maybe v Source #

Looks up the value of a key in the map.

This function will return the corresponding value as '(Just value)', or Nothing if the key isn't in the map.

Combination

unionWith :: Ord k => (v -> v -> v) -> NonEmptyMap k v -> NonEmptyMap k v -> NonEmptyMap k v Source #

Finds the union of two maps, with the given combining function.