packages feed

meep 0.1.1.0 → 0.1.2.0

raw patch · 3 files changed

+55/−7 lines, 3 filesdep +semigroupoidsdep ~bifunctors

Dependencies added: semigroupoids

Dependency ranges changed: bifunctors

Files

CHANGELOG.md view
@@ -1,3 +1,12 @@+0.1.2.0+=======++  * Fixed `Show` instance++  * Added `intersection*` functions++  * Added `Apply` instance+ 0.1.1.0 ======= 
meep.cabal view
@@ -1,5 +1,5 @@ name:                meep-version:             0.1.1.0+version:             0.1.2.0 synopsis:   A silly container description:@@ -22,16 +22,17 @@ source-repository this   type:     git   location: https://github.com/supki/meep-  tag:      0.1.1.0+  tag:      0.1.2.0  library   default-language:     Haskell2010   build-depends:-      base       >= 4.6 && < 5-    , bifunctors >= 4   && < 5-    , lens       >= 4   && < 5-    , semigroups >= 0.9 && < 1+      base          >= 4.6 && < 5+    , bifunctors    >= 5   && < 6+    , lens          >= 4   && < 5+    , semigroupoids >= 5   && < 6+    , semigroups    >= 0.9 && < 1   hs-source-dirs:     src   exposed-modules:@@ -49,6 +50,7 @@     , hspec-expectations-lens >= 0.3     , lens     , QuickCheck+    , semigroupoids     , semigroups   hs-source-dirs:     src
src/Data/Meep.hs view
@@ -25,6 +25,9 @@   , fromMaybe   , toMaybe   , maybeing+  , intersection+  , intersectionWith+  , intersectionWithKey   , keys   , elems   ) where@@ -34,6 +37,7 @@ import Data.Bifoldable (Bifoldable(..)) import Data.Bifunctor.Apply (Biapply(..)) import Data.Bitraversable (Bitraversable(..))+import Data.Functor.Apply (Apply(..)) import Data.Monoid (mempty) import Data.Data (Data, Typeable) import Data.Foldable (Foldable)@@ -51,7 +55,7 @@     deriving (Eq, Ord, Functor, Foldable, Traversable, Typeable, Data, Generic)  instance (Show k, Show a) => Show (Meep k a) where-  showsPrec p m = showParen (p > 10) (showString "fromMaybe " . shows (toMaybe m))+  showsPrec p m = showParen (p > 9) (showString "fromMaybe " . showsPrec 11 (toMaybe m))  -- | 'Meep's intersection instance (Eq k, Semigroup a) => Semigroup (Meep k a) where@@ -59,6 +63,9 @@   _        <> Empty      = Empty   Meep k v <> Meep k' v' = bool Empty (Meep k (v <> v')) (k == k') +instance Eq k => Apply (Meep k) where+  (<.>) = intersectionWith id+ instance Bifunctor Meep where   bimap _ _ Empty = Empty   bimap f g (Meep k v) = Meep (f k) (g v)@@ -190,6 +197,36 @@ elems :: Meep k a -> Maybe a elems Empty      = Nothing elems (Meep _ a) = Just a++-- | /O(1)/. Intersection of two 'Meep's+--+-- @+-- intersection ≡ 'intersectionWith' 'const'+-- @+intersection :: Eq k => Meep k a -> Meep k b -> Meep k a+intersection = intersectionWith const++-- | /O(1)/. Intersection of two 'Meep's with a combining function+--+-- >>> intersectionWith (+) (Meep "hello" 4) (Meep "hello" 7)+-- fromMaybe (Just ("hello",11))+--+-- >>> intersectionWith (+) (Meep "hello" 4) (Meep "bye" 7)+-- fromMaybe Nothing+--+-- >>> intersectionWith (+) Empty (Meep "hello" 7)+-- fromMaybe Nothing+--+-- @+-- intersectionWith f ≡ intersectionWithKey (const f)+-- @+intersectionWith :: Eq k => (a -> b -> c) -> Meep k a -> Meep k b -> Meep k c+intersectionWith f = intersectionWithKey (const f)++-- | /O(1)/. Intersection of two 'Meep's with a combining function+intersectionWithKey :: Eq k => (k -> a -> b -> c) -> Meep k a -> Meep k b -> Meep k c+intersectionWithKey f (Meep k a) (Meep k' b) | k == k' = Meep k (f k a b)+intersectionWithKey _ _          _                     = Empty  insert :: Eq k => k -> a -> Meep k a -> Meep k a insert k a Empty         = Meep k a