I have an array of strings and I need to turn them into quoted strings. Obviously I could just iterate over the array and use something like "\"%s\"".format(elem) to replace each element, but this seems grungy considering that my next step would be arr.mkString("(", "OR", ")")
I tried to curry String.format as follows:
val curried = "\"%s\"".format(_)
arr.map(curried)
But that does not work and complains:
found : (Any*) => String
required: (java.lang.String) => ?
How do I map a function like String.format over an array of strings? Is there another way to curry it or should I perhaps be specifying types?
You need to help compiler a little bit, and specify the desired type (at least it's one of the possible solutions to your problem):
val curried = "\"%s\"".format(_: String)
Otherwise compiler will produce Seq[Any] => String function, because format method has varargs.
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