I'm looking for the following syntax in Ruby[1,2,3].map {|n| f(n)} -> [1,2,3].map(f(_)). In Scala it's called a placeholder parameter.
Would it be possible to implement in ruby itself? Are there plans of adding some form of this syntax to the ruby language?
There isn't yet, but it may happen soon. The most likely syntax (as of 2019-08-29) would be
[1, 2, 3].map { f(_1) }
You can read the feature request here; the follow-up discussion here is a more recent take on it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With