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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -