Skip to content

Conversation

milesfrain
Copy link
Contributor

It would be nice to have examples for all instances, but Array is a good start.

-- | 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]]
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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.

@JordanMartinez
Copy link
Contributor

CI is failing because it's not pulling in the v0.14.0-rc3 purs binary. @milesfrain Could you rebase this on top of master?

@milesfrain milesfrain force-pushed the traversable-examples branch from c8b4c7e to 4d703fb Compare October 15, 2020 01:38
@milesfrain
Copy link
Contributor Author

@JordanMartinez Should be ready now

@JordanMartinez
Copy link
Contributor

Thanks!

@JordanMartinez JordanMartinez merged commit ae194b1 into purescript:master Oct 15, 2020
@milesfrain milesfrain deleted the traversable-examples branch October 15, 2020 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants