module Data.Series.Generic.Scans (
postscanl,
prescanl,
forwardFill,
) where
import Data.Series.Generic.Definition ( Series(..) )
import Data.Vector.Generic ( Vector )
import qualified Data.Vector.Generic as Vector
postscanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> Series v k b -> Series v k a
{-# INLINABLE postscanl #-}
postscanl :: forall (v :: * -> *) a b k.
(Vector v a, Vector v b) =>
(a -> b -> a) -> a -> Series v k b -> Series v k a
postscanl a -> b -> a
f a
s (MkSeries Index k
ix v b
vs) = 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 -> Series v k a) -> v a -> Series v k a
forall a b. (a -> b) -> a -> b
$ (a -> b -> a) -> a -> v b -> v a
forall (v :: * -> *) a b.
(Vector v a, Vector v b) =>
(a -> b -> a) -> a -> v b -> v a
Vector.postscanl a -> b -> a
f a
s v b
vs
prescanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> Series v k b -> Series v k a
{-# INLINABLE prescanl #-}
prescanl :: forall (v :: * -> *) a b k.
(Vector v a, Vector v b) =>
(a -> b -> a) -> a -> Series v k b -> Series v k a
prescanl a -> b -> a
f a
s (MkSeries Index k
ix v b
vs) = 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 -> Series v k a) -> v a -> Series v k a
forall a b. (a -> b) -> a -> b
$ (a -> b -> a) -> a -> v b -> v a
forall (v :: * -> *) a b.
(Vector v a, Vector v b) =>
(a -> b -> a) -> a -> v b -> v a
Vector.prescanl a -> b -> a
f a
s v b
vs
forwardFill :: (Vector v a, Vector v (Maybe a))
=> a
-> Series v k (Maybe a)
-> Series v k a
{-# INLINABLE forwardFill #-}
forwardFill :: forall (v :: * -> *) a k.
(Vector v a, Vector v (Maybe a)) =>
a -> Series v k (Maybe a) -> Series v k a
forwardFill = (a -> Maybe a -> a) -> a -> Series v k (Maybe a) -> Series v k a
forall (v :: * -> *) a b k.
(Vector v a, Vector v b) =>
(a -> b -> a) -> a -> Series v k b -> Series v k a
postscanl a -> Maybe a -> a
forall a. a -> Maybe a -> a
go
where
go :: a -> Maybe a -> a
go :: forall a. a -> Maybe a -> a
go a
lastValid Maybe a
Nothing = a
lastValid
go a
_ (Just a
v) = a
v