Skip to content

Commit 7070901

Browse files
committed
Merge pull request #3 from purescript/docs
Docs pending laws
2 parents 24efe49 + 1488abf commit 7070901

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@
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
815
class 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

src/Data/Unfoldable.purs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
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+
17
module Data.Unfoldable where
28

39
import Data.Maybe
@@ -6,6 +12,14 @@ import Data.Array.ST
612
import Control.Monad.Eff
713
import 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`.
923
class Unfoldable t where
1024
unfoldr :: forall a b. (b -> Maybe (Tuple a b)) -> b -> t a
1125

0 commit comments

Comments
 (0)