module Data.Series.Generic.Zip (
zipWith, zipWithMatched, zipWithKey,
zipWith3, zipWithMatched3, zipWithKey3,
replace, (|->), (<-|),
zipWithStrategy,
zipWithStrategy3,
ZipStrategy,
skipStrategy,
mapStrategy,
constStrategy,
zipWithMonoid,
esum, eproduct,
unzip, unzip3,
) where
import qualified Data.Map.Strict as Map
import Data.Monoid ( Sum(..), Product(..) )
import Data.Series.Generic.Definition ( Series(MkSeries, index, values) )
import qualified Data.Series.Generic.Definition as G
import Data.Series.Generic.View ( selectSubset, requireWith )
import Data.Vector.Generic ( Vector )
import qualified Data.Vector.Generic as Vector
import qualified Data.Series.Index as Index
import qualified Data.Series.Index.Internal as Index.Internal
import Prelude hiding ( zipWith, zipWith3, unzip, unzip3 )
infix 6 |->, <-|
zipWith :: (Vector v a, Vector v b, Vector v c, Vector v (Maybe c), Ord k)
=> (a -> b -> c) -> Series v k a -> Series v k b -> Series v k (Maybe c)
zipWith :: forall (v :: * -> *) a b c k.
(Vector v a, Vector v b, Vector v c, Vector v (Maybe c), Ord k) =>
(a -> b -> c)
-> Series v k a -> Series v k b -> Series v k (Maybe c)
zipWith a -> b -> c
f Series v k a
left Series v k b
right
= let matched :: Series v k c
matched = (a -> b -> c) -> Series v k a -> Series v k b -> Series v k c
forall (v :: * -> *) a b c k.
(Vector v a, Vector v b, Vector v c, Ord k) =>
(a -> b -> c) -> Series v k a -> Series v k b -> Series v k c
zipWithMatched a -> b -> c
f Series v k a
left Series v k b
right
matchedKeys :: Index k
matchedKeys = Series v k c -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k c
matched
allKeys :: Index k
allKeys = Series v k a -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k a
left Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.union` Series v k b -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k b
right
unmatchedKeys :: Index k
unmatchedKeys = Index k
allKeys Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.difference` Index k
matchedKeys
unmatched :: Series v k (Maybe c)
unmatched = Index k -> v (Maybe c) -> Series v k (Maybe c)
forall {k} (v :: k -> *) k1 (a :: k).
Index k1 -> v a -> Series v k1 a
MkSeries Index k
unmatchedKeys (Int -> Maybe c -> v (Maybe c)
forall (v :: * -> *) a. Vector v a => Int -> a -> v a
Vector.replicate (Index k -> Int
forall k. Index k -> Int
Index.size Index k
unmatchedKeys) Maybe c
forall a. Maybe a
Nothing)
in (c -> Maybe c) -> Series v k c -> Series v k (Maybe c)
forall (v :: * -> *) a b k.
(Vector v a, Vector v b) =>
(a -> b) -> Series v k a -> Series v k b
G.map c -> Maybe c
forall a. a -> Maybe a
Just Series v k c
matched Series v k (Maybe c)
-> Series v k (Maybe c) -> Series v k (Maybe c)
forall a. Semigroup a => a -> a -> a
<> Series v k (Maybe c)
unmatched
{-# INLINE zipWith #-}
zipWith3 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v (Maybe d), Ord k)
=> (a -> b -> c -> d)
-> Series v k a
-> Series v k b
-> Series v k c
-> Series v k (Maybe d)
zipWith3 :: forall (v :: * -> *) a b c d k.
(Vector v a, Vector v b, Vector v c, Vector v d,
Vector v (Maybe d), Ord k) =>
(a -> b -> c -> d)
-> Series v k a
-> Series v k b
-> Series v k c
-> Series v k (Maybe d)
zipWith3 a -> b -> c -> d
f Series v k a
left Series v k b
center Series v k c
right
= let matched :: Series v k d
matched = (a -> b -> c -> d)
-> Series v k a -> Series v k b -> Series v k c -> Series v k d
forall (v :: * -> *) a b c d k.
(Vector v a, Vector v b, Vector v c, Vector v d, Ord k) =>
(a -> b -> c -> d)
-> Series v k a -> Series v k b -> Series v k c -> Series v k d
zipWithMatched3 a -> b -> c -> d
f Series v k a
left Series v k b
center Series v k c
right
matchedKeys :: Index k
matchedKeys = Series v k d -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k d
matched
allKeys :: Index k
allKeys = Series v k a -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k a
left Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.union` Series v k b -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k b
center Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.union` Series v k c -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k c
right
unmatchedKeys :: Index k
unmatchedKeys = Index k
allKeys Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.difference` Index k
matchedKeys
unmatched :: Series v k (Maybe d)
unmatched = Index k -> v (Maybe d) -> Series v k (Maybe d)
forall {k} (v :: k -> *) k1 (a :: k).
Index k1 -> v a -> Series v k1 a
MkSeries Index k
unmatchedKeys (Int -> Maybe d -> v (Maybe d)
forall (v :: * -> *) a. Vector v a => Int -> a -> v a
Vector.replicate (Index k -> Int
forall k. Index k -> Int
Index.size Index k
unmatchedKeys) Maybe d
forall a. Maybe a
Nothing)
in (d -> Maybe d) -> Series v k d -> Series v k (Maybe d)
forall (v :: * -> *) a b k.
(Vector v a, Vector v b) =>
(a -> b) -> Series v k a -> Series v k b
G.map d -> Maybe d
forall a. a -> Maybe a
Just Series v k d
matched Series v k (Maybe d)
-> Series v k (Maybe d) -> Series v k (Maybe d)
forall a. Semigroup a => a -> a -> a
<> Series v k (Maybe d)
unmatched
{-# INLINE zipWith3 #-}
zipWithMatched :: (Vector v a, Vector v b, Vector v c, Ord k)
=> (a -> b -> c) -> Series v k a -> Series v k b -> Series v k c
zipWithMatched :: forall (v :: * -> *) a b c k.
(Vector v a, Vector v b, Vector v c, Ord k) =>
(a -> b -> c) -> Series v k a -> Series v k b -> Series v k c
zipWithMatched a -> b -> c
f Series v k a
left Series v k b
right
= let matchedKeys :: Index k
matchedKeys = Series v k a -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k a
left Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.intersection` Series v k b -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k b
right
(MkSeries Index k
_ !v a
xs) = Series v k a
left Series v k a -> Index k -> Series v k a
forall (v :: * -> *) a k.
(Vector v a, Ord k) =>
Series v k a -> Index k -> Series v k a
`selectSubset` Index k
matchedKeys
(MkSeries Index k
_ !v b
ys) = Series v k b
right Series v k b -> Index k -> Series v k b
forall (v :: * -> *) a k.
(Vector v a, Ord k) =>
Series v k a -> Index k -> Series v k a
`selectSubset` Index k
matchedKeys
in Index k -> v c -> Series v k c
forall {k} (v :: k -> *) k1 (a :: k).
Index k1 -> v a -> Series v k1 a
MkSeries Index k
matchedKeys (v c -> Series v k c) -> v c -> Series v k c
forall a b. (a -> b) -> a -> b
$ (a -> b -> c) -> v a -> v b -> v c
forall (v :: * -> *) a b c.
(Vector v a, Vector v b, Vector v c) =>
(a -> b -> c) -> v a -> v b -> v c
Vector.zipWith a -> b -> c
f v a
xs v b
ys
{-# INLINE zipWithMatched #-}
zipWithMatched3 :: (Vector v a, Vector v b, Vector v c, Vector v d, Ord k)
=> (a -> b -> c -> d)
-> Series v k a
-> Series v k b
-> Series v k c
-> Series v k d
zipWithMatched3 :: forall (v :: * -> *) a b c d k.
(Vector v a, Vector v b, Vector v c, Vector v d, Ord k) =>
(a -> b -> c -> d)
-> Series v k a -> Series v k b -> Series v k c -> Series v k d
zipWithMatched3 a -> b -> c -> d
f Series v k a
left Series v k b
center Series v k c
right
= let matchedKeys :: Index k
matchedKeys = Series v k a -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k a
left Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.intersection` Series v k b -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k b
center Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.intersection` Series v k c -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k c
right
(MkSeries Index k
_ !v a
xs) = Series v k a
left Series v k a -> Index k -> Series v k a
forall (v :: * -> *) a k.
(Vector v a, Ord k) =>
Series v k a -> Index k -> Series v k a
`selectSubset` Index k
matchedKeys
(MkSeries Index k
_ !v b
ys) = Series v k b
center Series v k b -> Index k -> Series v k b
forall (v :: * -> *) a k.
(Vector v a, Ord k) =>
Series v k a -> Index k -> Series v k a
`selectSubset` Index k
matchedKeys
(MkSeries Index k
_ !v c
zs) = Series v k c
right Series v k c -> Index k -> Series v k c
forall (v :: * -> *) a k.
(Vector v a, Ord k) =>
Series v k a -> Index k -> Series v k a
`selectSubset` Index k
matchedKeys
in Index k -> v d -> Series v k d
forall {k} (v :: k -> *) k1 (a :: k).
Index k1 -> v a -> Series v k1 a
MkSeries Index k
matchedKeys (v d -> Series v k d) -> v d -> Series v k d
forall a b. (a -> b) -> a -> b
$ (a -> b -> c -> d) -> v a -> v b -> v c -> v d
forall (v :: * -> *) a b c d.
(Vector v a, Vector v b, Vector v c, Vector v d) =>
(a -> b -> c -> d) -> v a -> v b -> v c -> v d
Vector.zipWith3 a -> b -> c -> d
f v a
xs v b
ys v c
zs
{-# INLINE zipWithMatched3 #-}
zipWithKey :: (Vector v a, Vector v b, Vector v c, Vector v k, Ord k)
=> (k -> a -> b -> c) -> Series v k a -> Series v k b -> Series v k c
zipWithKey :: forall (v :: * -> *) a b c k.
(Vector v a, Vector v b, Vector v c, Vector v k, Ord k) =>
(k -> a -> b -> c) -> Series v k a -> Series v k b -> Series v k c
zipWithKey k -> a -> b -> c
f Series v k a
left Series v k b
right
= let matchedKeys :: Index k
matchedKeys = Series v k a -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k a
left Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.intersection` Series v k b -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k b
right
(MkSeries Index k
_ v a
xs) = Series v k a
left Series v k a -> Index k -> Series v k a
forall (v :: * -> *) a k.
(Vector v a, Ord k) =>
Series v k a -> Index k -> Series v k a
`selectSubset` Index k
matchedKeys
(MkSeries Index k
_ v b
ys) = Series v k b
right Series v k b -> Index k -> Series v k b
forall (v :: * -> *) a k.
(Vector v a, Ord k) =>
Series v k a -> Index k -> Series v k a
`selectSubset` Index k
matchedKeys
ks :: v k
ks = Index k -> v k
forall (v :: * -> *) k. Vector v k => Index k -> v k
Index.toAscVector Index k
matchedKeys
in Index k -> v c -> Series v k c
forall {k} (v :: k -> *) k1 (a :: k).
Index k1 -> v a -> Series v k1 a
MkSeries Index k
matchedKeys (v c -> Series v k c) -> v c -> Series v k c
forall a b. (a -> b) -> a -> b
$ (k -> a -> b -> c) -> v k -> v a -> v b -> v c
forall (v :: * -> *) a b c d.
(Vector v a, Vector v b, Vector v c, Vector v d) =>
(a -> b -> c -> d) -> v a -> v b -> v c -> v d
Vector.zipWith3 k -> a -> b -> c
f v k
ks v a
xs v b
ys
{-# INLINE zipWithKey #-}
zipWithKey3 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v k, Ord k)
=> (k -> a -> b -> c -> d)
-> Series v k a
-> Series v k b
-> Series v k c
-> Series v k d
zipWithKey3 :: forall (v :: * -> *) a b c d k.
(Vector v a, Vector v b, Vector v c, Vector v d, Vector v k,
Ord k) =>
(k -> a -> b -> c -> d)
-> Series v k a -> Series v k b -> Series v k c -> Series v k d
zipWithKey3 k -> a -> b -> c -> d
f Series v k a
left Series v k b
center Series v k c
right
= let matchedKeys :: Index k
matchedKeys = Series v k a -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k a
left Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.intersection` Series v k c -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k c
right
(MkSeries Index k
_ v a
xs) = Series v k a
left Series v k a -> Index k -> Series v k a
forall (v :: * -> *) a k.
(Vector v a, Ord k) =>
Series v k a -> Index k -> Series v k a
`selectSubset` Index k
matchedKeys
(MkSeries Index k
_ v b
ys) = Series v k b
center Series v k b -> Index k -> Series v k b
forall (v :: * -> *) a k.
(Vector v a, Ord k) =>
Series v k a -> Index k -> Series v k a
`selectSubset` Index k
matchedKeys
(MkSeries Index k
_ v c
zs) = Series v k c
right Series v k c -> Index k -> Series v k c
forall (v :: * -> *) a k.
(Vector v a, Ord k) =>
Series v k a -> Index k -> Series v k a
`selectSubset` Index k
matchedKeys
ks :: v k
ks = Index k -> v k
forall (v :: * -> *) k. Vector v k => Index k -> v k
Index.toAscVector Index k
matchedKeys
in Index k -> v d -> Series v k d
forall {k} (v :: k -> *) k1 (a :: k).
Index k1 -> v a -> Series v k1 a
MkSeries Index k
matchedKeys (v d -> Series v k d) -> v d -> Series v k d
forall a b. (a -> b) -> a -> b
$ (k -> a -> b -> c -> d) -> v k -> v a -> v b -> v c -> v d
forall (v :: * -> *) a b c d e.
(Vector v a, Vector v b, Vector v c, Vector v d, Vector v e) =>
(a -> b -> c -> d -> e) -> v a -> v b -> v c -> v d -> v e
Vector.zipWith4 k -> a -> b -> c -> d
f v k
ks v a
xs v b
ys v c
zs
{-# INLINE zipWithKey3 #-}
replace :: (Vector v a, Vector v Int, Ord k)
=> Series v k a -> Series v k a -> Series v k a
{-# INLINE replace #-}
Series v k a
xs replace :: forall (v :: * -> *) a k.
(Vector v a, Vector v Int, Ord k) =>
Series v k a -> Series v k a -> Series v k a
`replace` Series v k a
ys
= let keysToReplace :: Index k
keysToReplace = Series v k a -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k a
xs Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.intersection` Series v k a -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k a
ys
iixs :: v Int
iixs = Index Int -> v Int
forall (v :: * -> *) k. Vector v k => Index k -> v k
Index.toAscVector (Index Int -> v Int) -> Index Int -> v Int
forall a b. (a -> b) -> a -> b
$ (k -> Int) -> Index k -> Index Int
forall k g. (k -> g) -> Index k -> Index g
Index.Internal.mapMonotonic (\k
k -> k -> Index k -> Int
forall k. (HasCallStack, Ord k) => k -> Index k -> Int
Index.Internal.findIndex k
k (Series v k a -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k a
ys)) Index k
keysToReplace
in Index k -> v a -> Series v k a
forall {k} (v :: k -> *) k1 (a :: k).
Index k1 -> v a -> Series v k1 a
MkSeries (Series v k a -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k a
ys) (v a -> Series v k a) -> v a -> Series v k a
forall a b. (a -> b) -> a -> b
$ v a -> v Int -> v a -> v a
forall (v :: * -> *) a.
(Vector v a, Vector v Int) =>
v a -> v Int -> v a -> v a
Vector.update_ (Series v k a -> v a
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> v a
values Series v k a
ys) v Int
iixs (Series v k a -> v a
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> v a
values (Series v k a
xs Series v k a -> Index k -> Series v k a
forall (v :: * -> *) a k.
(Vector v a, Ord k) =>
Series v k a -> Index k -> Series v k a
`selectSubset` Index k
keysToReplace))
(|->) :: (Vector v a, Vector v Int, Ord k)
=> Series v k a -> Series v k a -> Series v k a
{-# INLINE (|->) #-}
|-> :: forall (v :: * -> *) a k.
(Vector v a, Vector v Int, Ord k) =>
Series v k a -> Series v k a -> Series v k a
(|->) = Series v k a -> Series v k a -> Series v k a
forall (v :: * -> *) a k.
(Vector v a, Vector v Int, Ord k) =>
Series v k a -> Series v k a -> Series v k a
replace
(<-|) :: (Vector v a, Vector v Int, Ord k)
=> Series v k a -> Series v k a -> Series v k a
{-# INLINE (<-|) #-}
<-| :: forall (v :: * -> *) a k.
(Vector v a, Vector v Int, Ord k) =>
Series v k a -> Series v k a -> Series v k a
(<-|) = (Series v k a -> Series v k a -> Series v k a)
-> Series v k a -> Series v k a -> Series v k a
forall a b c. (a -> b -> c) -> b -> a -> c
flip Series v k a -> Series v k a -> Series v k a
forall (v :: * -> *) a k.
(Vector v a, Vector v Int, Ord k) =>
Series v k a -> Series v k a -> Series v k a
replace
type ZipStrategy k a b = (k -> a -> Maybe b)
skipStrategy :: ZipStrategy k a b
skipStrategy :: forall k a b. ZipStrategy k a b
skipStrategy k
_ a
_ = Maybe b
forall a. Maybe a
Nothing
{-# INLINE skipStrategy #-}
mapStrategy :: (a -> b) -> ZipStrategy k a b
mapStrategy :: forall a b k. (a -> b) -> ZipStrategy k a b
mapStrategy a -> b
f k
_ a
x = b -> Maybe b
forall a. a -> Maybe a
Just (a -> b
f a
x)
{-# INLINE mapStrategy #-}
constStrategy :: b -> ZipStrategy k a b
constStrategy :: forall b k a. b -> ZipStrategy k a b
constStrategy b
v = (a -> b) -> ZipStrategy k a b
forall a b k. (a -> b) -> ZipStrategy k a b
mapStrategy (b -> a -> b
forall a b. a -> b -> a
const b
v)
{-# INLINE constStrategy #-}
zipWithStrategy :: (Vector v a, Vector v b, Vector v c, Ord k)
=> (a -> b -> c)
-> ZipStrategy k a c
-> ZipStrategy k b c
-> Series v k a
-> Series v k b
-> Series v k c
zipWithStrategy :: forall (v :: * -> *) a b c k.
(Vector v a, Vector v b, Vector v c, Ord k) =>
(a -> b -> c)
-> ZipStrategy k a c
-> ZipStrategy k b c
-> Series v k a
-> Series v k b
-> Series v k c
zipWithStrategy a -> b -> c
f ZipStrategy k a c
whenLeft ZipStrategy k b c
whenRight Series v k a
left Series v k b
right
= let onlyLeftKeys :: Index k
onlyLeftKeys = Series v k a -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k a
left Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.difference` Series v k b -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k b
right
onlyRightKeys :: Index k
onlyRightKeys = Series v k b -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k b
right Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.difference` Series v k a -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k a
left
leftZip :: Series v k c
leftZip = ZipStrategy k a c -> Series v k a -> Series v k c
forall {k} {k} {k} {b} {v :: k -> *} {k1} {a :: k} {a}
{v :: k -> *} {k1} {a :: k}.
(IsSeries (Map k b) v k1 a, IsSeries (Map k a) v k1 a) =>
(k -> a -> Maybe b) -> Series v k1 a -> Series v k1 a
applyStrategy ZipStrategy k a c
whenLeft (Series v k a -> Series v k c) -> Series v k a -> Series v k c
forall a b. (a -> b) -> a -> b
$ Series v k a
left Series v k a -> Index k -> Series v k a
forall (v :: * -> *) a k.
(Vector v a, Ord k) =>
Series v k a -> Index k -> Series v k a
`selectSubset` Index k
onlyLeftKeys
rightZip :: Series v k c
rightZip = ZipStrategy k b c -> Series v k b -> Series v k c
forall {k} {k} {k} {b} {v :: k -> *} {k1} {a :: k} {a}
{v :: k -> *} {k1} {a :: k}.
(IsSeries (Map k b) v k1 a, IsSeries (Map k a) v k1 a) =>
(k -> a -> Maybe b) -> Series v k1 a -> Series v k1 a
applyStrategy ZipStrategy k b c
whenRight (Series v k b -> Series v k c) -> Series v k b -> Series v k c
forall a b. (a -> b) -> a -> b
$ Series v k b
right Series v k b -> Index k -> Series v k b
forall (v :: * -> *) a k.
(Vector v a, Ord k) =>
Series v k a -> Index k -> Series v k a
`selectSubset` Index k
onlyRightKeys
in (a -> b -> c) -> Series v k a -> Series v k b -> Series v k c
forall (v :: * -> *) a b c k.
(Vector v a, Vector v b, Vector v c, Ord k) =>
(a -> b -> c) -> Series v k a -> Series v k b -> Series v k c
zipWithMatched a -> b -> c
f Series v k a
left Series v k b
right Series v k c -> Series v k c -> Series v k c
forall a. Semigroup a => a -> a -> a
<> Series v k c
leftZip Series v k c -> Series v k c -> Series v k c
forall a. Semigroup a => a -> a -> a
<> Series v k c
rightZip
where
applyStrategy :: (k -> a -> Maybe b) -> Series v k1 a -> Series v k1 a
applyStrategy k -> a -> Maybe b
strat = Map k b -> Series v k1 a
forall {k} t (v :: k -> *) k1 (a :: k).
IsSeries t v k1 a =>
t -> Series v k1 a
G.toSeries
(Map k b -> Series v k1 a)
-> (Series v k1 a -> Map k b) -> Series v k1 a -> Series v k1 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (k -> a -> Maybe b) -> Map k a -> Map k b
forall k a b. (k -> a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybeWithKey k -> a -> Maybe b
strat
(Map k a -> Map k b)
-> (Series v k1 a -> Map k a) -> Series v k1 a -> Map k b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Series v k1 a -> Map k a
forall {k} t (v :: k -> *) k1 (a :: k).
IsSeries t v k1 a =>
Series v k1 a -> t
G.fromSeries
{-# INLINE zipWithStrategy #-}
zipWithStrategy3 :: (Vector v a, Vector v b, Vector v c, Vector v d, Ord k)
=> (a -> b -> c -> d)
-> ZipStrategy k a d
-> ZipStrategy k b d
-> ZipStrategy k c d
-> Series v k a
-> Series v k b
-> Series v k c
-> Series v k d
zipWithStrategy3 :: forall (v :: * -> *) a b c d k.
(Vector v a, Vector v b, Vector v c, Vector v d, Ord k) =>
(a -> b -> c -> d)
-> ZipStrategy k a d
-> ZipStrategy k b d
-> ZipStrategy k c d
-> Series v k a
-> Series v k b
-> Series v k c
-> Series v k d
zipWithStrategy3 a -> b -> c -> d
f ZipStrategy k a d
whenLeft ZipStrategy k b d
whenCenter ZipStrategy k c d
whenRight Series v k a
left Series v k b
center Series v k c
right
= let onlyLeftKeys :: Index k
onlyLeftKeys = Series v k a -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k a
left Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.difference` (Series v k b -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k b
center Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.union` Series v k c -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k c
right)
onlyCenterKeys :: Index k
onlyCenterKeys = Series v k b -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k b
center Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.difference` (Series v k a -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k a
left Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.union` Series v k c -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k c
right)
onlyRightKeys :: Index k
onlyRightKeys = Series v k c -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k c
right Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.difference` (Series v k b -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k b
center Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.union` Series v k a -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k a
left)
leftZip :: Series v k d
leftZip = ZipStrategy k a d -> Series v k a -> Series v k d
forall {k} {k} {k} {b} {v :: k -> *} {k1} {a :: k} {a}
{v :: k -> *} {k1} {a :: k}.
(IsSeries (Map k b) v k1 a, IsSeries (Map k a) v k1 a) =>
(k -> a -> Maybe b) -> Series v k1 a -> Series v k1 a
applyStrategy ZipStrategy k a d
whenLeft (Series v k a -> Series v k d) -> Series v k a -> Series v k d
forall a b. (a -> b) -> a -> b
$ Series v k a
left Series v k a -> Index k -> Series v k a
forall (v :: * -> *) a k.
(Vector v a, Ord k) =>
Series v k a -> Index k -> Series v k a
`selectSubset` Index k
onlyLeftKeys
centerZip :: Series v k d
centerZip = ZipStrategy k b d -> Series v k b -> Series v k d
forall {k} {k} {k} {b} {v :: k -> *} {k1} {a :: k} {a}
{v :: k -> *} {k1} {a :: k}.
(IsSeries (Map k b) v k1 a, IsSeries (Map k a) v k1 a) =>
(k -> a -> Maybe b) -> Series v k1 a -> Series v k1 a
applyStrategy ZipStrategy k b d
whenCenter (Series v k b -> Series v k d) -> Series v k b -> Series v k d
forall a b. (a -> b) -> a -> b
$ Series v k b
center Series v k b -> Index k -> Series v k b
forall (v :: * -> *) a k.
(Vector v a, Ord k) =>
Series v k a -> Index k -> Series v k a
`selectSubset` Index k
onlyCenterKeys
rightZip :: Series v k d
rightZip = ZipStrategy k c d -> Series v k c -> Series v k d
forall {k} {k} {k} {b} {v :: k -> *} {k1} {a :: k} {a}
{v :: k -> *} {k1} {a :: k}.
(IsSeries (Map k b) v k1 a, IsSeries (Map k a) v k1 a) =>
(k -> a -> Maybe b) -> Series v k1 a -> Series v k1 a
applyStrategy ZipStrategy k c d
whenRight (Series v k c -> Series v k d) -> Series v k c -> Series v k d
forall a b. (a -> b) -> a -> b
$ Series v k c
right Series v k c -> Index k -> Series v k c
forall (v :: * -> *) a k.
(Vector v a, Ord k) =>
Series v k a -> Index k -> Series v k a
`selectSubset` Index k
onlyRightKeys
in (a -> b -> c -> d)
-> Series v k a -> Series v k b -> Series v k c -> Series v k d
forall (v :: * -> *) a b c d k.
(Vector v a, Vector v b, Vector v c, Vector v d, Ord k) =>
(a -> b -> c -> d)
-> Series v k a -> Series v k b -> Series v k c -> Series v k d
zipWithMatched3 a -> b -> c -> d
f Series v k a
left Series v k b
center Series v k c
right Series v k d -> Series v k d -> Series v k d
forall a. Semigroup a => a -> a -> a
<> Series v k d
leftZip Series v k d -> Series v k d -> Series v k d
forall a. Semigroup a => a -> a -> a
<> Series v k d
centerZip Series v k d -> Series v k d -> Series v k d
forall a. Semigroup a => a -> a -> a
<> Series v k d
rightZip
where
applyStrategy :: (k -> a -> Maybe b) -> Series v k1 a -> Series v k1 a
applyStrategy k -> a -> Maybe b
strat = Map k b -> Series v k1 a
forall {k} t (v :: k -> *) k1 (a :: k).
IsSeries t v k1 a =>
t -> Series v k1 a
G.toSeries
(Map k b -> Series v k1 a)
-> (Series v k1 a -> Map k b) -> Series v k1 a -> Series v k1 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (k -> a -> Maybe b) -> Map k a -> Map k b
forall k a b. (k -> a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybeWithKey k -> a -> Maybe b
strat
(Map k a -> Map k b)
-> (Series v k1 a -> Map k a) -> Series v k1 a -> Map k b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Series v k1 a -> Map k a
forall {k} t (v :: k -> *) k1 (a :: k).
IsSeries t v k1 a =>
Series v k1 a -> t
G.fromSeries
{-# INLINE zipWithStrategy3 #-}
zipWithMonoid :: ( Monoid a, Monoid b
, Vector v a, Vector v b, Vector v c
, Ord k
)
=> (a -> b -> c)
-> Series v k a
-> Series v k b
-> Series v k c
zipWithMonoid :: forall a b (v :: * -> *) c k.
(Monoid a, Monoid b, Vector v a, Vector v b, Vector v c, Ord k) =>
(a -> b -> c) -> Series v k a -> Series v k b -> Series v k c
zipWithMonoid a -> b -> c
f Series v k a
left Series v k b
right
= let fullindex :: Index k
fullindex = Series v k a -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k a
left Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`Index.union` Series v k b -> Index k
forall {k1} (v :: k1 -> *) k2 (a :: k1). Series v k2 a -> Index k2
index Series v k b
right
(MkSeries Index k
ix v a
ls) = (k -> a) -> (a -> a) -> Series v k a -> Index k -> Series v k a
forall (v :: * -> *) a b k.
(Vector v a, Vector v b, Ord k) =>
(k -> b) -> (a -> b) -> Series v k a -> Index k -> Series v k b
requireWith (a -> k -> a
forall a b. a -> b -> a
const a
forall a. Monoid a => a
mempty) a -> a
forall a. a -> a
id Series v k a
left Index k
fullindex
(MkSeries Index k
_ v b
rs) = (k -> b) -> (b -> b) -> Series v k b -> Index k -> Series v k b
forall (v :: * -> *) a b k.
(Vector v a, Vector v b, Ord k) =>
(k -> b) -> (a -> b) -> Series v k a -> Index k -> Series v k b
requireWith (b -> k -> b
forall a b. a -> b -> a
const b
forall a. Monoid a => a
mempty) b -> b
forall a. a -> a
id Series v k b
right Index k
fullindex
in Index k -> v c -> Series v k c
forall {k} (v :: k -> *) k1 (a :: k).
Index k1 -> v a -> Series v k1 a
MkSeries Index k
ix (v c -> Series v k c) -> v c -> Series v k c
forall a b. (a -> b) -> a -> b
$ (a -> b -> c) -> v a -> v b -> v c
forall (v :: * -> *) a b c.
(Vector v a, Vector v b, Vector v c) =>
(a -> b -> c) -> v a -> v b -> v c
Vector.zipWith a -> b -> c
f v a
ls v b
rs
{-# INLINE zipWithMonoid #-}
esum :: (Ord k, Num a, Vector v a, Vector v (Sum a))
=> Series v k a
-> Series v k a
-> Series v k a
esum :: forall k a (v :: * -> *).
(Ord k, Num a, Vector v a, Vector v (Sum a)) =>
Series v k a -> Series v k a -> Series v k a
esum Series v k a
ls Series v k a
rs = (Sum a -> a) -> Series v k (Sum a) -> Series v k a
forall (v :: * -> *) a b k.
(Vector v a, Vector v b) =>
(a -> b) -> Series v k a -> Series v k b
G.map Sum a -> a
forall a. Sum a -> a
getSum (Series v k (Sum a) -> Series v k a)
-> Series v k (Sum a) -> Series v k a
forall a b. (a -> b) -> a -> b
$ (Sum a -> Sum a -> Sum a)
-> Series v k (Sum a) -> Series v k (Sum a) -> Series v k (Sum a)
forall a b (v :: * -> *) c k.
(Monoid a, Monoid b, Vector v a, Vector v b, Vector v c, Ord k) =>
(a -> b -> c) -> Series v k a -> Series v k b -> Series v k c
zipWithMonoid Sum a -> Sum a -> Sum a
forall a. Semigroup a => a -> a -> a
(<>) ((a -> Sum a) -> Series v k a -> Series v k (Sum a)
forall (v :: * -> *) a b k.
(Vector v a, Vector v b) =>
(a -> b) -> Series v k a -> Series v k b
G.map a -> Sum a
forall a. a -> Sum a
Sum Series v k a
ls) ((a -> Sum a) -> Series v k a -> Series v k (Sum a)
forall (v :: * -> *) a b k.
(Vector v a, Vector v b) =>
(a -> b) -> Series v k a -> Series v k b
G.map a -> Sum a
forall a. a -> Sum a
Sum Series v k a
rs)
{-# INLINE esum #-}
eproduct :: (Ord k, Num a, Vector v a, Vector v (Product a))
=> Series v k a
-> Series v k a
-> Series v k a
eproduct :: forall k a (v :: * -> *).
(Ord k, Num a, Vector v a, Vector v (Product a)) =>
Series v k a -> Series v k a -> Series v k a
eproduct Series v k a
ls Series v k a
rs = (Product a -> a) -> Series v k (Product a) -> Series v k a
forall (v :: * -> *) a b k.
(Vector v a, Vector v b) =>
(a -> b) -> Series v k a -> Series v k b
G.map Product a -> a
forall a. Product a -> a
getProduct (Series v k (Product a) -> Series v k a)
-> Series v k (Product a) -> Series v k a
forall a b. (a -> b) -> a -> b
$ (Product a -> Product a -> Product a)
-> Series v k (Product a)
-> Series v k (Product a)
-> Series v k (Product a)
forall a b (v :: * -> *) c k.
(Monoid a, Monoid b, Vector v a, Vector v b, Vector v c, Ord k) =>
(a -> b -> c) -> Series v k a -> Series v k b -> Series v k c
zipWithMonoid Product a -> Product a -> Product a
forall a. Semigroup a => a -> a -> a
(<>) ((a -> Product a) -> Series v k a -> Series v k (Product a)
forall (v :: * -> *) a b k.
(Vector v a, Vector v b) =>
(a -> b) -> Series v k a -> Series v k b
G.map a -> Product a
forall a. a -> Product a
Product Series v k a
ls) ((a -> Product a) -> Series v k a -> Series v k (Product a)
forall (v :: * -> *) a b k.
(Vector v a, Vector v b) =>
(a -> b) -> Series v k a -> Series v k b
G.map a -> Product a
forall a. a -> Product a
Product Series v k a
rs)
{-# INLINE eproduct #-}
unzip :: (Vector v a, Vector v b, Vector v (a, b))
=> Series v k (a, b)
-> ( Series v k a
, Series v k b
)
unzip :: forall (v :: * -> *) a b k.
(Vector v a, Vector v b, Vector v (a, b)) =>
Series v k (a, b) -> (Series v k a, Series v k b)
unzip (MkSeries Index k
ix v (a, b)
vs)
= let (v a
left, v b
right) = v (a, b) -> (v a, v b)
forall (v :: * -> *) a b.
(Vector v a, Vector v b, Vector v (a, b)) =>
v (a, b) -> (v a, v b)
Vector.unzip v (a, b)
vs
in (Index k -> v a -> Series v k a
forall {k} (v :: k -> *) k1 (a :: k).
Index k1 -> v a -> Series v k1 a
MkSeries Index k
ix v a
left, Index k -> v b -> Series v k b
forall {k} (v :: k -> *) k1 (a :: k).
Index k1 -> v a -> Series v k1 a
MkSeries Index k
ix v b
right)
{-# INLINE unzip #-}
unzip3 :: (Vector v a, Vector v b, Vector v c, Vector v (a, b, c))
=> Series v k (a, b, c)
-> ( Series v k a
, Series v k b
, Series v k c
)
unzip3 :: forall (v :: * -> *) a b c k.
(Vector v a, Vector v b, Vector v c, Vector v (a, b, c)) =>
Series v k (a, b, c) -> (Series v k a, Series v k b, Series v k c)
unzip3 (MkSeries Index k
ix v (a, b, c)
vs)
= let (v a
left, v b
center, v c
right) = v (a, b, c) -> (v a, v b, v c)
forall (v :: * -> *) a b c.
(Vector v a, Vector v b, Vector v c, Vector v (a, b, c)) =>
v (a, b, c) -> (v a, v b, v c)
Vector.unzip3 v (a, b, c)
vs
in (Index k -> v a -> Series v k a
forall {k} (v :: k -> *) k1 (a :: k).
Index k1 -> v a -> Series v k1 a
MkSeries Index k
ix v a
left, Index k -> v b -> Series v k b
forall {k} (v :: k -> *) k1 (a :: k).
Index k1 -> v a -> Series v k1 a
MkSeries Index k
ix v b
center, Index k -> v c -> Series v k c
forall {k} (v :: k -> *) k1 (a :: k).
Index k1 -> v a -> Series v k1 a
MkSeries Index k
ix v c
right)
{-# INLINE unzip3 #-}