matchable 0.1.2 → 0.1.2.1
raw patch · 5 files changed
+50/−30 lines, 5 filesdep −doctestdep ~containersdep ~hashabledep ~vectorPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies removed: doctest
Dependency ranges changed: containers, hashable, vector
API changes (from Hackage documentation)
- Data.Matchable: instance (GHC.Classes.Eq k, Data.Hashable.Class.Hashable k) => Data.Matchable.Matchable (Data.HashMap.Base.HashMap k)
+ Data.Matchable: instance (GHC.Classes.Eq k, Data.Hashable.Class.Hashable k) => Data.Matchable.Matchable (Data.HashMap.Internal.HashMap k)
Files
- CHANGELOG.md +5/−0
- LICENSE +1/−1
- README.md +8/−5
- matchable.cabal +12/−11
- src/Data/Matchable.hs +24/−13
CHANGELOG.md view
@@ -1,3 +1,8 @@+# 0.1.2.1++- No changes to the library itself. The package description (.cabal file)+ changed to the standard.+ # 0.1.2 - Add Data.Bimatchable
LICENSE view
@@ -1,4 +1,4 @@-Copyright Koji Miyazato (c) 2018+Copyright Koji Miyazato (c) 2018-2019 All rights reserved.
README.md view
@@ -1,11 +1,14 @@+[](https://github.com/viercc/matchable/actions/workflows/haskell.yml)+ ## matchable -This package provides a type class `Matchable`, which represents-`zipMatch` operation which can zip two values.+This package defines a type class `Matchable`,+which provides `zipMatch` operation for zipping two values of a+container type. -`zipMatch` operation can fail, and it returns zipped value wrapped+The `zipMatch` operation can fail. It returns the zipped value wrapped in `Maybe`. Specifically, `zipMatch` returns zipped value if and only if two arguments-have exactly same shape.+have the exactly same shape. ### Example @@ -16,4 +19,4 @@ Nothing ``` -See [example](https://github.com/viercc/matchable/blob/master/example/README.md) also.+See [examples](https://github.com/viercc/matchable/blob/master/example/README.md) also.
matchable.cabal view
@@ -1,17 +1,19 @@ name: matchable-version: 0.1.2+version: 0.1.2.1 synopsis: A type class for Matchable Functors.-description: This package provides a type class @Matchable@, which represents- @zipMatch@ operation which can zip two values if these two have- exactly same shape.+description: This package defines a type class @Matchable@, providing+ @zipMatch@ operation for zipping two values of any container-like+ functor type. license: BSD3 license-file: LICENSE author: Koji Miyazato maintainer: viercc@gmail.com category: Functors build-type: Simple-extra-source-files: README.md, CHANGELOG.md-cabal-version: >=1.10+extra-source-files: README.md+extra-doc-files: CHANGELOG.md+cabal-version: 2.0+tested-with: GHC ==9.0.2, GHC ==9.2.7, GHC ==9.4.4, GHC ==9.6.1 source-repository head type: git@@ -25,17 +27,16 @@ build-depends: base >=4.10 && <5, containers >=0.5.10.2 && <0.7, tagged >=0.8 && <0.9,- hashable >=1.0.1.1 && <1.3,+ hashable >=1.0.1.1 && <1.5, unordered-containers >=0.2.6 && <0.3,- vector >=0.10.9.0 && <0.13+ vector >=0.10.9.0 && <0.14 ghc-options: -Wall default-language: Haskell2010 -test-suite examples+test-suite matchable-test type: exitcode-stdio-1.0 hs-source-dirs: test main-is: example.hs- build-depends: base, containers, matchable, hspec, doctest- ghc-options: -Wall+ build-depends: base, containers, matchable, hspec default-language: Haskell2010
src/Data/Matchable.hs view
@@ -35,6 +35,7 @@ import Data.Map.Lazy (Map) import qualified Data.Map.Lazy as Map import Data.IntMap.Lazy (IntMap)+import qualified Data.IntMap.Lazy as IntMap import qualified Data.IntMap.Merge.Lazy as IntMap import Data.Tree (Tree) import Data.Sequence (Seq)@@ -49,6 +50,11 @@ import GHC.Generics +-- $setup+-- This is required to silence "type defaults" warning, which clutters GHCi+-- output and makes doctests fail.+-- >>> :set -Wno-type-defaults+ -- | Containers that allows exact structural matching of two containers. class (Eq1 t, Functor t) => Matchable t where {- |@@ -177,19 +183,6 @@ instance (Eq e) => Matchable (Either e) where zipMatchWith = genericZipMatchWith -instance (Eq k) => Matchable (Map k) where- zipMatchWith u ma mb =- Map.fromAscList <$> zipMatchWith (zipMatchWith u) (Map.toAscList ma) (Map.toAscList mb)--instance Matchable IntMap where- zipMatchWith u =- IntMap.mergeA (IntMap.traverseMissing (\_ _ -> Nothing))- (IntMap.traverseMissing (\_ _ -> Nothing))- (IntMap.zipWithAMatched (const u))--instance Matchable Tree where- zipMatchWith = genericZipMatchWith- instance Matchable Seq where zipMatch as bs | Seq.length as == Seq.length bs = Just (Seq.zip as bs)@@ -197,6 +190,24 @@ zipMatchWith u as bs | Seq.length as == Seq.length bs = unsafeFillIn u as (Data.Foldable.toList bs) | otherwise = Nothing++instance (Eq k) => Matchable (Map k) where+ zipMatchWith u as bs+ | Map.size as == Map.size bs =+ Map.fromDistinctAscList <$>+ zipMatchWith (zipMatchWith u) (Map.toAscList as) (Map.toAscList bs)+ | otherwise = Nothing++instance Matchable IntMap where+ zipMatchWith u as bs+ | IntMap.size as == IntMap.size bs = merger as bs+ | otherwise = Nothing+ where+ miss = IntMap.traverseMissing (\_ _ -> Nothing)+ merger = IntMap.mergeA miss miss (IntMap.zipWithAMatched (const u))++instance Matchable Tree where+ zipMatchWith = genericZipMatchWith instance Matchable Vector where zipMatch as bs