This module defines the Ticker cofunctor, useful for 'ticking off' a prefix of the input.

- newtype Ticker x = Ticker (x -> Maybe (Ticker x))
- splitTicked :: Ticker x -> [x] -> (Ticker x, [x], [x])
- class Contravariant f where
- contramap :: (a -> b) -> f b -> f a

- tickNone :: Ticker x
- tickOne :: Ticker x
- tickCount :: Int -> Ticker x
- tickPrefixOf :: Eq x => [x] -> Ticker x
- tickWhilePrefixOf :: [x -> Bool] -> Ticker x
- tickWhile :: (x -> Bool) -> Ticker x
- tickUntil :: (x -> Bool) -> Ticker x
- tickAll :: Ticker x
- andThen :: Ticker x -> Ticker x -> Ticker x
- and :: Ticker x -> Ticker x -> Ticker x
- or :: Ticker x -> Ticker x -> Ticker x

# The Ticker type

This is a contra-functor data type for selecting a prefix of an input stream. If the next input item is acceptable,
the ticker function returns the ticker for the rest of the stream. If not, it returns `Nothing`

.

# Using a Ticker

splitTicked :: Ticker x -> [x] -> (Ticker x, [x], [x])Source

Extracts a list prefix accepted by the `Ticker`

argument. Returns the modified ticker, the prefix, and the
remainder of the list.

class Contravariant f where

Any instance should be subject to the following laws:

contramap id = id contramap f . contramap g = contramap (g . f)

Note, that the second law follows from the free theorem of the type of
`contramap`

and the first law, so you need only check that the former
condition holds.

contramap :: (a -> b) -> f b -> f a

Contravariant Predicate | A |

Contravariant Comparison | A |

Contravariant Equivalence | Equivalence relations are |

Contravariant Ticker | |

Contravariant (Const a) | Control.Applicative.Const |

Contravariant (Op a) | |

Contravariant (Constant a) | Data.Functor.Constant |

(Contravariant f, Contravariant g) => Contravariant (Product f g) | Data.Functor.Product |

# Ticker constructors

tickPrefixOf :: Eq x => [x] -> Ticker xSource

A ticker that accepts the longest prefix of input that matches a prefix of the argument list.

tickWhilePrefixOf :: [x -> Bool] -> Ticker xSource

A ticker that accepts a prefix of input as long as each item satisfies the predicate at the same position in the argument list. The length of the predicate list thus determines the maximum number of acepted values.

tickWhile :: (x -> Bool) -> Ticker xSource

A ticker that accepts all input as long as it matches the given predicate.

tickUntil :: (x -> Bool) -> Ticker xSource

A ticker that accepts all input items until one matches the given predicate.

# Ticker combinators

andThen :: Ticker x -> Ticker x -> Ticker xSource

Sequential concatenation ticker combinator: when the first argument ticker stops ticking, the second takes over.