generator-0.5.1: A list monad transformer and related functions.



A monad transformer for the creation of Lists. Similar to Python's generators.

 import Data.List.Class (convList)

 hanoi 0 _ _ _ = mempty
 hanoi n from to other =
   generate $ do
     yields $ hanoi (n-1) from other to
     yield (from, to)
     yields $ hanoi (n-1) other to from

 > convList (hanoi 3 'A' 'B' 'C') :: [(Char, Char)]



data GeneratorT v m a Source

A monad transformer to create Lists. generate transforms a GeneratorT v m a to a DListT m a.


generate :: Monad m => GeneratorT v m () -> DListT m vSource

O(1), Transform a GeneratorT to a DListT

yield :: Monad m => v -> GeneratorT v m ()Source

O(1), Output a result value

yields :: Monad m => DListT m v -> GeneratorT v m ()Source

O(1), Output all the values of a DListT.