module Streamly.Internal.Data.Fold
(
Step (..)
, Fold (..)
, foldl'
, foldlM'
, foldl1'
, foldr
, foldrM
, mkFold
, mkFold_
, mkFoldM
, mkFoldM_
, fromPure
, fromEffect
, sconcat
, mconcat
, foldMap
, foldMapM
, drain
, drainBy
, last
, length
, mean
, variance
, stdDev
, rollingHash
, rollingHashWithSalt
, rollingHashFirstN
, sum
, product
, maximumBy
, maximum
, minimumBy
, minimum
, toList
, toListRev
, toStream
, toStreamRev
, drainN
, genericIndex
, index
, head
, find
, lookup
, findIndex
, elemIndex
, null
, elem
, notElem
, all
, any
, and
, or
, with
, hoist
, generally
, rmapM
, transform
, lmap
, lmapM
, scan
, postscan
, indexed
, filter
, filterM
, sampleFromthen
, catMaybes
, mapMaybe
, take
, takeEndBy
, takeEndBy_
, serialWith
, serial_
, splitAt
, teeWith
, tee
, teeWithFst
, teeWithMin
, distribute
, shortest
, longest
, partitionByM
, partitionByFstM
, partitionByMinM
, partitionBy
, partition
, demux
, demuxWith
, demuxDefault
, demuxDefaultWith
, classify
, classifyWith
, unzip
, unzipWith
, unzipWithM
, unzipWithFstM
, unzipWithMinM
, zipWithM
, zip
, many
, chunksOf
, chunksBetween
, concatSequence
, concatMap
, initialize
, snoc
, duplicate
, finish
, sequence
, mapM
)
where
import Data.Bifunctor (first)
import Data.Either (isLeft, isRight)
import Data.Functor.Identity (Identity(..))
import Data.Int (Int64)
import Data.Map.Strict (Map)
import Data.Maybe (isJust, fromJust)
#if __GLASGOW_HASKELL__ < 804
import Data.Semigroup (Semigroup((<>)))
#endif
import Streamly.Internal.BaseCompat (fromLeft, fromRight)
import Streamly.Internal.Data.Either.Strict
(Either'(..), fromLeft', fromRight', isLeft', isRight')
import Streamly.Internal.Data.Pipe.Type (Pipe (..), PipeState(..))
import Streamly.Internal.Data.Tuple.Strict (Tuple'(..), Tuple3'(..))
import Streamly.Internal.Data.Stream.Serial (SerialT(..))
import qualified Data.Map.Strict as Map
import qualified Streamly.Internal.Data.Pipe.Type as Pipe
import qualified Prelude
import Prelude hiding
( filter, foldl1, drop, dropWhile, take, takeWhile, zipWith
, foldl, foldr, map, mapM_, sequence, all, any, sum, product, elem
, notElem, maximum, minimum, head, last, tail, length, null
, reverse, iterate, init, and, or, lookup, (!!)
, scanl, scanl1, replicate, concatMap, mconcat, foldMap, unzip
, span, splitAt, break, mapM, zip)
import Streamly.Internal.Data.Fold.Type
hoist :: (forall x. m x -> n x) -> Fold m a b -> Fold n a b
hoist :: forall (m :: * -> *) (n :: * -> *) a b.
(forall x. m x -> n x) -> Fold m a b -> Fold n a b
hoist forall x. m x -> n x
f (Fold s -> a -> m (Step s b)
step m (Step s b)
initial s -> m b
extract) =
forall (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> m (Step s b) -> (s -> m b) -> Fold m a b
Fold (\s
x a
a -> forall x. m x -> n x
f forall a b. (a -> b) -> a -> b
$ s -> a -> m (Step s b)
step s
x a
a) (forall x. m x -> n x
f m (Step s b)
initial) (forall x. m x -> n x
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> m b
extract)
generally :: Monad m => Fold Identity a b -> Fold m a b
generally :: forall (m :: * -> *) a b.
Monad m =>
Fold Identity a b -> Fold m a b
generally = forall (m :: * -> *) (n :: * -> *) a b.
(forall x. m x -> n x) -> Fold m a b -> Fold n a b
hoist (forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Identity a -> a
runIdentity)
{-# DEPRECATED sequence "Use \"rmapM id\" instead" #-}
{-# INLINE sequence #-}
sequence :: Monad m => Fold m a (m b) -> Fold m a b
sequence :: forall (m :: * -> *) a b. Monad m => Fold m a (m b) -> Fold m a b
sequence = forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> Fold m a b -> Fold m a c
rmapM forall a. a -> a
id
{-# DEPRECATED mapM "Use rmapM instead" #-}
{-# INLINE mapM #-}
mapM :: Monad m => (b -> m c) -> Fold m a b -> Fold m a c
mapM :: forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> Fold m a b -> Fold m a c
mapM = forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> Fold m a b -> Fold m a c
rmapM
{-# INLINE mapMaybe #-}
mapMaybe :: (Monad m) => (a -> Maybe b) -> Fold m b r -> Fold m a r
mapMaybe :: forall (m :: * -> *) a b r.
Monad m =>
(a -> Maybe b) -> Fold m b r -> Fold m a r
mapMaybe a -> Maybe b
f = forall a b (m :: * -> *) r. (a -> b) -> Fold m b r -> Fold m a r
lmap a -> Maybe b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a r.
Monad m =>
(a -> Bool) -> Fold m a r -> Fold m a r
filter forall a. Maybe a -> Bool
isJust forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b (m :: * -> *) r. (a -> b) -> Fold m b r -> Fold m a r
lmap forall a. HasCallStack => Maybe a -> a
fromJust
{-# INLINE transform #-}
transform :: Monad m => Pipe m a b -> Fold m b c -> Fold m a c
transform :: forall (m :: * -> *) a b c.
Monad m =>
Pipe m a b -> Fold m b c -> Fold m a c
transform (Pipe s1 -> a -> m (Step (PipeState s1 s2) b)
pstep1 s2 -> m (Step (PipeState s1 s2) b)
pstep2 s1
pinitial) (Fold s -> b -> m (Step s c)
fstep m (Step s c)
finitial s -> m c
fextract) =
forall (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> m (Step s b) -> (s -> m b) -> Fold m a b
Fold Tuple' s1 s -> a -> m (Step (Tuple' s1 s) c)
step m (Step (Tuple' s1 s) c)
initial forall {a}. Tuple' a s -> m c
extract
where
initial :: m (Step (Tuple' s1 s) c)
initial = forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (forall a b. a -> b -> Tuple' a b
Tuple' s1
pinitial) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Step s c)
finitial
step :: Tuple' s1 s -> a -> m (Step (Tuple' s1 s) c)
step (Tuple' s1
ps s
fs) a
x = do
Step (PipeState s1 s2) b
r <- s1 -> a -> m (Step (PipeState s1 s2) b)
pstep1 s1
ps a
x
s -> Step (PipeState s1 s2) b -> m (Step (Tuple' s1 s) c)
go s
fs Step (PipeState s1 s2) b
r
where
go :: s -> Step (PipeState s1 s2) b -> m (Step (Tuple' s1 s) c)
go s
acc (Pipe.Yield b
b (Consume s1
ps')) = do
Step s c
acc' <- s -> b -> m (Step s c)
fstep s
acc b
b
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ case Step s c
acc' of
Partial s
s -> forall s b. s -> Step s b
Partial forall a b. (a -> b) -> a -> b
$ forall a b. a -> b -> Tuple' a b
Tuple' s1
ps' s
s
Done c
b2 -> forall s b. b -> Step s b
Done c
b2
go s
acc (Pipe.Yield b
b (Produce s2
ps')) = do
Step s c
acc' <- s -> b -> m (Step s c)
fstep s
acc b
b
Step (PipeState s1 s2) b
r <- s2 -> m (Step (PipeState s1 s2) b)
pstep2 s2
ps'
case Step s c
acc' of
Partial s
s -> s -> Step (PipeState s1 s2) b -> m (Step (Tuple' s1 s) c)
go s
s Step (PipeState s1 s2) b
r
Done c
b2 -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s b. b -> Step s b
Done c
b2
go s
acc (Pipe.Continue (Consume s1
ps')) =
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s b. s -> Step s b
Partial forall a b. (a -> b) -> a -> b
$ forall a b. a -> b -> Tuple' a b
Tuple' s1
ps' s
acc
go s
acc (Pipe.Continue (Produce s2
ps')) = do
Step (PipeState s1 s2) b
r <- s2 -> m (Step (PipeState s1 s2) b)
pstep2 s2
ps'
s -> Step (PipeState s1 s2) b -> m (Step (Tuple' s1 s) c)
go s
acc Step (PipeState s1 s2) b
r
extract :: Tuple' a s -> m c
extract (Tuple' a
_ s
fs) = s -> m c
fextract s
fs
{-# INLINE scan #-}
scan :: Monad m => Fold m a b -> Fold m b c -> Fold m a c
scan :: forall (m :: * -> *) a b c.
Monad m =>
Fold m a b -> Fold m b c -> Fold m a c
scan (Fold s -> a -> m (Step s b)
stepL m (Step s b)
initialL s -> m b
extractL) (Fold s -> b -> m (Step s c)
stepR m (Step s c)
initialR s -> m c
extractR) =
forall (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> m (Step s b) -> (s -> m b) -> Fold m a b
Fold (s, s) -> a -> m (Step (s, s) c)
step m (Step (s, s) c)
initial forall {a}. (a, s) -> m c
extract
where
{-# INLINE runStep #-}
runStep :: m (Step s b) -> s -> m (Step (s, s) c)
runStep m (Step s b)
actionL s
sR = do
Step s b
rL <- m (Step s b)
actionL
case Step s b
rL of
Done b
bL -> do
Step s c
rR <- s -> b -> m (Step s c)
stepR s
sR b
bL
case Step s c
rR of
Partial s
sR1 -> forall s b. b -> Step s b
Done forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m c
extractR s
sR1
Done c
bR -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s b. b -> Step s b
Done c
bR
Partial s
sL -> do
!b
b <- s -> m b
extractL s
sL
Step s c
rR <- s -> b -> m (Step s c)
stepR s
sR b
b
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ case Step s c
rR of
Partial s
sR1 -> forall s b. s -> Step s b
Partial (s
sL, s
sR1)
Done c
bR -> forall s b. b -> Step s b
Done c
bR
initial :: m (Step (s, s) c)
initial = do
Step s c
r <- m (Step s c)
initialR
case Step s c
r of
Partial s
sR -> m (Step s b) -> s -> m (Step (s, s) c)
runStep m (Step s b)
initialL s
sR
Done c
b -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s b. b -> Step s b
Done c
b
step :: (s, s) -> a -> m (Step (s, s) c)
step (s
sL, s
sR) a
x = m (Step s b) -> s -> m (Step (s, s) c)
runStep (s -> a -> m (Step s b)
stepL s
sL a
x) s
sR
extract :: (a, s) -> m c
extract = s -> m c
extractR forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd
{-# INLINE postscan #-}
postscan :: Monad m => Fold m a b -> Fold m b c -> Fold m a c
postscan :: forall (m :: * -> *) a b c.
Monad m =>
Fold m a b -> Fold m b c -> Fold m a c
postscan (Fold s -> a -> m (Step s b)
stepL m (Step s b)
initialL s -> m b
extractL) (Fold s -> b -> m (Step s c)
stepR m (Step s c)
initialR s -> m c
extractR) =
forall (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> m (Step s b) -> (s -> m b) -> Fold m a b
Fold (s, s) -> a -> m (Step (s, s) c)
step m (Step (s, s) c)
initial forall {a}. (a, s) -> m c
extract
where
{-# INLINE runStep #-}
runStep :: m (Step s b) -> s -> m (Step (s, s) c)
runStep m (Step s b)
actionL s
sR = do
Step s b
rL <- m (Step s b)
actionL
case Step s b
rL of
Done b
bL -> do
Step s c
rR <- s -> b -> m (Step s c)
stepR s
sR b
bL
case Step s c
rR of
Partial s
sR1 -> forall s b. b -> Step s b
Done forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m c
extractR s
sR1
Done c
bR -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s b. b -> Step s b
Done c
bR
Partial s
sL -> do
!b
b <- s -> m b
extractL s
sL
Step s c
rR <- s -> b -> m (Step s c)
stepR s
sR b
b
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ case Step s c
rR of
Partial s
sR1 -> forall s b. s -> Step s b
Partial (s
sL, s
sR1)
Done c
bR -> forall s b. b -> Step s b
Done c
bR
initial :: m (Step (s, s) c)
initial = do
Step s c
r <- m (Step s c)
initialR
Step s b
rL <- m (Step s b)
initialL
case Step s c
r of
Partial s
sR ->
case Step s b
rL of
Done b
_ -> forall s b. b -> Step s b
Done forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m c
extractR s
sR
Partial s
sL -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s b. s -> Step s b
Partial (s
sL, s
sR)
Done c
b -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s b. b -> Step s b
Done c
b
step :: (s, s) -> a -> m (Step (s, s) c)
step (s
sL, s
sR) a
x = m (Step s b) -> s -> m (Step (s, s) c)
runStep (s -> a -> m (Step s b)
stepL s
sL a
x) s
sR
extract :: (a, s) -> m c
extract = s -> m c
extractR forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd
{-# INLINE drainBy #-}
drainBy :: Monad m => (a -> m b) -> Fold m a ()
drainBy :: forall (m :: * -> *) a b. Monad m => (a -> m b) -> Fold m a ()
drainBy a -> m b
f = forall (m :: * -> *) a b r.
Monad m =>
(a -> m b) -> Fold m b r -> Fold m a r
lmapM a -> m b
f forall (m :: * -> *) a. Monad m => Fold m a ()
drain
{-# INLINE last #-}
last :: Monad m => Fold m a (Maybe a)
last :: forall (m :: * -> *) a. Monad m => Fold m a (Maybe a)
last = forall (m :: * -> *) a.
Monad m =>
(a -> a -> a) -> Fold m a (Maybe a)
foldl1' (\a
_ a
x -> a
x)
{-# INLINE genericLength #-}
genericLength :: (Monad m, Num b) => Fold m a b
genericLength :: forall (m :: * -> *) b a. (Monad m, Num b) => Fold m a b
genericLength = forall (m :: * -> *) b a.
Monad m =>
(b -> a -> b) -> b -> Fold m a b
foldl' (\b
n a
_ -> b
n forall a. Num a => a -> a -> a
+ b
1) b
0
{-# INLINE length #-}
length :: Monad m => Fold m a Int
length :: forall (m :: * -> *) a. Monad m => Fold m a Int
length = forall (m :: * -> *) b a. (Monad m, Num b) => Fold m a b
genericLength
{-# INLINE sum #-}
sum :: (Monad m, Num a) => Fold m a a
sum :: forall (m :: * -> *) a. (Monad m, Num a) => Fold m a a
sum = forall (m :: * -> *) b a.
Monad m =>
(b -> a -> b) -> b -> Fold m a b
foldl' forall a. Num a => a -> a -> a
(+) a
0
{-# INLINE product #-}
product :: (Monad m, Num a, Eq a) => Fold m a a
product :: forall (m :: * -> *) a. (Monad m, Num a, Eq a) => Fold m a a
product = forall (m :: * -> *) b a.
Monad m =>
(b -> a -> Step b b) -> Step b b -> Fold m a b
mkFold_ forall {s} {b}. (Eq s, Num s, Num b) => s -> s -> Step s b
step (forall s b. s -> Step s b
Partial a
1)
where
step :: s -> s -> Step s b
step s
x s
a =
if s
a forall a. Eq a => a -> a -> Bool
== s
0
then forall s b. b -> Step s b
Done b
0
else forall s b. s -> Step s b
Partial forall a b. (a -> b) -> a -> b
$ s
x forall a. Num a => a -> a -> a
* s
a
{-# INLINE maximumBy #-}
maximumBy :: Monad m => (a -> a -> Ordering) -> Fold m a (Maybe a)
maximumBy :: forall (m :: * -> *) a.
Monad m =>
(a -> a -> Ordering) -> Fold m a (Maybe a)
maximumBy a -> a -> Ordering
cmp = forall (m :: * -> *) a.
Monad m =>
(a -> a -> a) -> Fold m a (Maybe a)
foldl1' a -> a -> a
max'
where
max' :: a -> a -> a
max' a
x a
y =
case a -> a -> Ordering
cmp a
x a
y of
Ordering
GT -> a
x
Ordering
_ -> a
y
{-# INLINE maximum #-}
maximum :: (Monad m, Ord a) => Fold m a (Maybe a)
maximum :: forall (m :: * -> *) a. (Monad m, Ord a) => Fold m a (Maybe a)
maximum = forall (m :: * -> *) a.
Monad m =>
(a -> a -> a) -> Fold m a (Maybe a)
foldl1' forall a. Ord a => a -> a -> a
max
{-# INLINE minimumBy #-}
minimumBy :: Monad m => (a -> a -> Ordering) -> Fold m a (Maybe a)
minimumBy :: forall (m :: * -> *) a.
Monad m =>
(a -> a -> Ordering) -> Fold m a (Maybe a)
minimumBy a -> a -> Ordering
cmp = forall (m :: * -> *) a.
Monad m =>
(a -> a -> a) -> Fold m a (Maybe a)
foldl1' a -> a -> a
min'
where
min' :: a -> a -> a
min' a
x a
y =
case a -> a -> Ordering
cmp a
x a
y of
Ordering
GT -> a
y
Ordering
_ -> a
x
{-# INLINE minimum #-}
minimum :: (Monad m, Ord a) => Fold m a (Maybe a)
minimum :: forall (m :: * -> *) a. (Monad m, Ord a) => Fold m a (Maybe a)
minimum = forall (m :: * -> *) a.
Monad m =>
(a -> a -> a) -> Fold m a (Maybe a)
foldl1' forall a. Ord a => a -> a -> a
min
{-# INLINE mean #-}
mean :: (Monad m, Fractional a) => Fold m a a
mean :: forall (m :: * -> *) a. (Monad m, Fractional a) => Fold m a a
mean = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {a} {b}. Tuple' a b -> a
done forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a.
Monad m =>
(b -> a -> b) -> b -> Fold m a b
foldl' forall {b}. Fractional b => Tuple' b b -> b -> Tuple' b b
step Tuple' a a
begin
where
begin :: Tuple' a a
begin = forall a b. a -> b -> Tuple' a b
Tuple' a
0 a
0
step :: Tuple' b b -> b -> Tuple' b b
step (Tuple' b
x b
n) b
y =
let n1 :: b
n1 = b
n forall a. Num a => a -> a -> a
+ b
1
in forall a b. a -> b -> Tuple' a b
Tuple' (b
x forall a. Num a => a -> a -> a
+ (b
y forall a. Num a => a -> a -> a
- b
x) forall a. Fractional a => a -> a -> a
/ b
n1) b
n1
done :: Tuple' a b -> a
done (Tuple' a
x b
_) = a
x
{-# INLINE variance #-}
variance :: (Monad m, Fractional a) => Fold m a a
variance :: forall (m :: * -> *) a. (Monad m, Fractional a) => Fold m a a
variance = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {a} {b}. Fractional a => Tuple3' a b a -> a
done forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a.
Monad m =>
(b -> a -> b) -> b -> Fold m a b
foldl' forall {c}. Fractional c => Tuple3' c c c -> c -> Tuple3' c c c
step Tuple3' a a a
begin
where
begin :: Tuple3' a a a
begin = forall a b c. a -> b -> c -> Tuple3' a b c
Tuple3' a
0 a
0 a
0
step :: Tuple3' c c c -> c -> Tuple3' c c c
step (Tuple3' c
n c
mean_ c
m2) c
x = forall a b c. a -> b -> c -> Tuple3' a b c
Tuple3' c
n' c
mean' c
m2'
where
n' :: c
n' = c
n forall a. Num a => a -> a -> a
+ c
1
mean' :: c
mean' = (c
n forall a. Num a => a -> a -> a
* c
mean_ forall a. Num a => a -> a -> a
+ c
x) forall a. Fractional a => a -> a -> a
/ (c
n forall a. Num a => a -> a -> a
+ c
1)
delta :: c
delta = c
x forall a. Num a => a -> a -> a
- c
mean_
m2' :: c
m2' = c
m2 forall a. Num a => a -> a -> a
+ c
delta forall a. Num a => a -> a -> a
* c
delta forall a. Num a => a -> a -> a
* c
n forall a. Fractional a => a -> a -> a
/ (c
n forall a. Num a => a -> a -> a
+ c
1)
done :: Tuple3' a b a -> a
done (Tuple3' a
n b
_ a
m2) = a
m2 forall a. Fractional a => a -> a -> a
/ a
n
{-# INLINE stdDev #-}
stdDev :: (Monad m, Floating a) => Fold m a a
stdDev :: forall (m :: * -> *) a. (Monad m, Floating a) => Fold m a a
stdDev = forall a. Floating a => a -> a
sqrt forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. (Monad m, Fractional a) => Fold m a a
variance
{-# INLINE rollingHashWithSalt #-}
rollingHashWithSalt :: (Monad m, Enum a) => Int64 -> Fold m a Int64
rollingHashWithSalt :: forall (m :: * -> *) a.
(Monad m, Enum a) =>
Int64 -> Fold m a Int64
rollingHashWithSalt = forall (m :: * -> *) b a.
Monad m =>
(b -> a -> b) -> b -> Fold m a b
foldl' forall {a}. Enum a => Int64 -> a -> Int64
step
where
k :: Int64
k = Int64
2891336453 :: Int64
step :: Int64 -> a -> Int64
step Int64
cksum a
a = Int64
cksum forall a. Num a => a -> a -> a
* Int64
k forall a. Num a => a -> a -> a
+ forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Enum a => a -> Int
fromEnum a
a)
{-# INLINE defaultSalt #-}
defaultSalt :: Int64
defaultSalt :: Int64
defaultSalt = -Int64
2578643520546668380
{-# INLINE rollingHash #-}
rollingHash :: (Monad m, Enum a) => Fold m a Int64
rollingHash :: forall (m :: * -> *) a. (Monad m, Enum a) => Fold m a Int64
rollingHash = forall (m :: * -> *) a.
(Monad m, Enum a) =>
Int64 -> Fold m a Int64
rollingHashWithSalt Int64
defaultSalt
{-# INLINE rollingHashFirstN #-}
rollingHashFirstN :: (Monad m, Enum a) => Int -> Fold m a Int64
rollingHashFirstN :: forall (m :: * -> *) a. (Monad m, Enum a) => Int -> Fold m a Int64
rollingHashFirstN Int
n = forall (m :: * -> *) a b.
Monad m =>
Int -> Fold m a b -> Fold m a b
take Int
n forall (m :: * -> *) a. (Monad m, Enum a) => Fold m a Int64
rollingHash
{-# INLINE sconcat #-}
sconcat :: (Monad m, Semigroup a) => a -> Fold m a a
sconcat :: forall (m :: * -> *) a. (Monad m, Semigroup a) => a -> Fold m a a
sconcat = forall (m :: * -> *) b a.
Monad m =>
(b -> a -> b) -> b -> Fold m a b
foldl' forall a. Semigroup a => a -> a -> a
(<>)
{-# INLINE mconcat #-}
mconcat ::
( Monad m
#if !MIN_VERSION_base(4,11,0)
, Semigroup a
#endif
, Monoid a) => Fold m a a
mconcat :: forall (m :: * -> *) a. (Monad m, Monoid a) => Fold m a a
mconcat = forall (m :: * -> *) a. (Monad m, Semigroup a) => a -> Fold m a a
sconcat forall a. Monoid a => a
mempty
{-# INLINE foldMap #-}
foldMap :: (Monad m, Monoid b
#if !MIN_VERSION_base(4,11,0)
, Semigroup b
#endif
) => (a -> b) -> Fold m a b
foldMap :: forall (m :: * -> *) b a.
(Monad m, Monoid b) =>
(a -> b) -> Fold m a b
foldMap a -> b
f = forall a b (m :: * -> *) r. (a -> b) -> Fold m b r -> Fold m a r
lmap a -> b
f forall (m :: * -> *) a. (Monad m, Monoid a) => Fold m a a
mconcat
{-# INLINE foldMapM #-}
foldMapM :: (Monad m, Monoid b) => (a -> m b) -> Fold m a b
foldMapM :: forall (m :: * -> *) b a.
(Monad m, Monoid b) =>
(a -> m b) -> Fold m a b
foldMapM a -> m b
act = forall (m :: * -> *) b a.
Monad m =>
(b -> a -> m b) -> m b -> Fold m a b
foldlM' b -> a -> m b
step (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty)
where
step :: b -> a -> m b
step b
m a
a = do
b
m' <- a -> m b
act a
a
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$! forall a. Monoid a => a -> a -> a
mappend b
m b
m'
{-# INLINE toListRev #-}
toListRev :: Monad m => Fold m a [a]
toListRev :: forall (m :: * -> *) a. Monad m => Fold m a [a]
toListRev = forall (m :: * -> *) b a.
Monad m =>
(b -> a -> b) -> b -> Fold m a b
foldl' (forall a b c. (a -> b -> c) -> b -> a -> c
flip (:)) []
{-# INLINE drainN #-}
drainN :: Monad m => Int -> Fold m a ()
drainN :: forall (m :: * -> *) a. Monad m => Int -> Fold m a ()
drainN Int
n = forall (m :: * -> *) a b.
Monad m =>
Int -> Fold m a b -> Fold m a b
take Int
n forall (m :: * -> *) a. Monad m => Fold m a ()
drain
{-# INLINE genericIndex #-}
genericIndex :: (Integral i, Monad m) => i -> Fold m a (Maybe a)
genericIndex :: forall i (m :: * -> *) a.
(Integral i, Monad m) =>
i -> Fold m a (Maybe a)
genericIndex i
i = forall (m :: * -> *) s a b.
Monad m =>
(s -> a -> Step s b) -> Step s b -> (s -> b) -> Fold m a b
mkFold forall {a}. i -> a -> Step i (Maybe a)
step (forall s b. s -> Step s b
Partial i
0) (forall a b. a -> b -> a
const forall a. Maybe a
Nothing)
where
step :: i -> a -> Step i (Maybe a)
step i
j a
a =
if i
i forall a. Eq a => a -> a -> Bool
== i
j
then forall s b. b -> Step s b
Done forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just a
a
else forall s b. s -> Step s b
Partial (i
j forall a. Num a => a -> a -> a
+ i
1)
{-# INLINE index #-}
index :: Monad m => Int -> Fold m a (Maybe a)
index :: forall (m :: * -> *) a. Monad m => Int -> Fold m a (Maybe a)
index = forall i (m :: * -> *) a.
(Integral i, Monad m) =>
i -> Fold m a (Maybe a)
genericIndex
{-# INLINE head #-}
head :: Monad m => Fold m a (Maybe a)
head :: forall (m :: * -> *) a. Monad m => Fold m a (Maybe a)
head = forall (m :: * -> *) b a.
Monad m =>
(b -> a -> Step b b) -> Step b b -> Fold m a b
mkFold_ (forall a b. a -> b -> a
const (forall s b. b -> Step s b
Done forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just)) (forall s b. s -> Step s b
Partial forall a. Maybe a
Nothing)
{-# INLINE find #-}
find :: Monad m => (a -> Bool) -> Fold m a (Maybe a)
find :: forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Fold m a (Maybe a)
find a -> Bool
predicate = forall (m :: * -> *) s a b.
Monad m =>
(s -> a -> Step s b) -> Step s b -> (s -> b) -> Fold m a b
mkFold () -> a -> Step () (Maybe a)
step (forall s b. s -> Step s b
Partial ()) (forall a b. a -> b -> a
const forall a. Maybe a
Nothing)
where
step :: () -> a -> Step () (Maybe a)
step () a
a =
if a -> Bool
predicate a
a
then forall s b. b -> Step s b
Done (forall a. a -> Maybe a
Just a
a)
else forall s b. s -> Step s b
Partial ()
{-# INLINE lookup #-}
lookup :: (Eq a, Monad m) => a -> Fold m (a,b) (Maybe b)
lookup :: forall a (m :: * -> *) b.
(Eq a, Monad m) =>
a -> Fold m (a, b) (Maybe b)
lookup a
a0 = forall (m :: * -> *) s a b.
Monad m =>
(s -> a -> Step s b) -> Step s b -> (s -> b) -> Fold m a b
mkFold forall {a}. () -> (a, a) -> Step () (Maybe a)
step (forall s b. s -> Step s b
Partial ()) (forall a b. a -> b -> a
const forall a. Maybe a
Nothing)
where
step :: () -> (a, a) -> Step () (Maybe a)
step () (a
a, a
b) =
if a
a forall a. Eq a => a -> a -> Bool
== a
a0
then forall s b. b -> Step s b
Done forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just a
b
else forall s b. s -> Step s b
Partial ()
{-# INLINE findIndex #-}
findIndex :: Monad m => (a -> Bool) -> Fold m a (Maybe Int)
findIndex :: forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Fold m a (Maybe Int)
findIndex a -> Bool
predicate = forall (m :: * -> *) s a b.
Monad m =>
(s -> a -> Step s b) -> Step s b -> (s -> b) -> Fold m a b
mkFold forall {s}. Num s => s -> a -> Step s (Maybe s)
step (forall s b. s -> Step s b
Partial Int
0) (forall a b. a -> b -> a
const forall a. Maybe a
Nothing)
where
step :: s -> a -> Step s (Maybe s)
step s
i a
a =
if a -> Bool
predicate a
a
then forall s b. b -> Step s b
Done forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just s
i
else forall s b. s -> Step s b
Partial (s
i forall a. Num a => a -> a -> a
+ s
1)
{-# INLINE elemIndex #-}
elemIndex :: (Eq a, Monad m) => a -> Fold m a (Maybe Int)
elemIndex :: forall a (m :: * -> *).
(Eq a, Monad m) =>
a -> Fold m a (Maybe Int)
elemIndex a
a = forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Fold m a (Maybe Int)
findIndex (a
a forall a. Eq a => a -> a -> Bool
==)
{-# INLINE null #-}
null :: Monad m => Fold m a Bool
null :: forall (m :: * -> *) a. Monad m => Fold m a Bool
null = forall (m :: * -> *) s a b.
Monad m =>
(s -> a -> Step s b) -> Step s b -> (s -> b) -> Fold m a b
mkFold (\() a
_ -> forall s b. b -> Step s b
Done Bool
False) (forall s b. s -> Step s b
Partial ()) (forall a b. a -> b -> a
const Bool
True)
{-# INLINE any #-}
any :: Monad m => (a -> Bool) -> Fold m a Bool
any :: forall (m :: * -> *) a. Monad m => (a -> Bool) -> Fold m a Bool
any a -> Bool
predicate = forall (m :: * -> *) b a.
Monad m =>
(b -> a -> Step b b) -> Step b b -> Fold m a b
mkFold_ forall {p}. p -> a -> Step Bool Bool
step forall {b}. Step Bool b
initial
where
initial :: Step Bool b
initial = forall s b. s -> Step s b
Partial Bool
False
step :: p -> a -> Step Bool Bool
step p
_ a
a =
if a -> Bool
predicate a
a
then forall s b. b -> Step s b
Done Bool
True
else forall s b. s -> Step s b
Partial Bool
False
{-# INLINE elem #-}
elem :: (Eq a, Monad m) => a -> Fold m a Bool
elem :: forall a (m :: * -> *). (Eq a, Monad m) => a -> Fold m a Bool
elem a
a = forall (m :: * -> *) a. Monad m => (a -> Bool) -> Fold m a Bool
any (a
a forall a. Eq a => a -> a -> Bool
==)
{-# INLINE all #-}
all :: Monad m => (a -> Bool) -> Fold m a Bool
all :: forall (m :: * -> *) a. Monad m => (a -> Bool) -> Fold m a Bool
all a -> Bool
predicate = forall (m :: * -> *) b a.
Monad m =>
(b -> a -> Step b b) -> Step b b -> Fold m a b
mkFold_ forall {p}. p -> a -> Step Bool Bool
step forall {b}. Step Bool b
initial
where
initial :: Step Bool b
initial = forall s b. s -> Step s b
Partial Bool
True
step :: p -> a -> Step Bool Bool
step p
_ a
a =
if a -> Bool
predicate a
a
then forall s b. s -> Step s b
Partial Bool
True
else forall s b. b -> Step s b
Done Bool
False
{-# INLINE notElem #-}
notElem :: (Eq a, Monad m) => a -> Fold m a Bool
notElem :: forall a (m :: * -> *). (Eq a, Monad m) => a -> Fold m a Bool
notElem a
a = forall (m :: * -> *) a. Monad m => (a -> Bool) -> Fold m a Bool
all (a
a forall a. Eq a => a -> a -> Bool
/=)
{-# INLINE and #-}
and :: Monad m => Fold m Bool Bool
and :: forall (m :: * -> *). Monad m => Fold m Bool Bool
and = forall (m :: * -> *) a. Monad m => (a -> Bool) -> Fold m a Bool
all (forall a. Eq a => a -> a -> Bool
== Bool
True)
{-# INLINE or #-}
or :: Monad m => Fold m Bool Bool
or :: forall (m :: * -> *). Monad m => Fold m Bool Bool
or = forall (m :: * -> *) a. Monad m => (a -> Bool) -> Fold m a Bool
any (forall a. Eq a => a -> a -> Bool
== Bool
True)
{-# INLINE splitAt #-}
splitAt
:: Monad m
=> Int
-> Fold m a b
-> Fold m a c
-> Fold m a (b, c)
splitAt :: forall (m :: * -> *) a b c.
Monad m =>
Int -> Fold m a b -> Fold m a c -> Fold m a (b, c)
splitAt Int
n Fold m a b
fld = forall (m :: * -> *) a b c x.
Monad m =>
(a -> b -> c) -> Fold m x a -> Fold m x b -> Fold m x c
serialWith (,) (forall (m :: * -> *) a b.
Monad m =>
Int -> Fold m a b -> Fold m a b
take Int
n Fold m a b
fld)
{-# INLINE takeEndBy_ #-}
takeEndBy_ :: Monad m => (a -> Bool) -> Fold m a b -> Fold m a b
takeEndBy_ :: forall (m :: * -> *) a r.
Monad m =>
(a -> Bool) -> Fold m a r -> Fold m a r
takeEndBy_ a -> Bool
predicate (Fold s -> a -> m (Step s b)
fstep m (Step s b)
finitial s -> m b
fextract) =
forall (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> m (Step s b) -> (s -> m b) -> Fold m a b
Fold s -> a -> m (Step s b)
step m (Step s b)
finitial s -> m b
fextract
where
step :: s -> a -> m (Step s b)
step s
s a
a =
if Bool -> Bool
not (a -> Bool
predicate a
a)
then s -> a -> m (Step s b)
fstep s
s a
a
else forall s b. b -> Step s b
Done forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m b
fextract s
s
{-# INLINE takeEndBy #-}
takeEndBy :: Monad m => (a -> Bool) -> Fold m a b -> Fold m a b
takeEndBy :: forall (m :: * -> *) a r.
Monad m =>
(a -> Bool) -> Fold m a r -> Fold m a r
takeEndBy a -> Bool
predicate (Fold s -> a -> m (Step s b)
fstep m (Step s b)
finitial s -> m b
fextract) =
forall (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> m (Step s b) -> (s -> m b) -> Fold m a b
Fold s -> a -> m (Step s b)
step m (Step s b)
finitial s -> m b
fextract
where
step :: s -> a -> m (Step s b)
step s
s a
a = do
Step s b
res <- s -> a -> m (Step s b)
fstep s
s a
a
if Bool -> Bool
not (a -> Bool
predicate a
a)
then forall (m :: * -> *) a. Monad m => a -> m a
return Step s b
res
else do
case Step s b
res of
Partial s
s1 -> forall s b. b -> Step s b
Done forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m b
fextract s
s1
Done b
b -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s b. b -> Step s b
Done b
b
{-# INLINE tee #-}
tee :: Monad m => Fold m a b -> Fold m a c -> Fold m a (b,c)
tee :: forall (m :: * -> *) a b c.
Monad m =>
Fold m a b -> Fold m a c -> Fold m a (b, c)
tee = forall (m :: * -> *) a b c x.
Monad m =>
(a -> b -> c) -> Fold m x a -> Fold m x b -> Fold m x c
teeWith (,)
{-# INLINE distribute #-}
distribute :: Monad m => [Fold m a b] -> Fold m a [b]
distribute :: forall (m :: * -> *) a b. Monad m => [Fold m a b] -> Fold m a [b]
distribute = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Prelude.foldr (forall (m :: * -> *) a b c x.
Monad m =>
(a -> b -> c) -> Fold m x a -> Fold m x b -> Fold m x c
teeWith (:)) (forall (m :: * -> *) b a. Applicative m => b -> Fold m a b
fromPure [])
{-# INLINE partitionByMUsing #-}
partitionByMUsing :: Monad m =>
( (x -> y -> (x, y))
-> Fold m (Either b c) x
-> Fold m (Either b c) y
-> Fold m (Either b c) (x, y)
)
-> (a -> m (Either b c))
-> Fold m b x
-> Fold m c y
-> Fold m a (x, y)
partitionByMUsing :: forall (m :: * -> *) x y b c a.
Monad m =>
((x -> y -> (x, y))
-> Fold m (Either b c) x
-> Fold m (Either b c) y
-> Fold m (Either b c) (x, y))
-> (a -> m (Either b c))
-> Fold m b x
-> Fold m c y
-> Fold m a (x, y)
partitionByMUsing (x -> y -> (x, y))
-> Fold m (Either b c) x
-> Fold m (Either b c) y
-> Fold m (Either b c) (x, y)
t a -> m (Either b c)
f Fold m b x
fld1 Fold m c y
fld2 =
let l :: Fold m (Either b b) x
l = forall a b (m :: * -> *) r. (a -> b) -> Fold m b r -> Fold m a r
lmap (forall a b. a -> Either a b -> a
fromLeft forall a. HasCallStack => a
undefined) Fold m b x
fld1
r :: Fold m (Either a c) y
r = forall a b (m :: * -> *) r. (a -> b) -> Fold m b r -> Fold m a r
lmap (forall b a. b -> Either a b -> b
fromRight forall a. HasCallStack => a
undefined) Fold m c y
fld2
in forall (m :: * -> *) a b r.
Monad m =>
(a -> m b) -> Fold m b r -> Fold m a r
lmapM a -> m (Either b c)
f ((x -> y -> (x, y))
-> Fold m (Either b c) x
-> Fold m (Either b c) y
-> Fold m (Either b c) (x, y)
t (,) (forall (m :: * -> *) a r.
Monad m =>
(a -> Bool) -> Fold m a r -> Fold m a r
filter forall a b. Either a b -> Bool
isLeft forall {b}. Fold m (Either b b) x
l) (forall (m :: * -> *) a r.
Monad m =>
(a -> Bool) -> Fold m a r -> Fold m a r
filter forall a b. Either a b -> Bool
isRight forall {a}. Fold m (Either a c) y
r))
{-# INLINE partitionByM #-}
partitionByM :: Monad m
=> (a -> m (Either b c)) -> Fold m b x -> Fold m c y -> Fold m a (x, y)
partitionByM :: forall (m :: * -> *) a b c x y.
Monad m =>
(a -> m (Either b c))
-> Fold m b x -> Fold m c y -> Fold m a (x, y)
partitionByM = forall (m :: * -> *) x y b c a.
Monad m =>
((x -> y -> (x, y))
-> Fold m (Either b c) x
-> Fold m (Either b c) y
-> Fold m (Either b c) (x, y))
-> (a -> m (Either b c))
-> Fold m b x
-> Fold m c y
-> Fold m a (x, y)
partitionByMUsing forall (m :: * -> *) a b c x.
Monad m =>
(a -> b -> c) -> Fold m x a -> Fold m x b -> Fold m x c
teeWith
{-# INLINE partitionByFstM #-}
partitionByFstM :: Monad m
=> (a -> m (Either b c)) -> Fold m b x -> Fold m c y -> Fold m a (x, y)
partitionByFstM :: forall (m :: * -> *) a b c x y.
Monad m =>
(a -> m (Either b c))
-> Fold m b x -> Fold m c y -> Fold m a (x, y)
partitionByFstM = forall (m :: * -> *) x y b c a.
Monad m =>
((x -> y -> (x, y))
-> Fold m (Either b c) x
-> Fold m (Either b c) y
-> Fold m (Either b c) (x, y))
-> (a -> m (Either b c))
-> Fold m b x
-> Fold m c y
-> Fold m a (x, y)
partitionByMUsing forall (m :: * -> *) a b c x.
Monad m =>
(a -> b -> c) -> Fold m x a -> Fold m x b -> Fold m x c
teeWithFst
{-# INLINE partitionByMinM #-}
partitionByMinM :: Monad m =>
(a -> m (Either b c)) -> Fold m b x -> Fold m c y -> Fold m a (x, y)
partitionByMinM :: forall (m :: * -> *) a b c x y.
Monad m =>
(a -> m (Either b c))
-> Fold m b x -> Fold m c y -> Fold m a (x, y)
partitionByMinM = forall (m :: * -> *) x y b c a.
Monad m =>
((x -> y -> (x, y))
-> Fold m (Either b c) x
-> Fold m (Either b c) y
-> Fold m (Either b c) (x, y))
-> (a -> m (Either b c))
-> Fold m b x
-> Fold m c y
-> Fold m a (x, y)
partitionByMUsing forall (m :: * -> *) a b c x.
Monad m =>
(a -> b -> c) -> Fold m x a -> Fold m x b -> Fold m x c
teeWithMin
{-# INLINE partitionBy #-}
partitionBy :: Monad m
=> (a -> Either b c) -> Fold m b x -> Fold m c y -> Fold m a (x, y)
partitionBy :: forall (m :: * -> *) a b c x y.
Monad m =>
(a -> Either b c) -> Fold m b x -> Fold m c y -> Fold m a (x, y)
partitionBy a -> Either b c
f = forall (m :: * -> *) a b c x y.
Monad m =>
(a -> m (Either b c))
-> Fold m b x -> Fold m c y -> Fold m a (x, y)
partitionByM (forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Either b c
f)
{-# INLINE partition #-}
partition :: Monad m
=> Fold m b x -> Fold m c y -> Fold m (Either b c) (x, y)
partition :: forall (m :: * -> *) b x c y.
Monad m =>
Fold m b x -> Fold m c y -> Fold m (Either b c) (x, y)
partition = forall (m :: * -> *) a b c x y.
Monad m =>
(a -> Either b c) -> Fold m b x -> Fold m c y -> Fold m a (x, y)
partitionBy forall a. a -> a
id
{-# INLINE demuxWith #-}
demuxWith :: (Monad m, Ord k)
=> (a -> (k, a')) -> Map k (Fold m a' b) -> Fold m a (Map k b)
demuxWith :: forall (m :: * -> *) k a a' b.
(Monad m, Ord k) =>
(a -> (k, a')) -> Map k (Fold m a' b) -> Fold m a (Map k b)
demuxWith a -> (k, a')
f Map k (Fold m a' b)
kv = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) k a a' b c.
(Monad m, Ord k) =>
(a -> (k, a'))
-> Map k (Fold m a' b) -> Fold m (k, a') c -> Fold m a (Map k b, c)
demuxDefaultWith a -> (k, a')
f Map k (Fold m a' b)
kv forall (m :: * -> *) a. Monad m => Fold m a ()
drain
{-# INLINE demux #-}
demux :: (Monad m, Ord k)
=> Map k (Fold m a b) -> Fold m (k, a) (Map k b)
demux :: forall (m :: * -> *) k a b.
(Monad m, Ord k) =>
Map k (Fold m a b) -> Fold m (k, a) (Map k b)
demux = forall (m :: * -> *) k a a' b.
(Monad m, Ord k) =>
(a -> (k, a')) -> Map k (Fold m a' b) -> Fold m a (Map k b)
demuxWith forall a. a -> a
id
data DemuxState s b doneMap runMap =
DemuxMapAndDefault !s !doneMap !runMap
| DemuxOnlyMap b !doneMap !runMap
| DemuxOnlyDefault s !doneMap
{-# INLINE demuxDefaultWith #-}
demuxDefaultWith :: (Monad m, Ord k)
=> (a -> (k, a'))
-> Map k (Fold m a' b)
-> Fold m (k, a') c
-> Fold m a (Map k b, c)
demuxDefaultWith :: forall (m :: * -> *) k a a' b c.
(Monad m, Ord k) =>
(a -> (k, a'))
-> Map k (Fold m a' b) -> Fold m (k, a') c -> Fold m a (Map k b, c)
demuxDefaultWith a -> (k, a')
f Map k (Fold m a' b)
kv (Fold s -> (k, a') -> m (Step s c)
dstep m (Step s c)
dinitial s -> m c
dextract) =
forall (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> m (Step s b) -> (s -> m b) -> Fold m a b
Fold forall {b}.
DemuxState s c (Map k b) (Map k (Fold m a' b))
-> a
-> m (Step
(DemuxState s c (Map k b) (Map k (Fold m a' b))) (Map k b, c))
step m (Step
(DemuxState s c (Map k b) (Map k (Fold m a' b))) (Map k b, c))
initial forall {k} {b} {a}.
Ord k =>
DemuxState s c (Map k b) (Map k (Fold m a b)) -> m (Map k b, c)
extract
where
initial :: m (Step
(DemuxState s c (Map k b) (Map k (Fold m a' b))) (Map k b, c))
initial = do
let runInit :: Fold m a b -> m (Either' b (Fold m a b))
runInit (Fold s -> a -> m (Step s b)
step1 m (Step s b)
initial1 s -> m b
done1) = do
Step s b
r <- m (Step s b)
initial1
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ case Step s b
r of
Partial s
_ -> forall a b. b -> Either' a b
Right' (forall (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> m (Step s b) -> (s -> m b) -> Fold m a b
Fold s -> a -> m (Step s b)
step1 (forall (m :: * -> *) a. Monad m => a -> m a
return Step s b
r) s -> m b
done1)
Done b
b -> forall a b. a -> Either' a b
Left' b
b
Map k (Either' b (Fold m a' b))
kv1 <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
Prelude.mapM forall {m :: * -> *} {a} {b}.
Monad m =>
Fold m a b -> m (Either' b (Fold m a b))
runInit Map k (Fold m a' b)
kv
let runMap :: Map k (Fold m a' b)
runMap = forall a b k. (a -> b) -> Map k a -> Map k b
Map.map forall a b. Either' a b -> b
fromRight' forall a b. (a -> b) -> a -> b
$ forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter forall a b. Either' a b -> Bool
isRight' Map k (Either' b (Fold m a' b))
kv1
doneMap :: Map k b
doneMap = forall a b k. (a -> b) -> Map k a -> Map k b
Map.map forall a b. Either' a b -> a
fromLeft' forall a b. (a -> b) -> a -> b
$ forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter forall a b. Either' a b -> Bool
isLeft' Map k (Either' b (Fold m a' b))
kv1
Step s c
dres <- m (Step s c)
dinitial
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ case Step s c
dres of
Partial s
s ->
forall s b. s -> Step s b
Partial
forall a b. (a -> b) -> a -> b
$ if forall k a. Map k a -> Int
Map.size Map k (Fold m a' b)
runMap forall a. Ord a => a -> a -> Bool
> Int
0
then forall s b doneMap runMap.
s -> doneMap -> runMap -> DemuxState s b doneMap runMap
DemuxMapAndDefault s
s Map k b
doneMap Map k (Fold m a' b)
runMap
else forall s b doneMap runMap.
s -> doneMap -> DemuxState s b doneMap runMap
DemuxOnlyDefault s
s Map k b
doneMap
Done c
b ->
if forall k a. Map k a -> Int
Map.size Map k (Fold m a' b)
runMap forall a. Ord a => a -> a -> Bool
> Int
0
then forall s b. s -> Step s b
Partial forall a b. (a -> b) -> a -> b
$ forall s b doneMap runMap.
b -> doneMap -> runMap -> DemuxState s b doneMap runMap
DemuxOnlyMap c
b Map k b
doneMap Map k (Fold m a' b)
runMap
else forall s b. b -> Step s b
Done (Map k b
doneMap, c
b)
{-# INLINE runFold #-}
runFold :: (Map p b -> Map p (Fold m a b) -> s)
-> (Map p b -> Step s b)
-> Map p b
-> Map p (Fold m a b)
-> Fold m a b
-> p
-> a
-> m (Step s b)
runFold Map p b -> Map p (Fold m a b) -> s
fPartial Map p b -> Step s b
fDone Map p b
doneMap Map p (Fold m a b)
runMap (Fold s -> a -> m (Step s b)
step1 m (Step s b)
initial1 s -> m b
done1) p
k a
a1 = do
Step s b
resi <- m (Step s b)
initial1
case Step s b
resi of
Partial s
st -> do
Step s b
res <- s -> a -> m (Step s b)
step1 s
st a
a1
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ case Step s b
res of
Partial s
s ->
let fld :: Fold m a b
fld = forall (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> m (Step s b) -> (s -> m b) -> Fold m a b
Fold s -> a -> m (Step s b)
step1 (forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s b. s -> Step s b
Partial s
s) s -> m b
done1
runMap1 :: Map p (Fold m a b)
runMap1 = forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert p
k Fold m a b
fld Map p (Fold m a b)
runMap
in forall s b. s -> Step s b
Partial forall a b. (a -> b) -> a -> b
$ Map p b -> Map p (Fold m a b) -> s
fPartial Map p b
doneMap Map p (Fold m a b)
runMap1
Done b
b -> do
let runMap1 :: Map p (Fold m a b)
runMap1 = forall k a. Ord k => k -> Map k a -> Map k a
Map.delete p
k Map p (Fold m a b)
runMap
doneMap1 :: Map p b
doneMap1 = forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert p
k b
b Map p b
doneMap
if forall k a. Map k a -> Int
Map.size Map p (Fold m a b)
runMap1 forall a. Eq a => a -> a -> Bool
== Int
0
then Map p b -> Step s b
fDone Map p b
doneMap1
else forall s b. s -> Step s b
Partial forall a b. (a -> b) -> a -> b
$ Map p b -> Map p (Fold m a b) -> s
fPartial Map p b
doneMap1 Map p (Fold m a b)
runMap1
Done b
_ -> forall a. HasCallStack => [Char] -> a
error [Char]
"Bug: demuxDefaultWith: Done fold"
step :: DemuxState s c (Map k b) (Map k (Fold m a' b))
-> a
-> m (Step
(DemuxState s c (Map k b) (Map k (Fold m a' b))) (Map k b, c))
step (DemuxMapAndDefault s
dacc Map k b
doneMap Map k (Fold m a' b)
runMap) a
a = do
let (k
k, a'
a1) = a -> (k, a')
f a
a
case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup k
k Map k (Fold m a' b)
runMap of
Maybe (Fold m a' b)
Nothing -> do
Step s c
res <- s -> (k, a') -> m (Step s c)
dstep s
dacc (k
k, a'
a1)
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ forall s b. s -> Step s b
Partial
forall a b. (a -> b) -> a -> b
$ case Step s c
res of
Partial s
s -> forall s b doneMap runMap.
s -> doneMap -> runMap -> DemuxState s b doneMap runMap
DemuxMapAndDefault s
s Map k b
doneMap Map k (Fold m a' b)
runMap
Done c
b -> forall s b doneMap runMap.
b -> doneMap -> runMap -> DemuxState s b doneMap runMap
DemuxOnlyMap c
b Map k b
doneMap Map k (Fold m a' b)
runMap
Just Fold m a' b
fld ->
forall {m :: * -> *} {p} {b} {a} {s} {b}.
(Monad m, Ord p) =>
(Map p b -> Map p (Fold m a b) -> s)
-> (Map p b -> Step s b)
-> Map p b
-> Map p (Fold m a b)
-> Fold m a b
-> p
-> a
-> m (Step s b)
runFold
(forall s b doneMap runMap.
s -> doneMap -> runMap -> DemuxState s b doneMap runMap
DemuxMapAndDefault s
dacc)
(forall s b. s -> Step s b
Partial forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s b doneMap runMap.
s -> doneMap -> DemuxState s b doneMap runMap
DemuxOnlyDefault s
dacc)
Map k b
doneMap Map k (Fold m a' b)
runMap Fold m a' b
fld k
k a'
a1
step (DemuxOnlyMap c
dval Map k b
doneMap Map k (Fold m a' b)
runMap) a
a = do
let (k
k, a'
a1) = a -> (k, a')
f a
a
case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup k
k Map k (Fold m a' b)
runMap of
Maybe (Fold m a' b)
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s b. s -> Step s b
Partial forall a b. (a -> b) -> a -> b
$ forall s b doneMap runMap.
b -> doneMap -> runMap -> DemuxState s b doneMap runMap
DemuxOnlyMap c
dval Map k b
doneMap Map k (Fold m a' b)
runMap
Just Fold m a' b
fld ->
forall {m :: * -> *} {p} {b} {a} {s} {b}.
(Monad m, Ord p) =>
(Map p b -> Map p (Fold m a b) -> s)
-> (Map p b -> Step s b)
-> Map p b
-> Map p (Fold m a b)
-> Fold m a b
-> p
-> a
-> m (Step s b)
runFold
(forall s b doneMap runMap.
b -> doneMap -> runMap -> DemuxState s b doneMap runMap
DemuxOnlyMap c
dval)
(forall s b. b -> Step s b
Done forall b c a. (b -> c) -> (a -> b) -> a -> c
. (, c
dval))
Map k b
doneMap Map k (Fold m a' b)
runMap Fold m a' b
fld k
k a'
a1
step (DemuxOnlyDefault s
dacc Map k b
doneMap) a
a = do
let (k
k, a'
a1) = a -> (k, a')
f a
a
Step s c
res <- s -> (k, a') -> m (Step s c)
dstep s
dacc (k
k, a'
a1)
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ case Step s c
res of
Partial s
s -> forall s b. s -> Step s b
Partial forall a b. (a -> b) -> a -> b
$ forall s b doneMap runMap.
s -> doneMap -> DemuxState s b doneMap runMap
DemuxOnlyDefault s
s Map k b
doneMap
Done c
b -> forall s b. b -> Step s b
Done (Map k b
doneMap, c
b)
runExtract :: Fold m a b -> m b
runExtract (Fold s -> a -> m (Step s b)
_ m (Step s b)
initial1 s -> m b
done1) = do
Step s b
res <- m (Step s b)
initial1
case Step s b
res of
Partial s
s -> s -> m b
done1 s
s
Done b
b -> forall (m :: * -> *) a. Monad m => a -> m a
return b
b
extract :: DemuxState s c (Map k b) (Map k (Fold m a b)) -> m (Map k b, c)
extract (DemuxMapAndDefault s
dacc Map k b
doneMap Map k (Fold m a b)
runMap) = do
c
b <- s -> m c
dextract s
dacc
Map k b
runMap1 <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
Prelude.mapM forall {m :: * -> *} {a} {b}. Monad m => Fold m a b -> m b
runExtract Map k (Fold m a b)
runMap
forall (m :: * -> *) a. Monad m => a -> m a
return (Map k b
doneMap forall k a. Ord k => Map k a -> Map k a -> Map k a
`Map.union` Map k b
runMap1, c
b)
extract (DemuxOnlyMap c
dval Map k b
doneMap Map k (Fold m a b)
runMap) = do
Map k b
runMap1 <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
Prelude.mapM forall {m :: * -> *} {a} {b}. Monad m => Fold m a b -> m b
runExtract Map k (Fold m a b)
runMap
forall (m :: * -> *) a. Monad m => a -> m a
return (Map k b
doneMap forall k a. Ord k => Map k a -> Map k a -> Map k a
`Map.union` Map k b
runMap1, c
dval)
extract (DemuxOnlyDefault s
dacc Map k b
doneMap) = do
c
b <- s -> m c
dextract s
dacc
forall (m :: * -> *) a. Monad m => a -> m a
return (Map k b
doneMap, c
b)
{-# INLINE demuxDefault #-}
demuxDefault :: (Monad m, Ord k)
=> Map k (Fold m a b) -> Fold m (k, a) b -> Fold m (k, a) (Map k b, b)
demuxDefault :: forall (m :: * -> *) k a b.
(Monad m, Ord k) =>
Map k (Fold m a b) -> Fold m (k, a) b -> Fold m (k, a) (Map k b, b)
demuxDefault = forall (m :: * -> *) k a a' b c.
(Monad m, Ord k) =>
(a -> (k, a'))
-> Map k (Fold m a' b) -> Fold m (k, a') c -> Fold m a (Map k b, c)
demuxDefaultWith forall a. a -> a
id
{-# INLINE classifyWith #-}
classifyWith :: (Monad m, Ord k) => (a -> k) -> Fold m a b -> Fold m a (Map k b)
classifyWith :: forall (m :: * -> *) k a b.
(Monad m, Ord k) =>
(a -> k) -> Fold m a b -> Fold m a (Map k b)
classifyWith a -> k
f (Fold s -> a -> m (Step s b)
step1 m (Step s b)
initial1 s -> m b
extract1) =
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> Fold m a b -> Fold m a c
rmapM Map k (Either' s b) -> m (Map k b)
extract forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a.
Monad m =>
(b -> a -> m b) -> m b -> Fold m a b
foldlM' Map k (Either' s b) -> a -> m (Map k (Either' s b))
step forall {k} {a}. m (Map k a)
initial
where
initial :: m (Map k a)
initial = forall (m :: * -> *) a. Monad m => a -> m a
return forall k a. Map k a
Map.empty
step :: Map k (Either' s b) -> a -> m (Map k (Either' s b))
step Map k (Either' s b)
kv a
a =
case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup k
k Map k (Either' s b)
kv of
Maybe (Either' s b)
Nothing -> do
Step s b
x <- m (Step s b)
initial1
case Step s b
x of
Partial s
s -> do
Step s b
r <- s -> a -> m (Step s b)
step1 s
s a
a
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> b -> a -> c
flip (forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert k
k) Map k (Either' s b)
kv
forall a b. (a -> b) -> a -> b
$ case Step s b
r of
Partial s
s1 -> forall a b. a -> Either' a b
Left' s
s1
Done b
b -> forall a b. b -> Either' a b
Right' b
b
Done b
b -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert k
k (forall a b. b -> Either' a b
Right' b
b) Map k (Either' s b)
kv
Just Either' s b
x -> do
case Either' s b
x of
Left' s
s -> do
Step s b
r <- s -> a -> m (Step s b)
step1 s
s a
a
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> b -> a -> c
flip (forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert k
k) Map k (Either' s b)
kv
forall a b. (a -> b) -> a -> b
$ case Step s b
r of
Partial s
s1 -> forall a b. a -> Either' a b
Left' s
s1
Done b
b -> forall a b. b -> Either' a b
Right' b
b
Right' b
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return Map k (Either' s b)
kv
where
k :: k
k = a -> k
f a
a
extract :: Map k (Either' s b) -> m (Map k b)
extract =
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
Prelude.mapM
(\case
Left' s
s -> s -> m b
extract1 s
s
Right' b
b -> forall (m :: * -> *) a. Monad m => a -> m a
return b
b)
{-# INLINE classify #-}
classify :: (Monad m, Ord k) => Fold m a b -> Fold m (k, a) (Map k b)
classify :: forall (m :: * -> *) k a b.
(Monad m, Ord k) =>
Fold m a b -> Fold m (k, a) (Map k b)
classify Fold m a b
fld = forall (m :: * -> *) k a b.
(Monad m, Ord k) =>
(a -> k) -> Fold m a b -> Fold m a (Map k b)
classifyWith forall a b. (a, b) -> a
fst (forall a b (m :: * -> *) r. (a -> b) -> Fold m b r -> Fold m a r
lmap forall a b. (a, b) -> b
snd Fold m a b
fld)
{-# INLINE unzipWithMUsing #-}
unzipWithMUsing :: Monad m =>
( (x -> y -> (x, y))
-> Fold m (b, c) x
-> Fold m (b, c) y
-> Fold m (b, c) (x, y)
)
-> (a -> m (b, c))
-> Fold m b x
-> Fold m c y
-> Fold m a (x, y)
unzipWithMUsing :: forall (m :: * -> *) x y b c a.
Monad m =>
((x -> y -> (x, y))
-> Fold m (b, c) x -> Fold m (b, c) y -> Fold m (b, c) (x, y))
-> (a -> m (b, c)) -> Fold m b x -> Fold m c y -> Fold m a (x, y)
unzipWithMUsing (x -> y -> (x, y))
-> Fold m (b, c) x -> Fold m (b, c) y -> Fold m (b, c) (x, y)
t a -> m (b, c)
f Fold m b x
fld1 Fold m c y
fld2 =
let f1 :: Fold m (b, b) x
f1 = forall a b (m :: * -> *) r. (a -> b) -> Fold m b r -> Fold m a r
lmap forall a b. (a, b) -> a
fst Fold m b x
fld1
f2 :: Fold m (a, c) y
f2 = forall a b (m :: * -> *) r. (a -> b) -> Fold m b r -> Fold m a r
lmap forall a b. (a, b) -> b
snd Fold m c y
fld2
in forall (m :: * -> *) a b r.
Monad m =>
(a -> m b) -> Fold m b r -> Fold m a r
lmapM a -> m (b, c)
f ((x -> y -> (x, y))
-> Fold m (b, c) x -> Fold m (b, c) y -> Fold m (b, c) (x, y)
t (,) forall {b}. Fold m (b, b) x
f1 forall {a}. Fold m (a, c) y
f2)
{-# INLINE unzipWithM #-}
unzipWithM :: Monad m
=> (a -> m (b,c)) -> Fold m b x -> Fold m c y -> Fold m a (x,y)
unzipWithM :: forall (m :: * -> *) a b c x y.
Monad m =>
(a -> m (b, c)) -> Fold m b x -> Fold m c y -> Fold m a (x, y)
unzipWithM = forall (m :: * -> *) x y b c a.
Monad m =>
((x -> y -> (x, y))
-> Fold m (b, c) x -> Fold m (b, c) y -> Fold m (b, c) (x, y))
-> (a -> m (b, c)) -> Fold m b x -> Fold m c y -> Fold m a (x, y)
unzipWithMUsing forall (m :: * -> *) a b c x.
Monad m =>
(a -> b -> c) -> Fold m x a -> Fold m x b -> Fold m x c
teeWith
{-# INLINE unzipWithFstM #-}
unzipWithFstM :: Monad m =>
(a -> m (b, c)) -> Fold m b x -> Fold m c y -> Fold m a (x, y)
unzipWithFstM :: forall (m :: * -> *) a b c x y.
Monad m =>
(a -> m (b, c)) -> Fold m b x -> Fold m c y -> Fold m a (x, y)
unzipWithFstM = forall (m :: * -> *) x y b c a.
Monad m =>
((x -> y -> (x, y))
-> Fold m (b, c) x -> Fold m (b, c) y -> Fold m (b, c) (x, y))
-> (a -> m (b, c)) -> Fold m b x -> Fold m c y -> Fold m a (x, y)
unzipWithMUsing forall (m :: * -> *) a b c x.
Monad m =>
(a -> b -> c) -> Fold m x a -> Fold m x b -> Fold m x c
teeWithFst
{-# INLINE unzipWithMinM #-}
unzipWithMinM :: Monad m =>
(a -> m (b,c)) -> Fold m b x -> Fold m c y -> Fold m a (x,y)
unzipWithMinM :: forall (m :: * -> *) a b c x y.
Monad m =>
(a -> m (b, c)) -> Fold m b x -> Fold m c y -> Fold m a (x, y)
unzipWithMinM = forall (m :: * -> *) x y b c a.
Monad m =>
((x -> y -> (x, y))
-> Fold m (b, c) x -> Fold m (b, c) y -> Fold m (b, c) (x, y))
-> (a -> m (b, c)) -> Fold m b x -> Fold m c y -> Fold m a (x, y)
unzipWithMUsing forall (m :: * -> *) a b c x.
Monad m =>
(a -> b -> c) -> Fold m x a -> Fold m x b -> Fold m x c
teeWithMin
{-# INLINE unzipWith #-}
unzipWith :: Monad m
=> (a -> (b,c)) -> Fold m b x -> Fold m c y -> Fold m a (x,y)
unzipWith :: forall (m :: * -> *) a b c x y.
Monad m =>
(a -> (b, c)) -> Fold m b x -> Fold m c y -> Fold m a (x, y)
unzipWith a -> (b, c)
f = forall (m :: * -> *) a b c x y.
Monad m =>
(a -> m (b, c)) -> Fold m b x -> Fold m c y -> Fold m a (x, y)
unzipWithM (forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> (b, c)
f)
{-# INLINE unzip #-}
unzip :: Monad m => Fold m a x -> Fold m b y -> Fold m (a,b) (x,y)
unzip :: forall (m :: * -> *) a x b y.
Monad m =>
Fold m a x -> Fold m b y -> Fold m (a, b) (x, y)
unzip = forall (m :: * -> *) a b c x y.
Monad m =>
(a -> (b, c)) -> Fold m b x -> Fold m c y -> Fold m a (x, y)
unzipWith forall a. a -> a
id
{-# INLINE zipWithM #-}
zipWithM ::
(a -> b -> m c) -> t m a -> Fold m c x -> Fold m b x
zipWithM :: forall a b (m :: * -> *) c (t :: (* -> *) -> * -> *) x.
(a -> b -> m c) -> t m a -> Fold m c x -> Fold m b x
zipWithM = forall a. HasCallStack => a
undefined
{-# INLINE zip #-}
zip :: Monad m => t m a -> Fold m (a, b) x -> Fold m b x
zip :: forall (m :: * -> *) (t :: (* -> *) -> * -> *) a b x.
Monad m =>
t m a -> Fold m (a, b) x -> Fold m b x
zip = forall a b (m :: * -> *) c (t :: (* -> *) -> * -> *) x.
(a -> b -> m c) -> t m a -> Fold m c x -> Fold m b x
zipWithM (forall a b c. ((a, b) -> c) -> a -> b -> c
curry forall (m :: * -> *) a. Monad m => a -> m a
return)
{-# INLINE indexed #-}
indexed ::
Fold m (Int, a) b -> Fold m a b
indexed :: forall (m :: * -> *) a b. Fold m (Int, a) b -> Fold m a b
indexed = forall a. HasCallStack => a
undefined
{-# INLINE with #-}
with ::
(Fold m (s, a) b -> Fold m a b)
-> (((s, a) -> c) -> Fold m (s, a) b -> Fold m (s, a) b)
-> (((s, a) -> c) -> Fold m a b -> Fold m a b)
with :: forall (m :: * -> *) s a b c.
(Fold m (s, a) b -> Fold m a b)
-> (((s, a) -> c) -> Fold m (s, a) b -> Fold m (s, a) b)
-> ((s, a) -> c)
-> Fold m a b
-> Fold m a b
with Fold m (s, a) b -> Fold m a b
f ((s, a) -> c) -> Fold m (s, a) b -> Fold m (s, a) b
comb (s, a) -> c
g = Fold m (s, a) b -> Fold m a b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((s, a) -> c) -> Fold m (s, a) b -> Fold m (s, a) b
comb (s, a) -> c
g forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b (m :: * -> *) r. (a -> b) -> Fold m b r -> Fold m a r
lmap forall a b. (a, b) -> b
snd
{-# INLINE sampleFromthen #-}
sampleFromthen :: Monad m => Int -> Int -> Fold m a b -> Fold m a b
sampleFromthen :: forall (m :: * -> *) a b.
Monad m =>
Int -> Int -> Fold m a b -> Fold m a b
sampleFromthen Int
offset Int
size =
forall (m :: * -> *) s a b c.
(Fold m (s, a) b -> Fold m a b)
-> (((s, a) -> c) -> Fold m (s, a) b -> Fold m (s, a) b)
-> ((s, a) -> c)
-> Fold m a b
-> Fold m a b
with forall (m :: * -> *) a b. Fold m (Int, a) b -> Fold m a b
indexed forall (m :: * -> *) a r.
Monad m =>
(a -> Bool) -> Fold m a r -> Fold m a r
filter (\(Int
i, a
_) -> (Int
i forall a. Num a => a -> a -> a
+ Int
offset) forall a. Integral a => a -> a -> a
`mod` Int
size forall a. Eq a => a -> a -> Bool
== Int
0)
{-# INLINE concatSequence #-}
concatSequence ::
Fold m b c -> t (Fold m a b) -> Fold m a c
concatSequence :: forall (m :: * -> *) b c (t :: * -> *) a.
Fold m b c -> t (Fold m a b) -> Fold m a c
concatSequence Fold m b c
_f t (Fold m a b)
_p = forall a. HasCallStack => a
undefined
{-# INLINE chunksBetween #-}
chunksBetween ::
Int -> Int -> Fold m a b -> Fold m b c -> Fold m a c
chunksBetween :: forall (m :: * -> *) a b c.
Int -> Int -> Fold m a b -> Fold m b c -> Fold m a c
chunksBetween Int
_low Int
_high Fold m a b
_f1 Fold m b c
_f2 = forall a. HasCallStack => a
undefined
{-# INLINE toStream #-}
toStream :: Monad m => Fold m a (SerialT n a)
toStream :: forall (m :: * -> *) a (n :: * -> *).
Monad m =>
Fold m a (SerialT n a)
toStream = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (m :: * -> *) a. Stream m a -> SerialT m a
SerialT forall (m :: * -> *) a (n :: * -> *).
Monad m =>
Fold m a (Stream n a)
toStreamK
{-# INLINE toStreamRev #-}
toStreamRev :: Monad m => Fold m a (SerialT n a)
toStreamRev :: forall (m :: * -> *) a (n :: * -> *).
Monad m =>
Fold m a (SerialT n a)
toStreamRev = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (m :: * -> *) a. Stream m a -> SerialT m a
SerialT forall (m :: * -> *) a (n :: * -> *).
Monad m =>
Fold m a (Stream n a)
toStreamKRev