packages feed

nonemptymap 0.0.1.0 → 0.0.2.0

raw patch · 3 files changed

+83/−11 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Map.NonEmpty: instance (GHC.Show.Show k, GHC.Show.Show a) => GHC.Show.Show (Data.Map.NonEmpty.NonEmptyMap k a)
+ Data.Map.NonEmpty: instance Data.Functor.Classes.Eq2 Data.Map.NonEmpty.NonEmptyMap
+ Data.Map.NonEmpty: instance Data.Functor.Classes.Ord2 Data.Map.NonEmpty.NonEmptyMap
+ Data.Map.NonEmpty: instance Data.Functor.Classes.Show2 Data.Map.NonEmpty.NonEmptyMap
+ Data.Map.NonEmpty: instance GHC.Classes.Eq k => Data.Functor.Classes.Eq1 (Data.Map.NonEmpty.NonEmptyMap k)
+ Data.Map.NonEmpty: instance GHC.Classes.Ord k => Data.Functor.Classes.Ord1 (Data.Map.NonEmpty.NonEmptyMap k)
+ Data.Map.NonEmpty: instance GHC.Show.Show k => Data.Functor.Classes.Show1 (Data.Map.NonEmpty.NonEmptyMap k)

Files

README.md view
@@ -1,4 +1,4 @@-# Data.Map.NonEmpty - NonEmptyMap [![Build Status](https://travis-ci.com/ChristopherDavenport/NonEmptyMap.svg?branch=master)](https://travis-ci.com/ChristopherDavenport/NonEmptyMap)+# Data.Map.NonEmpty - NonEmptyMap [![Build Status](https://travis-ci.com/ChristopherDavenport/nonemptymap.svg?branch=master)](https://travis-ci.com/ChristopherDavenport/nonemptymap)  This map implementation is a NonEmptyMap that can be used where that is necessary. Hopefully slowly porting over more and more functions from the containers libraries. 
nonemptymap.cabal view
@@ -1,5 +1,5 @@ name:                nonemptymap-version:             0.0.1.0+version:             0.0.2.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
src/Data/Map/NonEmpty.hs view
@@ -1,6 +1,24 @@ {-# language InstanceSigs #-} {-# language ScopedTypeVariables #-}-+{-# language Trustworthy #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  Data.Map.NonEmpty+-- Copyright   :  (c) Christopher Davenport 2018+-- License     :  BSD-style+-- Maintainer  :  Chris@ChristopherDavenport.tech+-- Portability :  portable+--+-- = Description+--+-- An efficient implementation of non-empty maps from keys to values (dictionaries).+--+-- Since many function names (but not the type name) clash with+-- "Prelude" names, this module is usually imported @qualified@, e.g.+--+-- >  import Data.Map.NonEmpty (NonEmptyMap)+-- >  import qualified Data.Map.NonEmpty as NonEmptyMap+----------------------------------------------------------------------------- module Data.Map.NonEmpty(   NonEmptyMap(..) -- Generic Constructor   -- * Construction@@ -32,14 +50,60 @@  import qualified Data.Map                   as Map import Data.Maybe                           (fromMaybe, isJust)+import Data.Functor.Classes                 (Eq1, Eq2, liftEq2, liftEq+                                            , Ord1, Ord2, liftCompare2, liftCompare+                                            , Show1, Show2, liftShowsPrec2, showsUnaryWith, liftShowsPrec, liftShowList2+                                            , Read1, liftReadsPrec, readsData, readsUnaryWith, liftReadList) import Prelude                              hiding (lookup)  --- A NonEmptyMap of keys k to values a+-- | A NonEmptyMap of keys k to values a data NonEmptyMap k a = NonEmptyMap (k, a) (Map.Map k a)  -- Instances ++{--------------------------------------------------------------------+  Eq+--------------------------------------------------------------------}+instance Eq2 NonEmptyMap where+  liftEq2 :: (k -> l -> Bool) -> (m -> n -> Bool) -> NonEmptyMap k m -> NonEmptyMap l n -> Bool+  liftEq2 eqk eqa nem nen =+    size nen == size nen && liftEq (liftEq2 eqk eqa) (toList nem) (toList nen)++instance Eq k => Eq1 (NonEmptyMap k) where+  liftEq = liftEq2 (==)++{--------------------------------------------------------------------+  Ord+--------------------------------------------------------------------}+instance Ord2 NonEmptyMap where+  liftCompare2 cmpk cmpv m n =+    liftCompare (liftCompare2 cmpk cmpv) (toList m) (toList n)++instance Ord k => Ord1 (NonEmptyMap k) where+  liftCompare = liftCompare2 compare++{--------------------------------------------------------------------+  Show+--------------------------------------------------------------------}+instance Show2 NonEmptyMap where+  liftShowsPrec2 spk slk spv slv d m =+    showsUnaryWith (liftShowsPrec sp sl) "fromList" d (toList m)+    where+      sp = liftShowsPrec2 spk slk spv slv+      sl = liftShowList2 spk slk spv slv++instance Show k => Show1 (NonEmptyMap k) where+  liftShowsPrec = liftShowsPrec2 showsPrec showList++instance (Show k, Show a) => Show (NonEmptyMap k a) where+  showsPrec d m  = showParen (d > 10) $+    showString "fromList " . shows (toList m)++{--------------------------------------------------------------------+  Functor+--------------------------------------------------------------------} instance Functor (NonEmptyMap k) where   fmap :: (a -> b) -> NonEmptyMap k a -> NonEmptyMap k b   fmap f (NonEmptyMap (k, v) map) =  NonEmptyMap (k, f v) (fmap f map)@@ -52,8 +116,9 @@ fromList []       = Nothing fromList (x : xa) = Just $ NonEmptyMap x (Map.fromList xa) --- Insertion-+{--------------------------------------------------------------------+  Insertion+--------------------------------------------------------------------} -- , insert insert :: Ord k => k -> a -> NonEmptyMap k a -> NonEmptyMap k a insert = insertWith const@@ -74,7 +139,9 @@   if k == key then (Just a, NonEmptyMap(key, f key value a) m)   else fmap (NonEmptyMap (k, a)) (Map.insertLookupWithKey f key value m) --- Deletion/Update+{--------------------------------------------------------------------+  Deletion/Update+--------------------------------------------------------------------} delete :: Ord k => k -> NonEmptyMap k a -> Map.Map k a delete key (NonEmptyMap (k, a) m) | key == k  = m delete key (NonEmptyMap (k, a) m)             = Map.insert k a (Map.delete k m)@@ -103,7 +170,9 @@     insideF Nothing   = m alterF f key (NonEmptyMap (k, a) m)            = Map.insert k a <$> Map.alterF f key m --- Query+{--------------------------------------------------------------------+  Query+--------------------------------------------------------------------}  lookup :: Ord k => k -> NonEmptyMap k a -> Maybe a lookup key (NonEmptyMap (k, a) m) | key == k = Just a@@ -121,12 +190,15 @@ notMember :: Ord k => k -> NonEmptyMap k a -> Bool notMember k nem = not $ member k nem --- Size +{--------------------------------------------------------------------+  Size+--------------------------------------------------------------------} size :: NonEmptyMap k a -> Int size (NonEmptyMap _ m) = 1 + Map.size m    --- Conversions-+{--------------------------------------------------------------------+  Conversions+--------------------------------------------------------------------}  -- Lists toList :: NonEmptyMap k a -> [(k, a)]