Copyright | (c) Dan Doel |
---|---|
License | MIT |
Maintainer | Dan Doel |
Stability | Experimental |
Portability | Non-portable (Generalized algebraic data types, Functional Dependencies) |
Safe Haskell | None |
Language | Haskell98 |
Implements various cursor datatypes for iterating over collections
- data Cursor m r b a where
- type Iterator m a = Cursor m () () a
- generator :: MonadDelimitedCont p s m => ((a -> m b) -> m r) -> m (Cursor m r b a)
- iterator :: (Foldable t, MonadDelimitedCont p s m) => t a -> m (Iterator m a)
- current :: Cursor m r b a -> Maybe a
- next :: Iterator m a -> m (Iterator m a)
- open :: (Traversable t, MonadDelimitedCont p s m) => t a -> m (Cursor m (t b) b a)
- update :: b -> Cursor m r b a -> m (Cursor m r b a)
Documentation
data Cursor m r b a where Source
A generalized type that represents a reified data structure traversal. The other traversal data types in this module are special cases of this general type. Cursor is parameterized by four types:
m : The monad in which the Cursor object is usable.
r : The result type, which will be stored in the cursor once the traversal has been completed.
b : The type that the cursor expects to receive before moving on to the next element in the traversal.
a : The element type to which the Cursor provides access at each step in the traversal.
type Iterator m a = Cursor m () () a Source
A simple iterator, which provides a way to view each of the elements of a data structure in order.
generator :: MonadDelimitedCont p s m => ((a -> m b) -> m r) -> m (Cursor m r b a) Source
A function for making a cursor out of a free form generator, similar to
using yield
in Ruby or Python. For example:
generator $ \yield -> do a <- yield 1 ; yield 2 ; b <- yield 3 ; return [a,b]
iterator :: (Foldable t, MonadDelimitedCont p s m) => t a -> m (Iterator m a) Source
Creates an Iterator that will yield each of the elements of a Foldable in order.
current :: Cursor m r b a -> Maybe a Source
Extracts the current element from a cursor, if applicable.
next :: Iterator m a -> m (Iterator m a) Source
Advances an Iterator to the next element (has no effect on a finished Iterator).
open :: (Traversable t, MonadDelimitedCont p s m) => t a -> m (Cursor m (t b) b a) Source
Begins an updating traversal over a Traversable structure. At each step, the cursor will hold an element of type a, and providing an element of type b will move on to the next step. When done, a new Traversable object holding elements of type b will be available.