diff options
author | phadej <> | 2021-02-23 08:53:00 (GMT) |
---|---|---|
committer | hdiff <hdiff@hdiff.luite.com> | 2021-02-23 08:53:00 (GMT) |
commit | cdc03b1218a29292e2e3c0bd327a969da666fdd4 (patch) | |
tree | d86e9ab024cff5226eb354670d2bbfc0a0cf4bfc | |
parent | 3494977cf73701b87e2ec567d28ae506ca4e1870 (diff) |
-rw-r--r--[-rwxr-xr-x] | CHANGELOG.md | 4 | ||||
-rw-r--r--[-rwxr-xr-x] | README.md | 0 | ||||
-rw-r--r-- | insert-ordered-containers.cabal | 17 | ||||
-rw-r--r-- | src/Data/HashMap/Strict/InsOrd.hs | 39 |
4 files changed, 42 insertions, 18 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index f30d3f9..8e7a4f9 100755..100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +- 0.2.4 + - Add `indexed-traversable` instances + - lens-5 and optics-0.4 support + - 0.2.3 - Add support for indexed `optics` - Only support GHC-8.0+ diff --git a/README.md b/README.md index 22480cf..22480cf 100755..100644 --- a/README.md +++ b/README.md diff --git a/insert-ordered-containers.cabal b/insert-ordered-containers.cabal index d2e8d6c..384a04a 100644 --- a/insert-ordered-containers.cabal +++ b/insert-ordered-containers.cabal @@ -1,5 +1,5 @@ name: insert-ordered-containers -version: 0.2.3.1 +version: 0.2.4 synopsis: Associative containers retaining insertion order for traversals. @@ -18,7 +18,7 @@ license-file: LICENSE build-type: Simple cabal-version: >=1.10 tested-with: - GHC ==8.0.2 || ==8.2.2 || ==8.4.4 || ==8.6.5 || ==8.8.3 || ==8.10.1 + GHC ==8.0.2 || ==8.2.2 || ==8.4.4 || ==8.6.5 || ==8.8.4 || ==8.10.4 || ==9.0.1 extra-source-files: CHANGELOG.md @@ -33,13 +33,14 @@ library hs-source-dirs: src ghc-options: -Wall build-depends: - aeson >=1.4.2.0 && <1.5 - , base >=4.9 && <4.15 + aeson >=1.4.2.0 && <1.6 + , base >=4.9 && <4.16 , base-compat >=0.10.5 && <0.12 , hashable >=1.2.6.1 && <1.4 - , lens >=4.17 && <4.20 - , optics-core >=0.2 && <0.4 - , optics-extra >=0.2 && <0.4 + , indexed-traversable >=0.1.1 && <0.2 + , lens >=4.17 && <5.1 + , optics-core >=0.2 && <0.5 + , optics-extra >=0.2 && <0.5 , semigroupoids >=5.3.2 && <5.4 , semigroups >=0.18.5 && <0.20 , text >=1.2.3.0 && <1.3 @@ -70,7 +71,7 @@ test-suite ins-ord-containers-tests , QuickCheck >=2.13.2 && <2.15 , semigroupoids , semigroups - , tasty >=0.10.1.2 && <1.3 + , tasty >=0.10.1.2 && <1.5 , tasty-quickcheck >=0.8.3.2 && <0.11 , text , transformers diff --git a/src/Data/HashMap/Strict/InsOrd.hs b/src/Data/HashMap/Strict/InsOrd.hs index 923b8d1..b0d3e71 100644 --- a/src/Data/HashMap/Strict/InsOrd.hs +++ b/src/Data/HashMap/Strict/InsOrd.hs @@ -86,21 +86,22 @@ import Data.Aeson import qualified Data.Aeson.Encoding as E import Data.Data (Data, Typeable) import qualified Data.Foldable as F +import Data.Foldable.WithIndex (FoldableWithIndex (..)) import Data.Functor.Apply (Apply (..)) import Data.Functor.Bind (Bind (..)) +import Data.Functor.WithIndex (FunctorWithIndex (..)) import Data.Hashable (Hashable (..)) import Data.List (nub, sortBy) import Data.Maybe (fromMaybe) import Data.Ord (comparing) import Data.Semigroup (Semigroup (..)) +import Data.Traversable.WithIndex (TraversableWithIndex (..)) import Text.ParserCombinators.ReadPrec (prec) import Text.Read (Lexeme (..), Read (..), lexP, parens, readListPrecDefault) import Control.Lens - (At (..), FoldableWithIndex (..), FunctorWithIndex (..), Index, Iso, - IxValue, Ixed (..), TraversableWithIndex (..), Traversal, iso, (<&>), - _1, _2) + (At (..), Index, Iso, IxValue, Ixed (..), Traversal, _1, _2, iso, (<&>)) import Control.Monad.Trans.State.Strict (State, runState, state) import qualified Control.Lens as Lens @@ -233,6 +234,18 @@ instance (Eq k, Hashable k, FromJSONKey k, FromJSON v) => FromJSON (InsOrdHashMa parseJSON = parseJSON1 ------------------------------------------------------------------------------- +-- indexed-traversals +------------------------------------------------------------------------------- + +instance (Eq k, Hashable k) => FunctorWithIndex k (InsOrdHashMap k) where + imap = mapWithKey +instance (Eq k, Hashable k) => FoldableWithIndex k (InsOrdHashMap k) where + ifoldMap = foldMapWithKey + ifoldr = foldrWithKey +instance (Eq k, Hashable k) => TraversableWithIndex k (InsOrdHashMap k) where + itraverse = traverseWithKey + +------------------------------------------------------------------------------- -- Lens ------------------------------------------------------------------------------- @@ -262,13 +275,6 @@ instance (Eq k, Hashable k) => At (InsOrdHashMap k a) where where mv = lookup k m {-# INLINABLE at #-} -instance (Eq k, Hashable k) => FunctorWithIndex k (InsOrdHashMap k) where - imap = mapWithKey -instance (Eq k, Hashable k) => FoldableWithIndex k (InsOrdHashMap k) where - ifoldMap = foldMapWithKey -instance (Eq k, Hashable k) => TraversableWithIndex k (InsOrdHashMap k) where - itraverse = traverseWithKey - -- | This is a slight lie, as roundtrip doesn't preserve ordering. hashMap :: Iso (InsOrdHashMap k a) (InsOrdHashMap k b) (HashMap k a) (HashMap k b) hashMap = iso toHashMap fromHashMap @@ -276,6 +282,16 @@ hashMap = iso toHashMap fromHashMap unorderedTraversal :: Traversal (InsOrdHashMap k a) (InsOrdHashMap k b) a b unorderedTraversal = hashMap . traverse +#if !MIN_VERSION_lens(5,0,0) +instance (Eq k, Hashable k) => Lens.FunctorWithIndex k (InsOrdHashMap k) where + imap = mapWithKey +instance (Eq k, Hashable k) => Lens.FoldableWithIndex k (InsOrdHashMap k) where + ifoldMap = foldMapWithKey + ifoldr = foldrWithKey +instance (Eq k, Hashable k) => Lens.TraversableWithIndex k (InsOrdHashMap k) where + itraverse = traverseWithKey +#endif + ------------------------------------------------------------------------------- -- Optics ------------------------------------------------------------------------------- @@ -291,12 +307,15 @@ instance (Eq k, Hashable k) => Optics.At (InsOrdHashMap k a) where at k = Optics.lensVL $ \f m -> Lens.at k f m {-# INLINE at #-} +#if !MIN_VERSION_optics_core(0,4,0) instance (Eq k, Hashable k) => Optics.FunctorWithIndex k (InsOrdHashMap k) where imap = mapWithKey instance (Eq k, Hashable k) => Optics.FoldableWithIndex k (InsOrdHashMap k) where ifoldMap = foldMapWithKey + ifoldr = foldrWithKey instance (Eq k, Hashable k) => Optics.TraversableWithIndex k (InsOrdHashMap k) where itraverse = traverseWithKey +#endif ------------------------------------------------------------------------------- -- Construction |