Safe Haskell | Safe |
---|---|
Language | Haskell98 |
This module provides efficient and streaming left map-with-accumulator that you can combine
using Applicative
style.
Import this module qualified to avoid clashing with the Prelude:
>>>
import qualified Control.Scanl as SL
- data Scan a b = Scan (a -> State x b) x
- data ScanM m a b = ScanM (a -> StateT x m b) (m x)
- scan :: Traversable t => Scan a b -> t a -> t b
- scanM :: (Traversable t, Monad m) => ScanM m a b -> t a -> m (t b)
- prescan :: Fold a b -> Scan a b
- postscan :: Fold a b -> Scan a b
- purely :: (forall x. (a -> State x b) -> x -> r) -> Scan a b -> r
- purely_ :: (forall x. (x -> a -> (x, b)) -> x -> r) -> Scan a b -> r
- impurely :: (forall x. (a -> StateT x m b) -> m x -> r) -> ScanM m a b -> r
- impurely_ :: Monad m => (forall x. (x -> a -> m (x, b)) -> m x -> r) -> ScanM m a b -> r
- generalize :: Monad m => Scan a b -> ScanM m a b
- simplify :: ScanM Identity a b -> Scan a b
- hoists :: (forall x. m x -> n x) -> ScanM m a b -> ScanM n a b
- arrM :: Monad m => (b -> m c) -> ScanM m b c
- premap :: (a -> b) -> Scan b r -> Scan a r
- premapM :: Monad m => (a -> m b) -> ScanM m b r -> ScanM m a r
Scan Types
Efficient representation of a left map-with-accumulator that preserves the scan's step function and initial accumulator.
This allows the Applicative
instance to assemble derived scans that
traverse the container only once
A 'Scan
a b' processes elements of type a replacing each with a
value of type b.
Arrow Scan Source # | |
Profunctor Scan Source # | |
Functor (Scan a) Source # | |
Applicative (Scan a) Source # | |
Category * Scan Source # | |
Floating b => Floating (Scan a b) Source # | |
Fractional b => Fractional (Scan a b) Source # | |
Num b => Num (Scan a b) Source # | |
Semigroup b => Semigroup (Scan a b) Source # | |
Monoid b => Monoid (Scan a b) Source # | |
Like Scan
, but monadic.
A 'ScanM
m a b' processes elements of type a and
results in a monadic value of type m b.
Monad m => Arrow (ScanM m) Source # | |
Functor m => Profunctor (ScanM m) Source # | |
Monad m => Category * (ScanM m) Source # | |
Functor m => Functor (ScanM m a) Source # | |
Applicative m => Applicative (ScanM m a) Source # | |
(Monad m, Floating b) => Floating (ScanM m a b) Source # | |
(Monad m, Fractional b) => Fractional (ScanM m a b) Source # | |
(Monad m, Num b) => Num (ScanM m a b) Source # | |
(Monad m, Semigroup b) => Semigroup (ScanM m a b) Source # | |
(Monad m, Monoid b) => Monoid (ScanM m a b) Source # | |
Scanning
scan :: Traversable t => Scan a b -> t a -> t b Source #
Apply a strict left Scan
to a Traversable
container
prescan :: Fold a b -> Scan a b Source #
Convert a Fold
into a prescan
"Prescan" means that the last element of the scan is not included
postscan :: Fold a b -> Scan a b Source #
Convert a Fold
into a postscan
"Postscan" means that the first element of the scan is not included
Utilities
purely :: (forall x. (a -> State x b) -> x -> r) -> Scan a b -> r Source #
Upgrade a scan to accept the Scan
type
purely_ :: (forall x. (x -> a -> (x, b)) -> x -> r) -> Scan a b -> r Source #
Upgrade a more traditional scan to accept the Scan
type
impurely :: (forall x. (a -> StateT x m b) -> m x -> r) -> ScanM m a b -> r Source #
Upgrade a monadic scan to accept the ScanM
type
impurely_ :: Monad m => (forall x. (x -> a -> m (x, b)) -> m x -> r) -> ScanM m a b -> r Source #
Upgrade a more traditional monadic scan to accept the ScanM
type