Stability | experimental |
---|---|

Maintainer | Uwe Schmidt (uwe@fh-wedel.de) |

Safe Haskell | None |

A map-fold function for interleaved map and fold. The elements of a list are processed like in a binary tree.

- mapFoldBinary :: (a -> b) -> (b -> b -> b) -> [a] -> b
- mapFoldBinaryM :: Monad m => (a -> m b) -> (b -> b -> m b) -> [a] -> m b

# Documentation

mapFoldBinary :: (a -> b) -> (b -> b -> b) -> [a] -> bSource

Pure version of binary map fold

`mapFoldBinary id (+) [1..8]`

adds the elements of a list in the following order:
`(((1+2)+(3+4))+((5+6)+(7+8)))`

mapFoldBinaryM :: Monad m => (a -> m b) -> (b -> b -> m b) -> [a] -> m bSource

Monadic version of a binary map fold

The elements of a list are mapped and folded in the same way as in the pure version. The map and fold operations are interleaved. In the above example the expressions are evaluated from left to right, folding is performed, as early as possible.