A FoldM is a "left fold" over a data structure with:
A structure delivering elements of type A (variable type, like a List) and which can be folded over
A structure delivering elements of type A (fixed type, like an InputStream) and which can be folded over
A FoldM is a "left fold" over a data structure with:
Both 'start' and 'end' have an effect which allows the whole folding to take place inside a context M.
If 'M' has an 'Apply' instance then FoldM can be made Applicative to allow the folding of two values U and S at the same time.
If 'M' has a 'Monad' instance then FoldM can be made into a 'Compose' instance which allows to compose 2 folds into one, for example:
A FoldM can be used with a 'FoldableM' which produces the elements to fold over. Examples of FoldableM include
Usage example:
sum.run(List(1, 2, 3)) == 6