summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorphadej <>2019-10-21 10:45:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2019-10-21 10:45:00 (GMT)
commitd35a3bd53f5da9d23937b78087654271606b7a60 (patch)
tree729863193052237f9edc28b5c6fcfffa78f734c6
parent9597c704dd4829cdafea7ac90fce17369ffdbc50 (diff)
version 1.1HEAD1.1master
-rwxr-xr-xCHANGELOG.md5
-rw-r--r--semialign-indexed.cabal28
-rw-r--r--src/Data/Semialign/Indexed.hs33
3 files changed, 50 insertions, 16 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a2aecd0..8ede691 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+# 1.1
+
+- Split `ZipWithIndex` out of `SemialignWithIndex`
+- Compatible `semialign-1.1`.
+
# 1
Split out of `these` package.
diff --git a/semialign-indexed.cabal b/semialign-indexed.cabal
index 7f66ce7..3afb698 100644
--- a/semialign-indexed.cabal
+++ b/semialign-indexed.cabal
@@ -1,7 +1,7 @@
cabal-version: >=1.10
name: semialign-indexed
-version: 1
-synopsis: SemialignWithIndex, i.e. izip and ialign
+version: 1.1
+synopsis: SemialignWithIndex, i.e. izipWith and ialignWith
homepage: https://github.com/isomorphism/these
license: BSD3
license-file: LICENSE
@@ -16,13 +16,27 @@ description:
@
class (FunctorWithIndex i f, Semialign f) => SemialignWithIndex i f | f -> i where
\ ialignWith :: (i -> These a b -> c) -> f a -> f b -> f c
+ @
+ .
+ @
+ class (SemialignWithIndex i f, Zip f) => ZipWithIndex i f | f -> i where
\ izipWith :: (i -> a -> b -> c) -> f a -> f b -> f c
@
.
Superclass @FunctorWithIndex@ is from @lens@ package.
+ See https://hackage.haskell.org/package/semialign-optics for @optics@ variant.
tested-with:
- GHC ==7.4.2 || ==7.6.3 || ==7.8.4 || ==7.10.3 || ==8.0.2 || ==8.2.2 || ==8.4.4 || ==8.6.5 || ==8.8.1
+ GHC ==7.4.2
+ || ==7.6.3
+ || ==7.8.4
+ || ==7.10.3
+ || ==8.0.2
+ || ==8.2.2
+ || ==8.4.4
+ || ==8.6.5
+ || ==8.8.1
+ , GHCJS ==8.4
source-repository head
type: git
@@ -40,17 +54,17 @@ library
-- ghc boot libs
build-depends:
- base >=4.5.1.0 && <4.13
+ base >=4.5.1.0 && <4.14
, containers >=0.4.2.1 && <0.7
build-depends:
- semialign >=1 && <1.1
- , these >=1 && <1.1
+ semialign >=1.1 && <1.2
+ , these >=1 && <1.1
-- other dependencies
build-depends:
hashable >=1.2.7.0 && <1.4
- , lens >=4.17 && <4.18
+ , lens >=4.17 && <4.19
, unordered-containers >=0.2.8.0 && <0.3
, vector >=0.12.0.2 && <0.13
diff --git a/src/Data/Semialign/Indexed.hs b/src/Data/Semialign/Indexed.hs
index 4dfb66b..33b7f22 100644
--- a/src/Data/Semialign/Indexed.hs
+++ b/src/Data/Semialign/Indexed.hs
@@ -5,14 +5,16 @@
-- | Zipping and aligning of indexed functors.
module Data.Semialign.Indexed (
SemialignWithIndex (..),
+ ZipWithIndex (..),
) where
-import Prelude hiding (zip, zipWith)
+import Prelude hiding (repeat, zip, zipWith)
import Control.Lens (FunctorWithIndex (imap))
import Data.Align
import Data.These
+import Data.Zip
-- Instances
import Control.Applicative (ZipList)
@@ -37,6 +39,8 @@ class (FunctorWithIndex i f, Semialign f) => SemialignWithIndex i f | f -> i whe
ialignWith :: (i -> These a b -> c) -> f a -> f b -> f c
ialignWith f a b = imap f (align a b)
+-- | Indexed version of 'Zip'
+class (SemialignWithIndex i f, Zip f) => ZipWithIndex i f | f -> i where
-- | Analogous to 'zipWith', but also provides an index.
izipWith :: (i -> a -> b -> c) -> f a -> f b -> f c
izipWith f a b = imap (uncurry . f) (zip a b)
@@ -46,41 +50,50 @@ class (FunctorWithIndex i f, Semialign f) => SemialignWithIndex i f | f -> i whe
-------------------------------------------------------------------------------
instance SemialignWithIndex () Maybe
+instance ZipWithIndex () Maybe
instance SemialignWithIndex Int []
+instance ZipWithIndex Int []
instance SemialignWithIndex Int ZipList
+instance ZipWithIndex Int ZipList
-------------------------------------------------------------------------------
-- transformers
-------------------------------------------------------------------------------
instance SemialignWithIndex () Identity
+instance ZipWithIndex () Identity
instance (SemialignWithIndex i f, SemialignWithIndex j g) => SemialignWithIndex (Either i j) (Product f g) where
- izipWith f (Pair fa ga) (Pair fb gb) = Pair fc gc where
- fc = izipWith (f . Left) fa fb
- gc = izipWith (f . Right) ga gb
-
ialignWith f (Pair fa ga) (Pair fb gb) = Pair fc gc where
fc = ialignWith (f . Left) fa fb
gc = ialignWith (f . Right) ga gb
-instance (SemialignWithIndex i f, SemialignWithIndex j g) => SemialignWithIndex (i, j) (Compose f g) where
- izipWith f (Compose fga) (Compose fgb) = Compose fgc where
- fgc = izipWith (\i -> izipWith (\j -> f (i, j))) fga fgb
+instance (ZipWithIndex i f, ZipWithIndex j g) => ZipWithIndex (Either i j) (Product f g) where
+ izipWith f (Pair fa ga) (Pair fb gb) = Pair fc gc where
+ fc = izipWith (f . Left) fa fb
+ gc = izipWith (f . Right) ga gb
+instance (SemialignWithIndex i f, SemialignWithIndex j g) => SemialignWithIndex (i, j) (Compose f g) where
ialignWith f (Compose fga) (Compose fgb) = Compose $ ialignWith g fga fgb where
g i (This ga) = imap (\j -> f (i, j) . This) ga
g i (That gb) = imap (\j -> f (i, j) . That) gb
g i (These ga gb) = ialignWith (\j -> f (i, j)) ga gb
+instance (ZipWithIndex i f, ZipWithIndex j g) => ZipWithIndex (i, j) (Compose f g) where
+ izipWith f (Compose fga) (Compose fgb) = Compose fgc where
+ fgc = izipWith (\i -> izipWith (\j -> f (i, j))) fga fgb
+
-------------------------------------------------------------------------------
-- containers
-------------------------------------------------------------------------------
instance SemialignWithIndex Int Seq
-instance SemialignWithIndex Int IntMap where
+instance ZipWithIndex Int Seq
+instance SemialignWithIndex Int IntMap
+instance ZipWithIndex Int IntMap where
izipWith = IntMap.intersectionWithKey
instance Ord k => SemialignWithIndex k (Map k) where
+instance Ord k => ZipWithIndex k (Map k) where
izipWith = Map.intersectionWithKey
-------------------------------------------------------------------------------
@@ -88,6 +101,7 @@ instance Ord k => SemialignWithIndex k (Map k) where
-------------------------------------------------------------------------------
instance (Eq k, Hashable k) => SemialignWithIndex k (HashMap k) where
+instance (Eq k, Hashable k) => ZipWithIndex k (HashMap k) where
izipWith = HM.intersectionWithKey
-------------------------------------------------------------------------------
@@ -95,4 +109,5 @@ instance (Eq k, Hashable k) => SemialignWithIndex k (HashMap k) where
-------------------------------------------------------------------------------
instance SemialignWithIndex Int Vector where
+instance ZipWithIndex Int Vector where
izipWith = V.izipWith