-
Notifications
You must be signed in to change notification settings - Fork 56
Add examples for sequence and traverse #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add examples for sequence and traverse #115
Conversation
| -- | traverse (fromNumber) [1.0, 2.0, 3.0] == Just [1,2,3] | ||
| -- | traverse (fromNumber) [1.5, 2.0, 3.0] == Nothing | ||
| -- | | ||
| -- | 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]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this example will be particularly illuminating; it doesn't seem very useful at first glance. I think probably most of the time when I'm using traverse, it's with Effect, Aff, or a monad transformer stack with one of these at the bottom, so I think an effectful example would probably be better. How about something like:
traverse logShow [1,2,3]
-- prints:
1
2
3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the logShow example.
I think it's also nice to show how traverse can be used for array expansion. Reading code that does this often trips me up because I never expect traverse to do something like this. For example in filterA https://github.com/purescript/purescript-arrays/blob/463dcacb99455de5e28ac4a3312bb795f293d2d9/src/Data/Array.purs#L609-L612
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. I guess it’s good to show a few different examples to illustrate that it can do a whole lot of very different things based on the Applicative instance in use.
|
CI is failing because it's not pulling in the v0.14.0-rc3 |
c8b4c7e to
4d703fb
Compare
|
@JordanMartinez Should be ready now |
|
Thanks! |
It would be nice to have examples for all instances, but Array is a good start.