Safe Haskell | None |
---|---|

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`

Use `scan`

to apply a `Fold`

to a list (or other `Traversable`

structures) from left to right,
and `scanr`

to do so from right to left.

## Synopsis

- 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)
- scanr :: Traversable t => Scan a b -> t a -> 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**.

## Instances

Arrow Scan Source # | |

Profunctor Scan Source # | |

Functor (Scan a) Source # | |

Applicative (Scan a) Source # | |

Category Scan Source # | |

Floating b => Floating (Scan a b) Source # | |

Defined in Control.Scanl sqrt :: Scan a b -> Scan a b # (**) :: Scan a b -> Scan a b -> Scan a b # logBase :: Scan a b -> Scan a b -> Scan a b # asin :: Scan a b -> Scan a b # acos :: Scan a b -> Scan a b # atan :: Scan a b -> Scan a b # sinh :: Scan a b -> Scan a b # cosh :: Scan a b -> Scan a b # tanh :: Scan a b -> Scan a b # asinh :: Scan a b -> Scan a b # acosh :: Scan a b -> Scan a b # atanh :: Scan a b -> Scan a b # log1p :: Scan a b -> Scan a b # expm1 :: Scan a b -> Scan a b # | |

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**.

## Instances

Monad m => Arrow (ScanM m) Source # | |

Functor m => Profunctor (ScanM m) Source # | |

Defined in Control.Scanl | |

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 # | |

Defined in Control.Scanl exp :: ScanM m a b -> ScanM m a b # log :: ScanM m a b -> ScanM m a b # sqrt :: ScanM m a b -> ScanM m a b # (**) :: ScanM m a b -> ScanM m a b -> ScanM m a b # logBase :: ScanM m a b -> ScanM m a b -> ScanM m a b # sin :: ScanM m a b -> ScanM m a b # cos :: ScanM m a b -> ScanM m a b # tan :: ScanM m a b -> ScanM m a b # asin :: ScanM m a b -> ScanM m a b # acos :: ScanM m a b -> ScanM m a b # atan :: ScanM m a b -> ScanM m a b # sinh :: ScanM m a b -> ScanM m a b # cosh :: ScanM m a b -> ScanM m a b # tanh :: ScanM m a b -> ScanM m a b # asinh :: ScanM m a b -> ScanM m a b # acosh :: ScanM m a b -> ScanM m a b # atanh :: ScanM m a b -> ScanM m a b # log1p :: ScanM m a b -> ScanM m a b # expm1 :: ScanM m a b -> ScanM m a b # | |

(Monad m, Fractional b) => Fractional (ScanM m a b) Source # | |

(Monad m, Num b) => Num (ScanM m a b) Source # | |

Defined in Control.Scanl (+) :: ScanM m a b -> ScanM m a b -> ScanM m a b # (-) :: ScanM m a b -> ScanM m a b -> ScanM m a b # (*) :: ScanM m a b -> ScanM m a b -> ScanM m a b # negate :: ScanM m a b -> ScanM m a b # abs :: ScanM m a b -> ScanM m a b # signum :: ScanM m a b -> ScanM m a b # fromInteger :: Integer -> ScanM m a b # | |

(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

scanr :: Traversable t => Scan a b -> t a -> t b Source #

Like `scan`

but start scanning from the right

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