monad-coroutine-0.6.1: Coroutine monad transformer for suspending and resuming monadic computations

Control.Cofunctor.Ticker

Contents

Description

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

Synopsis

The Ticker type

newtype Ticker x Source

This is a cofunctor 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.

Constructors

Ticker (x -> Maybe (Ticker x)) 

Using a Ticker

cofmap :: (x -> y) -> Ticker y -> Ticker xSource

Ticker happens to be a cofunctor, but there is no standard class declaration to declare it an instance of.

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.

Various Ticker constructors

tickNone :: Ticker xSource

A ticker that accepts no input.

tickOne :: Ticker xSource

A ticker that accepts a single input item.

tickCount :: Int -> Ticker xSource

A ticker that accepts a given number of input items.

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.

tickAll :: Ticker xSource

A ticker that accepts all input.

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

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