This module contains functions for folding common collections types that can contain recursive data structures.
Fold a list that contains recursive types from right to left.
type RoseTree a
= Leaf a
| Node (List (RoseTree a))
countRoseTreeLeaves : RoseTree a -> Int
countRoseTreeLeaves =
runRecursion
(\tree ->
case tree of
Leaf _ ->
base 1
Node trees ->
foldrList recurse (+) 0 trees
)Favor foldlList if possible as it will be more efficient.
Fold a dictionary that contains recursive types in its value type in ascending order of keys.
Fold a dictionary that contains recursive types in its value type in descending order of keys.
Fold an array that contains recursive types from left to right.
Fold an array that contains recursive types from right to left.
Reduces a list that contains recursive types from left to right.