Skip to content

Commit ae194b1

Browse files
authored
Add examples for sequence and traverse (#115)
* Add examples for sequence and traverse * Review feedback, unnecessary parens and logShow
1 parent 5140095 commit ae194b1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/Data/Traversable.purs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ import Data.Traversable.Accum.Internal (StateL(..), StateR(..), stateL, stateR)
3232
-- | - `sequence` runs the actions _contained_ in a data structure,
3333
-- | and accumulates the results.
3434
-- |
35+
-- | ```purescript
36+
-- | import Data.Traversable
37+
-- | import Data.Maybe
38+
-- | import Data.Int (fromNumber)
39+
-- |
40+
-- | sequence [Just 1, Just 2, Just 3] == Just [1,2,3]
41+
-- | sequence [Nothing, Just 2, Just 3] == Nothing
42+
-- |
43+
-- | traverse fromNumber [1.0, 2.0, 3.0] == Just [1,2,3]
44+
-- | traverse fromNumber [1.5, 2.0, 3.0] == Nothing
45+
-- |
46+
-- | traverse logShow [1,2,3]
47+
-- | -- prints:
48+
-- | 1
49+
-- | 2
50+
-- | 3
51+
-- |
52+
-- | traverse (\x -> [x, 0]) [1,2,3] == [[1,2,3],[1,2,0],[1,0,3],[1,0,0],[0,2,3],[0,2,0],[0,0,3],[0,0,0]]
53+
-- | ```
54+
-- |
3555
-- | The `traverse` and `sequence` functions should be compatible in the
3656
-- | following sense:
3757
-- |

0 commit comments

Comments
 (0)