- maybe-sequence mappable map #!optional aggregatorprocedure
- either-sequence mappable map #!optional aggregatorprocedure
The purpose of these procedures is to transform a collection of Maybes/Eithers of some particular type into a Maybe/Either of a collection, often of the same type.
The mappable argument is the collection to be transformed, and the map argument is the appropriate procedure that can transform it, one element at a time. The signature of map is (map proc mappable), where proc is supplied by the implementation. Typical mappables are lists and vectors, and map and vector-map are useful map functions, though not the only possible ones.
Each element is processed as follows: If it is a Just/Right, its values are unwrapped and the aggregator function (which defaults to list) is applied to them. But if it is a Left/Nothing, that object is immediately returned as the value of maybe-sequence/either-sequence.
Assuming there are no Lefts/Nothings, the map function is then responsible for constructing the new mappable out of the results of the calls on aggregator.
For example, a list of Justs becomes a Just list of lists if the map procedure is map and the aggregator is list. In the same way, a vector of Rights containing one value each becomes a Right vector if the map procedure is vector-map and the aggregator is (lambda (x) x).