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
Using a Ticker
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
contramap :: (a -> b) -> f b -> f a
Equivalence relations are
|Contravariant (Const a)|
|Contravariant (Op a)|
|Contravariant (Constant a)|
|(Contravariant f, Contravariant g) => Contravariant (Product f g)|
A ticker that accepts the longest prefix of input that matches a prefix of the argument list.
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.
A ticker that accepts all input as long as it matches the given predicate.
A ticker that accepts all input items until one matches the given predicate.
Sequential concatenation ticker combinator: when the first argument ticker stops ticking, the second takes over.
Parallel conjunction ticker combinator: the result keeps ticking as long as both arguments do.