This module contains functions for folding common collections types that can contain recursive data structures.
Prefer to use the functions that accept a continuation when possible (fold____Then) as they will be more efficient than folding and then mapping after.
Fold a list of items which are recurisve types and then perform a recursive action with the result.
Fold a list of items which contain recursive types.
type KeyedRoseTree a
= Leaf a
| Node (List ( String, KeyedRoseTree a ))
countRoseTreeLeaves : KeyedRoseTree a -> Int
countRoseTreeLeaves =
runRecursion <|
\tree ->
case tree of
Leaf _ ->
base 1
Node trees ->
foldMapList
(\( _, rec ) count -> recurseMap rec ((+) count))
0
treesFold a list of items which contain recursive types and then perform a recursive action with the result.
Fold a Dict whose values are recursive types.
type HashTrie a
= Leaf a
| Node (Dict Char (HashTrie a))
countHashTrie : HashTrie a -> Int
countHashTrie =
runRecursion <|
\tree ->
case tree of
Leaf _ ->
base 1
Node trees ->
foldDict (\_ x count -> x + count) 0 treesFold a Dict whose values are recursive types and then perform a recursive action with the result.
Fold a Dict whose values contain recursive types.
type HashTrie a
= Leaf a
| Node (Dict Char ( Int, HashTrie a ))
countHashTrie : HashTrie a -> Int
countHashTrie =
runRecursion <|
\tree ->
case tree of
Leaf _ ->
base 1
Node trees ->
foldMapDict (\_ ( _, v ) count -> recurseMap v (\x -> x + count)) 0 treesFold a Dict whose values contain recursive types and then perform a recursive action with the result.
Fold an Array whose items are recursive types.
Fold an Array whose items are recursive types and then perform a recursive action with the result.
Fold an Array whose items contain recursive types.
Fold an Array whose items contain recursive types and then perform a recursive action with the result.
Fold a list of items which are recursive types.