packages feed

nonemptymap 0.0.2.0 → 0.0.3.0

raw patch · 2 files changed

+29/−5 lines, 2 filesdep +semigroupoidsPVP ok

version bump matches the API change (PVP)

Dependencies added: semigroupoids

API changes (from Hackage documentation)

+ Data.Map.NonEmpty: instance Data.Foldable.Foldable (Data.Map.NonEmpty.NonEmptyMap k)
+ Data.Map.NonEmpty: instance Data.Semigroup.Foldable.Class.Foldable1 (Data.Map.NonEmpty.NonEmptyMap k)

Files

nonemptymap.cabal view
@@ -1,5 +1,5 @@ name:                nonemptymap-version:             0.0.2.0+version:             0.0.3.0 synopsis:            A NonEmptyMap Implementation description:         This package intends to allow general use of a NonEmptyMap                      which is very beneficial as sometimes you want the functionality@@ -20,6 +20,7 @@   exposed-modules:     Data.Map.NonEmpty   build-depends:       base >= 4.7 && < 5                        , containers >= 0.5.8 && < 0.6+                       , semigroupoids >= 5 && < 6   default-language:    Haskell2010  source-repository head
src/Data/Map/NonEmpty.hs view
@@ -54,6 +54,11 @@                                             , Ord1, Ord2, liftCompare2, liftCompare                                             , Show1, Show2, liftShowsPrec2, showsUnaryWith, liftShowsPrec, liftShowList2                                             , Read1, liftReadsPrec, readsData, readsUnaryWith, liftReadList)+import Data.Semigroup                        (Semigroup, (<>))+import Data.Semigroup.Foldable               (Foldable1(..))+import Data.List.NonEmpty                    (NonEmpty(..))+import qualified Data.List.NonEmpty         as NonEmptyList+ import Prelude                              hiding (lookup)  @@ -108,6 +113,17 @@   fmap :: (a -> b) -> NonEmptyMap k a -> NonEmptyMap k b   fmap f (NonEmptyMap (k, v) map) =  NonEmptyMap (k, f v) (fmap f map) +{--------------------------------------------------------------------+  Foldable+--------------------------------------------------------------------}+instance Foldable (NonEmptyMap k) where+  foldr :: (a -> b -> b) -> b -> NonEmptyMap k a -> b+  foldr f b (NonEmptyMap (k, a) m) = Map.foldr f (f a b) m++instance Foldable1 (NonEmptyMap k) where+  foldMap1 :: Semigroup m => (a -> m) -> NonEmptyMap k a -> m+  foldMap1 f (NonEmptyMap (k, a) m) = Map.foldr ((<>) . f) (f a) m+   -- Construction singleton :: (k, a) -> NonEmptyMap k a singleton tup = NonEmptyMap tup Map.empty@@ -116,24 +132,25 @@ fromList []       = Nothing fromList (x : xa) = Just $ NonEmptyMap x (Map.fromList xa) +fromNonEmpty :: Ord k => NonEmpty (k, a) -> NonEmptyMap k a+fromNonEmpty nel = NonEmptyMap (NonEmptyList.head nel) (Map.fromList (NonEmptyList.tail nel))+ {--------------------------------------------------------------------   Insertion --------------------------------------------------------------------}--- , insert+ insert :: Ord k => k -> a -> NonEmptyMap k a -> NonEmptyMap k a insert = insertWith const --- , insertWith insertWith :: Ord k => (a -> a -> a) -> k -> a -> NonEmptyMap k a -> NonEmptyMap k a insertWith f key value (NonEmptyMap (k, a) m) | key == k  = NonEmptyMap (key, f value a) m insertWith f key value (NonEmptyMap (k, a) m)             = NonEmptyMap (k, a) (Map.insertWith f key value m)--- , insertWithKey+ insertWithKey :: Ord k => (k -> a -> a -> a) -> k -> a -> NonEmptyMap k a -> NonEmptyMap k a insertWithKey f key value (NonEmptyMap (k, a) m) =    if k == key then NonEmptyMap (key, f key value a) m   else NonEmptyMap (k, a) (Map.insertWithKey f key value m) ---  insertLookupWithKey insertLookupWithKey :: Ord k => (k -> a -> a -> a) -> k -> a -> NonEmptyMap k a -> (Maybe a, NonEmptyMap k a) insertLookupWithKey f key value (NonEmptyMap (k, a) m) =    if k == key then (Just a, NonEmptyMap(key, f key value a) m)@@ -203,3 +220,9 @@ -- Lists toList :: NonEmptyMap k a -> [(k, a)] toList (NonEmptyMap tup m) = tup : Map.toList m++toNonEmpty :: NonEmptyMap k a -> NonEmpty (k, a)+toNonEmpty (NonEmptyMap tup m) = tup :| Map.toList m++toMap :: Ord k => NonEmptyMap k a -> Map.Map k a+toMap (NonEmptyMap (k, a) m) = Map.insert k a m