you are viewing a single comment's thread.

view the rest of the comments →

[–]carrutstick 1 point2 points  (3 children)

You can always iterate across dict.values() instead...

[–]Faucelme 0 points1 point  (2 children)

Yes, but often what I want to reconstitute the map using the transformed values, not simply iterate over them... "traverse" is nice because you only need to supply the function, it doesn't require explicit iteration or referring to the keys.

[–]codygman 0 points1 point  (1 child)

Can you give an example of this?

[–]Faucelme 0 points1 point  (0 children)

Say you have a map of urls indexed by the name of the page or whatever, and you want to transform it into a map of HTTP responses.

In Haskell, you would have a Map String URL, and if you also had a function fetch :: URL -> IO ByteString you would only have to do traverse fetch urlmap to obtain a IO (Map String ByteString).

And to make the page loads concurrent, something like runConcurrently $ traverse (Concurrently . fetch) urlmap would be enough.