File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 22
33## Module Data.Unfoldable
44
5+
6+ This module provides a type class for _ unfoldable functors_ , i.e.
7+ functors which support an ` unfoldr ` operation.
8+
9+ This allows us to unify various operations on arrays, lists,
10+ sequences, etc.
11+
512#### ` Unfoldable `
613
714``` purescript
815class Unfoldable t where
916 unfoldr :: forall a b. (b -> Maybe (Tuple a b)) -> b -> t a
1017```
1118
19+ This class identifies data structures which can be _ unfolded_ ,
20+ generalizing ` unfoldr ` on arrays.
21+
22+ The generating function ` f ` in ` unfoldr f ` in understood as follows:
23+
24+ - If ` f b ` is ` Nothing ` , then ` unfoldr f b ` should be empty.
25+ - If ` f b ` is ` Just (Tuple a b1) ` , then ` unfoldr f b ` should consist of ` a `
26+ appended to the result of ` unfoldr f b1 ` .
1227
1328#### ` unfoldableArray `
1429
Original file line number Diff line number Diff line change 1+ -- | This module provides a type class for _unfoldable functors_, i.e.
2+ -- | functors which support an `unfoldr` operation.
3+ -- |
4+ -- | This allows us to unify various operations on arrays, lists,
5+ -- | sequences, etc.
6+
17module Data.Unfoldable where
28
39import Data.Maybe
@@ -6,6 +12,14 @@ import Data.Array.ST
612import Control.Monad.Eff
713import Control.Monad.ST
814
15+ -- | This class identifies data structures which can be _unfolded_,
16+ -- | generalizing `unfoldr` on arrays.
17+ -- |
18+ -- | The generating function `f` in `unfoldr f` in understood as follows:
19+ -- |
20+ -- | - If `f b` is `Nothing`, then `unfoldr f b` should be empty.
21+ -- | - If `f b` is `Just (Tuple a b1)`, then `unfoldr f b` should consist of `a`
22+ -- | appended to the result of `unfoldr f b1`.
923class Unfoldable t where
1024 unfoldr :: forall a b . (b -> Maybe (Tuple a b )) -> b -> t a
1125
You can’t perform that action at this time.
0 commit comments