I have a List[String]
, and I want to quote each element. So I figured I could just do var.map(s"'$_'")
. But that gives me error in interpolated string: identifier or block expected. What am I doing wrong? Is there a way to use the _
within a string interpolation?
I'm currently doing var.map("'" + _ + "'")
, but it seems somewhat verbose and confusing.
The PR to make this work wasn't merged because the syntax was considered too radical, too unsettling.
The PR for the same syntax in a pattern context was accepted, however.
There is some discussion at:
https://github.com/scala/scala/pull/2793
I would have used this syntax at least a handful of times. People like to save an extra arrow. People also don't like the burden of inventing identifiers needlessly. Yes, like x
.
I would do:
var.map(x => s"'$x'")
It is decidedly less "verbose and confusing", and probably less confusing than var.map(s"'$_'")
as well.
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