Whats a scala-like way to alter first and last in a List -
i have list[string] com.github.seratch.scalikesolr populating little inconveniantly... if list has 1 element, looks this:
[value]
(it has prepended , appended brackets).
if list has more 1 element, elements like:
[value1 value2]
struggling find clean looking scala-ish code remove brackets if present. suggest. in advance.
p.s. have several lists apply "filter" to... reusable code better approach.
def debracketize(list: list[string]): list[string] = list.map(_.stripprefix("[").stripsuffix("]"))
example usage:
println(debracketize(list("[value1", "value2]"))) println(debracketize(list("[value1]")))
outputs:
list(value1, value2) list(value1)
Comments
Post a Comment