This module provides a type class for unfoldable functors, i.e.
functors which support an unfoldr
operation.
This allows us to unify various operations on arrays, lists, sequences, etc.
class Unfoldable t where
unfoldr :: forall a b. (b -> Maybe (Tuple a b)) -> b -> t a
This class identifies data structures which can be unfolded,
generalizing unfoldr
on arrays.
The generating function f
in unfoldr f
in understood as follows:
- If
f b
isNothing
, thenunfoldr f b
should be empty. - If
f b
isJust (Tuple a b1)
, thenunfoldr f b
should consist ofa
appended to the result ofunfoldr f b1
.
instance unfoldableArray :: Unfoldable Prim.Array