Naming of Dry::Monads::List#traverse

First of all, thank you for making dry-monads. I really like the API and the way you have managed to give us something akin to do notation. My code is (at least to me) much clearer and much more solid with it. Having done some Haskell and Scala before, I also enjoy how familiar it all feels.

That familiarity is actually what motivates me to write. Shouldn’t List’s traverse be called sequence? Haskell’s traverse requires a function that will map each traversed item to an Applicative in order to produce the result with the Applicative on the outside and the mapped values in a new Traversable on the inside (traverse :: (Traversable t, Applicative f) => (a -> f b) -> t a -> f (t b)). sequence, on the other hand, has a Monad constraint and already presumes you’re dealing with a Traversable containing monadic values (sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)) – which is what dry-monads’ traverse does.

Hah, I like this one :slight_smile: List#traverse actually yields a block, I just made it falling back to sequence behavior when no block was given. It’s also a bit different for Validated for the sake of simplifying the most common usage: https://github.com/dry-rb/dry-monads/blob/1bc16508d6aec7b8a40c322ceafcedb99f5a8d4b/lib/dry/monads/traverse.rb I’m not particularly proud of it but it does the trick. I wouldn’t do this in Haskell but Ruby is more relaxed I think :slight_smile:

I’m sorry for playing the role of ignorant purist. The code samples didn’t show the optional block, but the text in the doc says it takes one. Thank you for taking the time to explain your decision.

1 Like