traverse -package:base-compat -package:case-insensitive -package:diagrams-lib -package:ral

Map each element of a structure to an action, evaluate these actions from left to right, and collect the results. For a version that ignores the results see traverse_.

Examples

Basic usage: In the first two examples we show each evaluated action mapping to the output structure.
>>> traverse Just [1,2,3,4]
Just [1,2,3,4]
>>> traverse id [Right 1, Right 2, Right 3, Right 4]
Right [1,2,3,4]
In the next examples, we show that Nothing and Left values short circuit the created structure.
>>> traverse (const Nothing) [1,2,3,4]
Nothing
>>> traverse (\x -> if odd x then Just x else Nothing)  [1,2,3,4]
Nothing
>>> traverse id [Right 1, Right 2, Right 3, Right 4, Left 0]
Left 0
Perform an Applicative action for each key-value pair in a KeyMap and produce a KeyMap of all the results.
Map each element of a structure to an action, evaluate these actions from left to right, and collect the results. For a version that ignores the results see traverse_.
Foldable instance would allow to strip off the exception too easily. I like the methods of Traversable, but Traversable instance requires Foldable instance.
A transformation, which traverses the stream with an action in the inner monad.
O(n log n). Traverse the elements of the heap in sorted order and produce a new heap using Applicative side-effects.
Map each element of the array to an action, evaluate these actions from left to right, and collect the results. For a version that ignores the results, see traverse_.
Map each element of a structure to an action, evaluate these actions from left to right, and collect the results. For a version that ignores the results see traverse_.
Traverse a function over a record. Note that the fields of the record will be accessed in lexicographic order by the labels.
Traverse a function over a variant.
Analog of traverse from Traversable.
Apply an action to every element of a Vec, yielding a Vec of results.
Apply an action to every element of a Vec, yielding a Vec of results.
Don't rely on a particular order of traversal!
\(TestGraph gr) nl el -> Graph.isConsistent $ evalTraverse nl el gr
\(TestGraph gr) nl el -> evalTraverse nl el gr == evalTraverseNode nl (evalTraverseEdge el gr)
\(TestGraph gr) nl el -> evalTraverse nl el gr == evalTraverseEdge el (evalTraverseNode nl gr)
\(TestGraph gr) nl -> flip MS.evalState nl (Graph.traverseNode nodeAction gr) == flip MS.evalState nl (Graph.traverse nodeAction pure gr)
\(TestGraph gr) el -> flip MS.evalState el (Graph.traverseEdge edgeAction gr) == flip MS.evalState el (Graph.traverse pure edgeAction gr)
Before every note switch to another instrument according to a list of programs given as state of the State monad. I do not know how to handle multiple channels in a reasonable way. Currently I just switch the instrument independent from the channel, and send the program switch to the same channel as the beginning note.
Traverse the type map. (map with effects.)
Traverse the type map. (map with effects.)