mirror of
https://github.com/ilyakooo0/monoidal-containers.git
synced 2024-10-05 16:47:24 +03:00
Split lens instances into a separate package
This commit is contained in:
parent
64c44462f8
commit
c81e80f54d
55
.travis.yml
55
.travis.yml
@ -1,6 +1,6 @@
|
||||
# This Travis job script has been generated by a script via
|
||||
#
|
||||
# haskell-ci 'monoidal-containers.cabal' '-o' '.travis.yml'
|
||||
# haskell-ci 'cabal.project' '-o' '.travis.yml'
|
||||
#
|
||||
# To regenerate the script (for example after adjusting tested-with) run
|
||||
#
|
||||
@ -8,12 +8,12 @@
|
||||
#
|
||||
# For more information, see https://github.com/haskell-CI/haskell-ci
|
||||
#
|
||||
# version: 0.10.3
|
||||
# version: 0.13.20210827
|
||||
#
|
||||
version: ~> 1.0
|
||||
language: c
|
||||
os: linux
|
||||
dist: xenial
|
||||
dist: bionic
|
||||
git:
|
||||
# whether to recursively clone submodules
|
||||
submodules: false
|
||||
@ -34,25 +34,25 @@ before_cache:
|
||||
jobs:
|
||||
include:
|
||||
- compiler: ghc-8.10.2
|
||||
addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.10.2","cabal-install-3.2"]}}
|
||||
addons: {"apt":{"packages":["ghc-8.10.2","cabal-install-3.4"],"sources":[{"key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286","sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu bionic main"}]}}
|
||||
os: linux
|
||||
- compiler: ghc-8.8.4
|
||||
addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.8.4","cabal-install-3.2"]}}
|
||||
addons: {"apt":{"packages":["ghc-8.8.4","cabal-install-3.4"],"sources":[{"key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286","sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu bionic main"}]}}
|
||||
os: linux
|
||||
- compiler: ghc-8.6.5
|
||||
addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.6.5","cabal-install-3.2"]}}
|
||||
addons: {"apt":{"packages":["ghc-8.6.5","cabal-install-3.4"],"sources":[{"key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286","sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu bionic main"}]}}
|
||||
os: linux
|
||||
- compiler: ghc-8.4.3
|
||||
addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.4.3","cabal-install-3.2"]}}
|
||||
addons: {"apt":{"packages":["ghc-8.4.3","cabal-install-3.4"],"sources":[{"key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286","sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu bionic main"}]}}
|
||||
os: linux
|
||||
- compiler: ghc-8.2.2
|
||||
addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.2.2","cabal-install-3.2"]}}
|
||||
addons: {"apt":{"packages":["ghc-8.2.2","cabal-install-3.4"],"sources":[{"key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286","sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu bionic main"}]}}
|
||||
os: linux
|
||||
- compiler: ghc-8.0.2
|
||||
addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.0.2","cabal-install-3.2"]}}
|
||||
addons: {"apt":{"packages":["ghc-8.0.2","cabal-install-3.4"],"sources":[{"key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286","sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu bionic main"}]}}
|
||||
os: linux
|
||||
- compiler: ghc-7.8.4
|
||||
addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-7.8.4","cabal-install-3.2"]}}
|
||||
addons: {"apt":{"packages":["ghc-7.8.4","cabal-install-3.4"],"sources":[{"key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286","sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu bionic main"}]}}
|
||||
os: linux
|
||||
before_install:
|
||||
- HC=$(echo "/opt/$CC/bin/ghc" | sed 's/-/\//')
|
||||
@ -75,7 +75,7 @@ before_install:
|
||||
- |
|
||||
echo "verbose: normal +nowrap +markoutput" >> $CABALHOME/config
|
||||
echo "remote-build-reporting: anonymous" >> $CABALHOME/config
|
||||
echo "write-ghc-environment-files: always" >> $CABALHOME/config
|
||||
echo "write-ghc-environment-files: never" >> $CABALHOME/config
|
||||
echo "remote-repo-cache: $CABALHOME/packages" >> $CABALHOME/config
|
||||
echo "logs-dir: $CABALHOME/logs" >> $CABALHOME/config
|
||||
echo "world-file: $CABALHOME/world" >> $CABALHOME/config
|
||||
@ -101,14 +101,18 @@ install:
|
||||
- rm -rf cabal.project cabal.project.local cabal.project.freeze
|
||||
- touch cabal.project
|
||||
- |
|
||||
echo "packages: ." >> cabal.project
|
||||
- if [ $HCNUMVER -ge 80200 ] ; then echo 'package monoidal-containers' >> cabal.project ; fi
|
||||
- "if [ $HCNUMVER -ge 80200 ] ; then echo ' ghc-options: -Werror=missing-methods' >> cabal.project ; fi"
|
||||
- |
|
||||
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | (grep -vE -- '^(monoidal-containers)$' || true) | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
|
||||
echo "packages: monoidal-containers" >> cabal.project
|
||||
echo "packages: monoidal-containers-lens" >> cabal.project
|
||||
- if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo 'package monoidal-containers' >> cabal.project ; fi
|
||||
- "if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo ' ghc-options: -Werror=missing-methods' >> cabal.project ; fi"
|
||||
- if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo 'package monoidal-containers-lens' >> cabal.project ; fi
|
||||
- "if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo ' ghc-options: -Werror=missing-methods' >> cabal.project ; fi"
|
||||
- ""
|
||||
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | (grep -vE -- '^(monoidal-containers|monoidal-containers-lens)$' || true) | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
|
||||
- cat cabal.project || true
|
||||
- cat cabal.project.local || true
|
||||
- if [ -f "./configure.ac" ]; then (cd "." && autoreconf -i); fi
|
||||
- if [ -f "monoidal-containers/configure.ac" ]; then (cd "monoidal-containers" && autoreconf -i); fi
|
||||
- if [ -f "monoidal-containers-lens/configure.ac" ]; then (cd "monoidal-containers-lens" && autoreconf -i); fi
|
||||
- ${CABAL} v2-freeze $WITHCOMPILER ${TEST} ${BENCH}
|
||||
- "cat cabal.project.freeze | sed -E 's/^(constraints: *| *)//' | sed 's/any.//'"
|
||||
- rm cabal.project.freeze
|
||||
@ -124,15 +128,19 @@ script:
|
||||
- find . -maxdepth 1 -type f -name '*.tar.gz' -exec tar -xvf '{}' \;
|
||||
- find . -maxdepth 1 -type f -name '*.tar.gz' -exec rm '{}' \;
|
||||
- PKGDIR_monoidal_containers="$(find . -maxdepth 1 -type d -regex '.*/monoidal-containers-[0-9.]*')"
|
||||
- PKGDIR_monoidal_containers_lens="$(find . -maxdepth 1 -type d -regex '.*/monoidal-containers-lens-[0-9.]*')"
|
||||
# Generate cabal.project
|
||||
- rm -rf cabal.project cabal.project.local cabal.project.freeze
|
||||
- touch cabal.project
|
||||
- |
|
||||
echo "packages: ${PKGDIR_monoidal_containers}" >> cabal.project
|
||||
- if [ $HCNUMVER -ge 80200 ] ; then echo 'package monoidal-containers' >> cabal.project ; fi
|
||||
- "if [ $HCNUMVER -ge 80200 ] ; then echo ' ghc-options: -Werror=missing-methods' >> cabal.project ; fi"
|
||||
- |
|
||||
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | (grep -vE -- '^(monoidal-containers)$' || true) | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
|
||||
echo "packages: ${PKGDIR_monoidal_containers_lens}" >> cabal.project
|
||||
- if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo 'package monoidal-containers' >> cabal.project ; fi
|
||||
- "if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo ' ghc-options: -Werror=missing-methods' >> cabal.project ; fi"
|
||||
- if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo 'package monoidal-containers-lens' >> cabal.project ; fi
|
||||
- "if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo ' ghc-options: -Werror=missing-methods' >> cabal.project ; fi"
|
||||
- ""
|
||||
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | (grep -vE -- '^(monoidal-containers|monoidal-containers-lens)$' || true) | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
|
||||
- cat cabal.project || true
|
||||
- cat cabal.project.local || true
|
||||
# Building...
|
||||
@ -140,14 +148,15 @@ script:
|
||||
- ${CABAL} v2-build $WITHCOMPILER --disable-tests --disable-benchmarks all
|
||||
# Building with tests and benchmarks...
|
||||
# build & run tests, build benchmarks
|
||||
- ${CABAL} v2-build $WITHCOMPILER ${TEST} ${BENCH} all
|
||||
- ${CABAL} v2-build $WITHCOMPILER ${TEST} ${BENCH} all --write-ghc-environment-files=always
|
||||
# cabal check...
|
||||
- (cd ${PKGDIR_monoidal_containers} && ${CABAL} -vnormal check)
|
||||
- (cd ${PKGDIR_monoidal_containers_lens} && ${CABAL} -vnormal check)
|
||||
# haddock...
|
||||
- ${CABAL} v2-haddock $WITHCOMPILER --with-haddock $HADDOCK ${TEST} ${BENCH} all
|
||||
# Building without installed constraints for packages in global-db...
|
||||
- rm -f cabal.project.local
|
||||
- ${CABAL} v2-build $WITHCOMPILER --disable-tests --disable-benchmarks all
|
||||
|
||||
# REGENDATA ("0.10.3",["monoidal-containers.cabal","-o",".travis.yml"])
|
||||
# REGENDATA ("0.13.20210827",["cabal.project","-o",".travis.yml"])
|
||||
# EOF
|
||||
|
3
cabal.project
Normal file
3
cabal.project
Normal file
@ -0,0 +1,3 @@
|
||||
packages:
|
||||
monoidal-containers/
|
||||
monoidal-containers-lens/
|
1
monoidal-containers-lens/Changelog.md
Normal file
1
monoidal-containers-lens/Changelog.md
Normal file
@ -0,0 +1 @@
|
||||
# Monoidal containers lens
|
14
monoidal-containers-lens/default.nix
Normal file
14
monoidal-containers-lens/default.nix
Normal file
@ -0,0 +1,14 @@
|
||||
{ mkDerivation, base, containers, hashable, lens
|
||||
, stdenv, unordered-containers, monoidal-containers
|
||||
}:
|
||||
mkDerivation {
|
||||
pname = "monoidal-containers-lens";
|
||||
version = "0.6";
|
||||
src = ./.;
|
||||
libraryHaskellDepends = [
|
||||
base containers hashable lens unordered-containers monoidal-containers
|
||||
];
|
||||
homepage = "http://github.com/bgamari/monoidal-containers";
|
||||
description = "Lens instances for monoidal-containers";
|
||||
license = stdenv.lib.licenses.bsd3;
|
||||
}
|
41
monoidal-containers-lens/monoidal-containers-lens.cabal
Normal file
41
monoidal-containers-lens/monoidal-containers-lens.cabal
Normal file
@ -0,0 +1,41 @@
|
||||
name: monoidal-containers-lens
|
||||
version: 0.6.0.1
|
||||
synopsis: Lens instances for containers with monoidal accumulation
|
||||
description:
|
||||
'lens' instances for 'monoidal-containers'
|
||||
homepage: http://github.com/bgamari/monoidal-containers
|
||||
license: BSD3
|
||||
license-file: LICENSE
|
||||
author: Ben Gamari
|
||||
maintainer: ben@smart-cactus.org
|
||||
copyright: (c) 2014 Ben Gamari
|
||||
category: Data
|
||||
build-type: Simple
|
||||
cabal-version: >=1.10
|
||||
extra-source-files: Changelog.md
|
||||
tested-with: GHC ==7.8.4, GHC ==8.0.2, GHC ==8.2.2, GHC ==8.4.3, GHC ==8.6.5, GHC ==8.8.4, GHC ==8.10.2
|
||||
|
||||
source-repository head
|
||||
type: git
|
||||
location: git://github.com/bgamari/monoidal-containers
|
||||
|
||||
library
|
||||
exposed-modules: Data.Map.Monoidal.Strict.Lens
|
||||
Data.Map.Monoidal.Lens
|
||||
Data.IntMap.Monoidal.Strict.Lens
|
||||
Data.IntMap.Monoidal.Lens
|
||||
Data.HashMap.Monoidal.Lens
|
||||
default-extensions: MultiParamTypeClasses,
|
||||
GeneralizedNewtypeDeriving,
|
||||
DeriveTraversable,
|
||||
DeriveDataTypeable,
|
||||
TypeFamilies,
|
||||
FlexibleInstances
|
||||
build-depends: base >=4.7 && <4.16,
|
||||
containers >=0.5 && <0.7,
|
||||
unordered-containers >= 0.2 && < 0.3,
|
||||
hashable >= 1.2 && < 1.4,
|
||||
lens >=4.4 && <5,
|
||||
monoidal-containers
|
||||
hs-source-dirs: src
|
||||
default-language: Haskell2010
|
38
monoidal-containers-lens/src/Data/HashMap/Monoidal/Lens.hs
Normal file
38
monoidal-containers-lens/src/Data/HashMap/Monoidal/Lens.hs
Normal file
@ -0,0 +1,38 @@
|
||||
module Data.HashMap.Monoidal.Lens () where
|
||||
|
||||
import Control.Lens
|
||||
import Data.HashMap.Monoidal
|
||||
import qualified Data.HashMap.Strict as M
|
||||
import Data.Hashable (Hashable)
|
||||
|
||||
type instance Index (MonoidalHashMap k a) = k
|
||||
type instance IxValue (MonoidalHashMap k a) = a
|
||||
instance (Eq k, Hashable k) => Ixed (MonoidalHashMap k a) where
|
||||
ix k f (MonoidalHashMap m) = case M.lookup k m of
|
||||
Just v -> f v <&> \v' -> MonoidalHashMap (M.insert k v' m)
|
||||
Nothing -> pure (MonoidalHashMap m)
|
||||
{-# INLINE ix #-}
|
||||
|
||||
instance (Eq k, Hashable k) => At (MonoidalHashMap k a) where
|
||||
at k f (MonoidalHashMap m) = f mv <&> \r -> case r of
|
||||
Nothing -> maybe (MonoidalHashMap m) (const (MonoidalHashMap $ M.delete k m)) mv
|
||||
Just v' -> MonoidalHashMap $ M.insert k v' m
|
||||
where mv = M.lookup k m
|
||||
{-# INLINE at #-}
|
||||
|
||||
instance Each (MonoidalHashMap k a) (MonoidalHashMap k b) a b
|
||||
|
||||
instance (Eq k, Hashable k) => FunctorWithIndex k (MonoidalHashMap k)
|
||||
instance (Eq k, Hashable k) => FoldableWithIndex k (MonoidalHashMap k)
|
||||
instance (Eq k, Hashable k) => TraversableWithIndex k (MonoidalHashMap k) where
|
||||
itraverse f (MonoidalHashMap m) = fmap MonoidalHashMap $ itraverse f m
|
||||
{-# INLINE itraverse #-}
|
||||
|
||||
instance AsEmpty (MonoidalHashMap k a) where
|
||||
_Empty = nearly (MonoidalHashMap M.empty) (M.null . getMonoidalHashMap)
|
||||
{-# INLINE _Empty #-}
|
||||
|
||||
instance Wrapped (MonoidalHashMap k a) where
|
||||
type Unwrapped (MonoidalHashMap k a) = M.HashMap k a
|
||||
_Wrapped' = iso getMonoidalHashMap MonoidalHashMap
|
||||
{-# INLINE _Wrapped' #-}
|
44
monoidal-containers-lens/src/Data/IntMap/Monoidal/Lens.hs
Normal file
44
monoidal-containers-lens/src/Data/IntMap/Monoidal/Lens.hs
Normal file
@ -0,0 +1,44 @@
|
||||
module Data.IntMap.Monoidal.Lens () where
|
||||
|
||||
import Control.Lens
|
||||
import Data.IntMap.Monoidal
|
||||
import qualified Data.IntMap as M
|
||||
|
||||
type instance Index (MonoidalIntMap a) = Int
|
||||
type instance IxValue (MonoidalIntMap a) = a
|
||||
instance Ixed (MonoidalIntMap a) where
|
||||
ix k f (MonoidalIntMap m) = case M.lookup k m of
|
||||
Just v -> f v <&> \v' -> MonoidalIntMap (M.insert k v' m)
|
||||
Nothing -> pure (MonoidalIntMap m)
|
||||
{-# INLINE ix #-}
|
||||
|
||||
instance At (MonoidalIntMap a) where
|
||||
at k f (MonoidalIntMap m) = f mv <&> \r -> case r of
|
||||
Nothing -> maybe (MonoidalIntMap m) (const (MonoidalIntMap $ M.delete k m)) mv
|
||||
Just v' -> MonoidalIntMap $ M.insert k v' m
|
||||
where mv = M.lookup k m
|
||||
{-# INLINE at #-}
|
||||
|
||||
instance Each (MonoidalIntMap a) (MonoidalIntMap b) a b
|
||||
|
||||
instance FunctorWithIndex Int MonoidalIntMap
|
||||
instance FoldableWithIndex Int MonoidalIntMap
|
||||
instance TraversableWithIndex Int MonoidalIntMap where
|
||||
itraverse f (MonoidalIntMap m) = fmap MonoidalIntMap $ itraverse f m
|
||||
{-# INLINE itraverse #-}
|
||||
|
||||
instance TraverseMin Int MonoidalIntMap where
|
||||
traverseMin f (MonoidalIntMap m) = fmap MonoidalIntMap $ traverseMin f m
|
||||
{-# INLINE traverseMin #-}
|
||||
instance TraverseMax Int MonoidalIntMap where
|
||||
traverseMax f (MonoidalIntMap m) = fmap MonoidalIntMap $ traverseMax f m
|
||||
{-# INLINE traverseMax #-}
|
||||
|
||||
instance AsEmpty (MonoidalIntMap a) where
|
||||
_Empty = nearly (MonoidalIntMap M.empty) (M.null . getMonoidalIntMap)
|
||||
{-# INLINE _Empty #-}
|
||||
|
||||
instance Wrapped (MonoidalIntMap a) where
|
||||
type Unwrapped (MonoidalIntMap a) = M.IntMap a
|
||||
_Wrapped' = iso getMonoidalIntMap MonoidalIntMap
|
||||
{-# INLINE _Wrapped' #-}
|
@ -0,0 +1,44 @@
|
||||
module Data.IntMap.Monoidal.Strict.Lens () where
|
||||
|
||||
import Control.Lens
|
||||
import Data.IntMap.Monoidal.Strict
|
||||
import qualified Data.IntMap.Strict as M
|
||||
|
||||
type instance Index (MonoidalIntMap a) = Int
|
||||
type instance IxValue (MonoidalIntMap a) = a
|
||||
instance Ixed (MonoidalIntMap a) where
|
||||
ix k f (MonoidalIntMap m) = case M.lookup k m of
|
||||
Just v -> f v <&> \v' -> MonoidalIntMap (M.insert k v' m)
|
||||
Nothing -> pure (MonoidalIntMap m)
|
||||
{-# INLINE ix #-}
|
||||
|
||||
instance At (MonoidalIntMap a) where
|
||||
at k f (MonoidalIntMap m) = f mv <&> \r -> case r of
|
||||
Nothing -> maybe (MonoidalIntMap m) (const (MonoidalIntMap $ M.delete k m)) mv
|
||||
Just v' -> MonoidalIntMap $ M.insert k v' m
|
||||
where mv = M.lookup k m
|
||||
{-# INLINE at #-}
|
||||
|
||||
instance Each (MonoidalIntMap a) (MonoidalIntMap b) a b
|
||||
|
||||
instance FunctorWithIndex Int MonoidalIntMap
|
||||
instance FoldableWithIndex Int MonoidalIntMap
|
||||
instance TraversableWithIndex Int MonoidalIntMap where
|
||||
itraverse f (MonoidalIntMap m) = fmap MonoidalIntMap $ itraverse f m
|
||||
{-# INLINE itraverse #-}
|
||||
|
||||
instance TraverseMin Int MonoidalIntMap where
|
||||
traverseMin f (MonoidalIntMap m) = fmap MonoidalIntMap $ traverseMin f m
|
||||
{-# INLINE traverseMin #-}
|
||||
instance TraverseMax Int MonoidalIntMap where
|
||||
traverseMax f (MonoidalIntMap m) = fmap MonoidalIntMap $ traverseMax f m
|
||||
{-# INLINE traverseMax #-}
|
||||
|
||||
instance AsEmpty (MonoidalIntMap a) where
|
||||
_Empty = nearly (MonoidalIntMap M.empty) (M.null . getMonoidalIntMap)
|
||||
{-# INLINE _Empty #-}
|
||||
|
||||
instance Wrapped (MonoidalIntMap a) where
|
||||
type Unwrapped (MonoidalIntMap a) = M.IntMap a
|
||||
_Wrapped' = iso getMonoidalIntMap MonoidalIntMap
|
||||
{-# INLINE _Wrapped' #-}
|
44
monoidal-containers-lens/src/Data/Map/Monoidal/Lens.hs
Normal file
44
monoidal-containers-lens/src/Data/Map/Monoidal/Lens.hs
Normal file
@ -0,0 +1,44 @@
|
||||
module Data.Map.Monoidal.Lens () where
|
||||
|
||||
import Control.Lens
|
||||
import Data.Map.Monoidal
|
||||
import qualified Data.Map as M
|
||||
|
||||
type instance Index (MonoidalMap k a) = k
|
||||
type instance IxValue (MonoidalMap k a) = a
|
||||
instance Ord k => Ixed (MonoidalMap k a) where
|
||||
ix k f (MonoidalMap m) = case M.lookup k m of
|
||||
Just v -> f v <&> \v' -> MonoidalMap (M.insert k v' m)
|
||||
Nothing -> pure (MonoidalMap m)
|
||||
{-# INLINE ix #-}
|
||||
|
||||
instance Ord k => At (MonoidalMap k a) where
|
||||
at k f (MonoidalMap m) = f mv <&> \r -> case r of
|
||||
Nothing -> maybe (MonoidalMap m) (const (MonoidalMap $ M.delete k m)) mv
|
||||
Just v' -> MonoidalMap $ M.insert k v' m
|
||||
where mv = M.lookup k m
|
||||
{-# INLINE at #-}
|
||||
|
||||
instance Each (MonoidalMap k a) (MonoidalMap k b) a b
|
||||
|
||||
instance FunctorWithIndex k (MonoidalMap k)
|
||||
instance FoldableWithIndex k (MonoidalMap k)
|
||||
instance TraversableWithIndex k (MonoidalMap k) where
|
||||
itraverse f (MonoidalMap m) = fmap MonoidalMap $ itraverse f m
|
||||
{-# INLINE itraverse #-}
|
||||
|
||||
instance Ord k => TraverseMin k (MonoidalMap k) where
|
||||
traverseMin f (MonoidalMap m) = fmap MonoidalMap $ traverseMin f m
|
||||
{-# INLINE traverseMin #-}
|
||||
instance Ord k => TraverseMax k (MonoidalMap k) where
|
||||
traverseMax f (MonoidalMap m) = fmap MonoidalMap $ traverseMax f m
|
||||
{-# INLINE traverseMax #-}
|
||||
|
||||
instance AsEmpty (MonoidalMap k a) where
|
||||
_Empty = nearly (MonoidalMap M.empty) (M.null . getMonoidalMap)
|
||||
{-# INLINE _Empty #-}
|
||||
|
||||
instance Wrapped (MonoidalMap k a) where
|
||||
type Unwrapped (MonoidalMap k a) = M.Map k a
|
||||
_Wrapped' = iso getMonoidalMap MonoidalMap
|
||||
{-# INLINE _Wrapped' #-}
|
@ -0,0 +1,45 @@
|
||||
module Data.Map.Monoidal.Strict.Lens () where
|
||||
|
||||
import Control.Lens
|
||||
import Data.Map.Monoidal.Strict
|
||||
import qualified Data.Map.Strict as M
|
||||
|
||||
type instance Index (MonoidalMap k a) = k
|
||||
type instance IxValue (MonoidalMap k a) = a
|
||||
instance Ord k => Ixed (MonoidalMap k a) where
|
||||
ix k f (MonoidalMap m) = case M.lookup k m of
|
||||
Just v -> f v <&> \v' -> MonoidalMap (M.insert k v' m)
|
||||
Nothing -> pure (MonoidalMap m)
|
||||
{-# INLINE ix #-}
|
||||
|
||||
instance Ord k => At (MonoidalMap k a) where
|
||||
at k f (MonoidalMap m) = f mv <&> \r -> case r of
|
||||
Nothing -> maybe (MonoidalMap m) (const (MonoidalMap $ M.delete k m)) mv
|
||||
Just v' -> MonoidalMap $ M.insert k v' m
|
||||
where mv = M.lookup k m
|
||||
{-# INLINE at #-}
|
||||
|
||||
instance Each (MonoidalMap k a) (MonoidalMap k b) a b
|
||||
|
||||
instance FunctorWithIndex k (MonoidalMap k)
|
||||
instance FoldableWithIndex k (MonoidalMap k)
|
||||
instance TraversableWithIndex k (MonoidalMap k) where
|
||||
itraverse f (MonoidalMap m) = fmap MonoidalMap $ itraverse f m
|
||||
{-# INLINE itraverse #-}
|
||||
|
||||
instance Ord k => TraverseMin k (MonoidalMap k) where
|
||||
traverseMin f (MonoidalMap m) = fmap MonoidalMap $ traverseMin f m
|
||||
{-# INLINE traverseMin #-}
|
||||
instance Ord k => TraverseMax k (MonoidalMap k) where
|
||||
traverseMax f (MonoidalMap m) = fmap MonoidalMap $ traverseMax f m
|
||||
{-# INLINE traverseMax #-}
|
||||
|
||||
instance AsEmpty (MonoidalMap k a) where
|
||||
_Empty = nearly (MonoidalMap M.empty) (M.null . getMonoidalMap)
|
||||
{-# INLINE _Empty #-}
|
||||
|
||||
instance Wrapped (MonoidalMap k a) where
|
||||
type Unwrapped (MonoidalMap k a) = M.Map k a
|
||||
_Wrapped' = iso getMonoidalMap MonoidalMap
|
||||
{-# INLINE _Wrapped' #-}
|
||||
|
30
monoidal-containers/LICENSE
Normal file
30
monoidal-containers/LICENSE
Normal file
@ -0,0 +1,30 @@
|
||||
Copyright (c) 2015, Ben Gamari
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
|
||||
* Neither the name of Ben Gamari nor the names of other
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@ -52,7 +52,6 @@ library
|
||||
deepseq >=1.3 && <1.5,
|
||||
unordered-containers >= 0.2 && < 0.3,
|
||||
hashable >= 1.2 && < 1.4,
|
||||
lens >=4.4 && <5,
|
||||
newtype >=0.2 && <0.3,
|
||||
semigroups >= 0.18 && < 0.20
|
||||
|
@ -57,7 +57,6 @@ import Data.Hashable (Hashable)
|
||||
#if MIN_VERSION_unordered_containers(0,2,8)
|
||||
import Data.Hashable.Lifted (Hashable1)
|
||||
#endif
|
||||
import Control.Lens
|
||||
import Control.Newtype
|
||||
import Data.Align
|
||||
#ifdef MIN_VERSION_semialign
|
||||
@ -85,38 +84,6 @@ newtype MonoidalHashMap k a = MonoidalHashMap { getMonoidalHashMap :: M.HashMap
|
||||
#endif
|
||||
)
|
||||
|
||||
type instance Index (MonoidalHashMap k a) = k
|
||||
type instance IxValue (MonoidalHashMap k a) = a
|
||||
instance (Eq k, Hashable k) => Ixed (MonoidalHashMap k a) where
|
||||
ix k f (MonoidalHashMap m) = case M.lookup k m of
|
||||
Just v -> f v <&> \v' -> MonoidalHashMap (M.insert k v' m)
|
||||
Nothing -> pure (MonoidalHashMap m)
|
||||
{-# INLINE ix #-}
|
||||
|
||||
instance (Eq k, Hashable k) => At (MonoidalHashMap k a) where
|
||||
at k f (MonoidalHashMap m) = f mv <&> \r -> case r of
|
||||
Nothing -> maybe (MonoidalHashMap m) (const (MonoidalHashMap $ M.delete k m)) mv
|
||||
Just v' -> MonoidalHashMap $ M.insert k v' m
|
||||
where mv = M.lookup k m
|
||||
{-# INLINE at #-}
|
||||
|
||||
instance Each (MonoidalHashMap k a) (MonoidalHashMap k b) a b
|
||||
|
||||
instance (Eq k, Hashable k) => FunctorWithIndex k (MonoidalHashMap k)
|
||||
instance (Eq k, Hashable k) => FoldableWithIndex k (MonoidalHashMap k)
|
||||
instance (Eq k, Hashable k) => TraversableWithIndex k (MonoidalHashMap k) where
|
||||
itraverse f (MonoidalHashMap m) = fmap MonoidalHashMap $ itraverse f m
|
||||
{-# INLINE itraverse #-}
|
||||
|
||||
instance AsEmpty (MonoidalHashMap k a) where
|
||||
_Empty = nearly (MonoidalHashMap M.empty) (M.null . unpack)
|
||||
{-# INLINE _Empty #-}
|
||||
|
||||
instance Wrapped (MonoidalHashMap k a) where
|
||||
type Unwrapped (MonoidalHashMap k a) = M.HashMap k a
|
||||
_Wrapped' = iso unpack pack
|
||||
{-# INLINE _Wrapped' #-}
|
||||
|
||||
instance (Eq k, Hashable k, Semigroup a) => Semigroup (MonoidalHashMap k a) where
|
||||
MonoidalHashMap a <> MonoidalHashMap b = MonoidalHashMap $ M.unionWith (<>) a b
|
||||
{-# INLINE (<>) #-}
|
||||
@ -179,7 +146,7 @@ lookupM k = fromMaybe mempty . M.lookup k . unpack
|
||||
-- | /O(log n)/. Delete a key and its value from the map. When the key is not
|
||||
-- a member of the map, the original map is returned.
|
||||
delete :: (Eq k, Hashable k) => k -> MonoidalHashMap k a -> MonoidalHashMap k a
|
||||
delete k = _Wrapping' MonoidalHashMap %~ M.delete k
|
||||
delete k = MonoidalHashMap . M.delete k . getMonoidalHashMap
|
||||
{-# INLINE delete #-}
|
||||
|
||||
-- | /O(n)/.
|
@ -144,7 +144,6 @@ import qualified GHC.Exts as IsList
|
||||
|
||||
import Control.DeepSeq
|
||||
import qualified Data.IntMap as M
|
||||
import Control.Lens
|
||||
import Control.Newtype
|
||||
import Data.Aeson(FromJSON, ToJSON, FromJSON1, ToJSON1)
|
||||
#if MIN_VERSION_containers(0,5,9)
|
||||
@ -181,45 +180,6 @@ deriving instance Ord1 MonoidalIntMap
|
||||
deriving instance Show1 MonoidalIntMap
|
||||
#endif
|
||||
|
||||
type instance Index (MonoidalIntMap a) = Int
|
||||
type instance IxValue (MonoidalIntMap a) = a
|
||||
instance Ixed (MonoidalIntMap a) where
|
||||
ix k f (MonoidalIntMap m) = case M.lookup k m of
|
||||
Just v -> f v <&> \v' -> MonoidalIntMap (M.insert k v' m)
|
||||
Nothing -> pure (MonoidalIntMap m)
|
||||
{-# INLINE ix #-}
|
||||
|
||||
instance At (MonoidalIntMap a) where
|
||||
at k f (MonoidalIntMap m) = f mv <&> \r -> case r of
|
||||
Nothing -> maybe (MonoidalIntMap m) (const (MonoidalIntMap $ M.delete k m)) mv
|
||||
Just v' -> MonoidalIntMap $ M.insert k v' m
|
||||
where mv = M.lookup k m
|
||||
{-# INLINE at #-}
|
||||
|
||||
instance Each (MonoidalIntMap a) (MonoidalIntMap b) a b
|
||||
|
||||
instance FunctorWithIndex Int MonoidalIntMap
|
||||
instance FoldableWithIndex Int MonoidalIntMap
|
||||
instance TraversableWithIndex Int MonoidalIntMap where
|
||||
itraverse f (MonoidalIntMap m) = fmap MonoidalIntMap $ itraverse f m
|
||||
{-# INLINE itraverse #-}
|
||||
|
||||
instance TraverseMin Int MonoidalIntMap where
|
||||
traverseMin f (MonoidalIntMap m) = fmap MonoidalIntMap $ traverseMin f m
|
||||
{-# INLINE traverseMin #-}
|
||||
instance TraverseMax Int MonoidalIntMap where
|
||||
traverseMax f (MonoidalIntMap m) = fmap MonoidalIntMap $ traverseMax f m
|
||||
{-# INLINE traverseMax #-}
|
||||
|
||||
instance AsEmpty (MonoidalIntMap a) where
|
||||
_Empty = nearly (MonoidalIntMap M.empty) (M.null . unpack)
|
||||
{-# INLINE _Empty #-}
|
||||
|
||||
instance Wrapped (MonoidalIntMap a) where
|
||||
type Unwrapped (MonoidalIntMap a) = M.IntMap a
|
||||
_Wrapped' = iso unpack pack
|
||||
{-# INLINE _Wrapped' #-}
|
||||
|
||||
instance Semigroup a => Semigroup (MonoidalIntMap a) where
|
||||
MonoidalIntMap a <> MonoidalIntMap b = MonoidalIntMap $ M.unionWith (<>) a b
|
||||
{-# INLINE (<>) #-}
|
||||
@ -277,7 +237,7 @@ findWithDefault def k = M.findWithDefault def k . unpack
|
||||
-- | /O(log n)/. Delete a key and its value from the map. When the key is not
|
||||
-- a member of the map, the original map is returned.
|
||||
delete :: Int -> MonoidalIntMap a -> MonoidalIntMap a
|
||||
delete k = _Wrapping' MonoidalIntMap %~ M.delete k
|
||||
delete k = MonoidalIntMap . M.delete k . getMonoidalIntMap
|
||||
{-# INLINE delete #-}
|
||||
|
||||
-- | /O(n)/. Return all elements of the map and their keys
|
||||
@ -418,7 +378,7 @@ mapWithKey = coerce (M.mapWithKey :: (Int -> a -> b) -> M.IntMap a -> M.IntMap b
|
||||
{-# INLINE mapWithKey #-}
|
||||
|
||||
traverseWithKey :: Applicative t => (Int -> a -> t b) -> MonoidalIntMap a -> t (MonoidalIntMap b)
|
||||
traverseWithKey = itraverse
|
||||
traverseWithKey f = fmap MonoidalIntMap . M.traverseWithKey f . getMonoidalIntMap
|
||||
{-# INLINE traverseWithKey #-}
|
||||
|
||||
mapAccum :: forall a b c. (a -> b -> (a, c)) -> a -> MonoidalIntMap b -> (a, MonoidalIntMap c)
|
@ -144,7 +144,6 @@ import qualified GHC.Exts as IsList
|
||||
|
||||
import Control.DeepSeq
|
||||
import qualified Data.IntMap.Strict as M
|
||||
import Control.Lens
|
||||
import Control.Newtype
|
||||
import Data.Aeson(FromJSON, ToJSON, FromJSON1, ToJSON1)
|
||||
#if MIN_VERSION_containers(0,5,9)
|
||||
@ -181,45 +180,6 @@ deriving instance Ord1 MonoidalIntMap
|
||||
deriving instance Show1 MonoidalIntMap
|
||||
#endif
|
||||
|
||||
type instance Index (MonoidalIntMap a) = Int
|
||||
type instance IxValue (MonoidalIntMap a) = a
|
||||
instance Ixed (MonoidalIntMap a) where
|
||||
ix k f (MonoidalIntMap m) = case M.lookup k m of
|
||||
Just v -> f v <&> \v' -> MonoidalIntMap (M.insert k v' m)
|
||||
Nothing -> pure (MonoidalIntMap m)
|
||||
{-# INLINE ix #-}
|
||||
|
||||
instance At (MonoidalIntMap a) where
|
||||
at k f (MonoidalIntMap m) = f mv <&> \r -> case r of
|
||||
Nothing -> maybe (MonoidalIntMap m) (const (MonoidalIntMap $ M.delete k m)) mv
|
||||
Just v' -> MonoidalIntMap $ M.insert k v' m
|
||||
where mv = M.lookup k m
|
||||
{-# INLINE at #-}
|
||||
|
||||
instance Each (MonoidalIntMap a) (MonoidalIntMap b) a b
|
||||
|
||||
instance FunctorWithIndex Int MonoidalIntMap
|
||||
instance FoldableWithIndex Int MonoidalIntMap
|
||||
instance TraversableWithIndex Int MonoidalIntMap where
|
||||
itraverse f (MonoidalIntMap m) = fmap MonoidalIntMap $ itraverse f m
|
||||
{-# INLINE itraverse #-}
|
||||
|
||||
instance TraverseMin Int MonoidalIntMap where
|
||||
traverseMin f (MonoidalIntMap m) = fmap MonoidalIntMap $ traverseMin f m
|
||||
{-# INLINE traverseMin #-}
|
||||
instance TraverseMax Int MonoidalIntMap where
|
||||
traverseMax f (MonoidalIntMap m) = fmap MonoidalIntMap $ traverseMax f m
|
||||
{-# INLINE traverseMax #-}
|
||||
|
||||
instance AsEmpty (MonoidalIntMap a) where
|
||||
_Empty = nearly (MonoidalIntMap M.empty) (M.null . unpack)
|
||||
{-# INLINE _Empty #-}
|
||||
|
||||
instance Wrapped (MonoidalIntMap a) where
|
||||
type Unwrapped (MonoidalIntMap a) = M.IntMap a
|
||||
_Wrapped' = iso unpack pack
|
||||
{-# INLINE _Wrapped' #-}
|
||||
|
||||
instance Semigroup a => Semigroup (MonoidalIntMap a) where
|
||||
MonoidalIntMap a <> MonoidalIntMap b = MonoidalIntMap $ M.unionWith (<>) a b
|
||||
{-# INLINE (<>) #-}
|
||||
@ -277,7 +237,7 @@ findWithDefault def k = M.findWithDefault def k . unpack
|
||||
-- | /O(log n)/. Delete a key and its value from the map. When the key is not
|
||||
-- a member of the map, the original map is returned.
|
||||
delete :: Int -> MonoidalIntMap a -> MonoidalIntMap a
|
||||
delete k = _Wrapping' MonoidalIntMap %~ M.delete k
|
||||
delete k = MonoidalIntMap . M.delete k . getMonoidalIntMap
|
||||
{-# INLINE delete #-}
|
||||
|
||||
-- | /O(n)/. Return all elements of the map and their keys
|
||||
@ -418,7 +378,7 @@ mapWithKey = coerce (M.mapWithKey :: (Int -> a -> b) -> M.IntMap a -> M.IntMap b
|
||||
{-# INLINE mapWithKey #-}
|
||||
|
||||
traverseWithKey :: Applicative t => (Int -> a -> t b) -> MonoidalIntMap a -> t (MonoidalIntMap b)
|
||||
traverseWithKey = itraverse
|
||||
traverseWithKey f = fmap MonoidalIntMap . M.traverseWithKey f . getMonoidalIntMap
|
||||
{-# INLINE traverseWithKey #-}
|
||||
|
||||
mapAccum :: forall a b c. (a -> b -> (a, c)) -> a -> MonoidalIntMap b -> (a, MonoidalIntMap c)
|
@ -144,7 +144,6 @@ import qualified GHC.Exts as IsList
|
||||
|
||||
import Control.DeepSeq
|
||||
import qualified Data.Map as M
|
||||
import Control.Lens
|
||||
import Control.Newtype
|
||||
import Data.Aeson(FromJSON, ToJSON, FromJSON1, ToJSON1)
|
||||
#if MIN_VERSION_containers(0,5,9)
|
||||
@ -181,45 +180,6 @@ deriving instance (Ord k) => Ord1 (MonoidalMap k)
|
||||
deriving instance (Show k) => Show1 (MonoidalMap k)
|
||||
#endif
|
||||
|
||||
type instance Index (MonoidalMap k a) = k
|
||||
type instance IxValue (MonoidalMap k a) = a
|
||||
instance Ord k => Ixed (MonoidalMap k a) where
|
||||
ix k f (MonoidalMap m) = case M.lookup k m of
|
||||
Just v -> f v <&> \v' -> MonoidalMap (M.insert k v' m)
|
||||
Nothing -> pure (MonoidalMap m)
|
||||
{-# INLINE ix #-}
|
||||
|
||||
instance Ord k => At (MonoidalMap k a) where
|
||||
at k f (MonoidalMap m) = f mv <&> \r -> case r of
|
||||
Nothing -> maybe (MonoidalMap m) (const (MonoidalMap $ M.delete k m)) mv
|
||||
Just v' -> MonoidalMap $ M.insert k v' m
|
||||
where mv = M.lookup k m
|
||||
{-# INLINE at #-}
|
||||
|
||||
instance Each (MonoidalMap k a) (MonoidalMap k b) a b
|
||||
|
||||
instance FunctorWithIndex k (MonoidalMap k)
|
||||
instance FoldableWithIndex k (MonoidalMap k)
|
||||
instance TraversableWithIndex k (MonoidalMap k) where
|
||||
itraverse f (MonoidalMap m) = fmap MonoidalMap $ itraverse f m
|
||||
{-# INLINE itraverse #-}
|
||||
|
||||
instance Ord k => TraverseMin k (MonoidalMap k) where
|
||||
traverseMin f (MonoidalMap m) = fmap MonoidalMap $ traverseMin f m
|
||||
{-# INLINE traverseMin #-}
|
||||
instance Ord k => TraverseMax k (MonoidalMap k) where
|
||||
traverseMax f (MonoidalMap m) = fmap MonoidalMap $ traverseMax f m
|
||||
{-# INLINE traverseMax #-}
|
||||
|
||||
instance AsEmpty (MonoidalMap k a) where
|
||||
_Empty = nearly (MonoidalMap M.empty) (M.null . unpack)
|
||||
{-# INLINE _Empty #-}
|
||||
|
||||
instance Wrapped (MonoidalMap k a) where
|
||||
type Unwrapped (MonoidalMap k a) = M.Map k a
|
||||
_Wrapped' = iso unpack pack
|
||||
{-# INLINE _Wrapped' #-}
|
||||
|
||||
instance (Ord k, Semigroup a) => Semigroup (MonoidalMap k a) where
|
||||
MonoidalMap a <> MonoidalMap b = MonoidalMap $ M.unionWith (<>) a b
|
||||
{-# INLINE (<>) #-}
|
||||
@ -277,7 +237,7 @@ findWithDefault def k = M.findWithDefault def k . unpack
|
||||
-- | /O(log n)/. Delete a key and its value from the map. When the key is not
|
||||
-- a member of the map, the original map is returned.
|
||||
delete :: Ord k => k -> MonoidalMap k a -> MonoidalMap k a
|
||||
delete k = _Wrapping' MonoidalMap %~ M.delete k
|
||||
delete k = MonoidalMap . M.delete k . getMonoidalMap
|
||||
{-# INLINE delete #-}
|
||||
|
||||
-- | /O(n)/. Return all elements of the map and their keys
|
||||
@ -420,7 +380,7 @@ mapWithKey = coerce (M.mapWithKey :: (k -> a -> b) -> M.Map k a -> M.Map k b)
|
||||
{-# INLINE mapWithKey #-}
|
||||
|
||||
traverseWithKey :: Applicative t => (k -> a -> t b) -> MonoidalMap k a -> t (MonoidalMap k b)
|
||||
traverseWithKey = itraverse
|
||||
traverseWithKey f = fmap MonoidalMap . M.traverseWithKey f . getMonoidalMap
|
||||
{-# INLINE traverseWithKey #-}
|
||||
|
||||
mapAccum :: forall k a b c. (a -> b -> (a, c)) -> a -> MonoidalMap k b -> (a, MonoidalMap k c)
|
@ -144,7 +144,6 @@ import qualified GHC.Exts as IsList
|
||||
|
||||
import Control.DeepSeq
|
||||
import qualified Data.Map.Strict as M
|
||||
import Control.Lens
|
||||
import Control.Newtype
|
||||
import Data.Aeson(FromJSON, ToJSON, FromJSON1, ToJSON1)
|
||||
#if MIN_VERSION_containers(0,5,9)
|
||||
@ -181,45 +180,6 @@ deriving instance (Ord k) => Ord1 (MonoidalMap k)
|
||||
deriving instance (Show k) => Show1 (MonoidalMap k)
|
||||
#endif
|
||||
|
||||
type instance Index (MonoidalMap k a) = k
|
||||
type instance IxValue (MonoidalMap k a) = a
|
||||
instance Ord k => Ixed (MonoidalMap k a) where
|
||||
ix k f (MonoidalMap m) = case M.lookup k m of
|
||||
Just v -> f v <&> \v' -> MonoidalMap (M.insert k v' m)
|
||||
Nothing -> pure (MonoidalMap m)
|
||||
{-# INLINE ix #-}
|
||||
|
||||
instance Ord k => At (MonoidalMap k a) where
|
||||
at k f (MonoidalMap m) = f mv <&> \r -> case r of
|
||||
Nothing -> maybe (MonoidalMap m) (const (MonoidalMap $ M.delete k m)) mv
|
||||
Just v' -> MonoidalMap $ M.insert k v' m
|
||||
where mv = M.lookup k m
|
||||
{-# INLINE at #-}
|
||||
|
||||
instance Each (MonoidalMap k a) (MonoidalMap k b) a b
|
||||
|
||||
instance FunctorWithIndex k (MonoidalMap k)
|
||||
instance FoldableWithIndex k (MonoidalMap k)
|
||||
instance TraversableWithIndex k (MonoidalMap k) where
|
||||
itraverse f (MonoidalMap m) = fmap MonoidalMap $ itraverse f m
|
||||
{-# INLINE itraverse #-}
|
||||
|
||||
instance Ord k => TraverseMin k (MonoidalMap k) where
|
||||
traverseMin f (MonoidalMap m) = fmap MonoidalMap $ traverseMin f m
|
||||
{-# INLINE traverseMin #-}
|
||||
instance Ord k => TraverseMax k (MonoidalMap k) where
|
||||
traverseMax f (MonoidalMap m) = fmap MonoidalMap $ traverseMax f m
|
||||
{-# INLINE traverseMax #-}
|
||||
|
||||
instance AsEmpty (MonoidalMap k a) where
|
||||
_Empty = nearly (MonoidalMap M.empty) (M.null . unpack)
|
||||
{-# INLINE _Empty #-}
|
||||
|
||||
instance Wrapped (MonoidalMap k a) where
|
||||
type Unwrapped (MonoidalMap k a) = M.Map k a
|
||||
_Wrapped' = iso unpack pack
|
||||
{-# INLINE _Wrapped' #-}
|
||||
|
||||
instance (Ord k, Semigroup a) => Semigroup (MonoidalMap k a) where
|
||||
MonoidalMap a <> MonoidalMap b = MonoidalMap $ M.unionWith (<>) a b
|
||||
{-# INLINE (<>) #-}
|
||||
@ -277,7 +237,7 @@ findWithDefault def k = M.findWithDefault def k . unpack
|
||||
-- | /O(log n)/. Delete a key and its value from the map. When the key is not
|
||||
-- a member of the map, the original map is returned.
|
||||
delete :: Ord k => k -> MonoidalMap k a -> MonoidalMap k a
|
||||
delete k = _Wrapping' MonoidalMap %~ M.delete k
|
||||
delete k = MonoidalMap . M.delete k . getMonoidalMap
|
||||
{-# INLINE delete #-}
|
||||
|
||||
-- | /O(n)/. Return all elements of the map and their keys
|
||||
@ -419,7 +379,7 @@ mapWithKey = coerce (M.mapWithKey :: (k -> a -> b) -> M.Map k a -> M.Map k b)
|
||||
{-# INLINE mapWithKey #-}
|
||||
|
||||
traverseWithKey :: Applicative t => (k -> a -> t b) -> MonoidalMap k a -> t (MonoidalMap k b)
|
||||
traverseWithKey = itraverse
|
||||
traverseWithKey f = fmap MonoidalMap . M.traverseWithKey f . getMonoidalMap
|
||||
{-# INLINE traverseWithKey #-}
|
||||
|
||||
mapAccum :: forall k a b c. (a -> b -> (a, c)) -> a -> MonoidalMap k b -> (a, MonoidalMap k c)
|
Loading…
Reference in New Issue
Block a user