|Portability||Non-portable (Generalized algebraic data types, Functional Dependencies)|
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)
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.
A simple iterator, which provides a way to view each of the elements of a data structure in order.
A function for making a cursor out of a free form generator, similar to
yield in Ruby or Python. For example:
generator $ \yield -> do a <- yield 1 ; yield 2 ; b <- yield 3 ; return [a,b]
Creates an Iterator that will yield each of the elements of a Foldable in order.
Extracts the current element from a cursor, if applicable.
Advances an Iterator to the next element (has no effect on a finished Iterator).
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.