Scala - select elements from ordered list -


i looking nice way remove first n elements equal ordered list, e.g.

list(1,1,1,2,3,3) 

should return

removesame(list)  -> (1,1,1) 

is there nice way it, rather remove head of list , use takewhile on remainder, , using dropwhile? can think of simple non-functional solution wondering whether functional 1 exists

the functional way avoid duplication of takewhile , dropwhile prefix , remainder using span, i.e.

scala> val list = list(1,1,1,2,3,3) list: list[int] = list(1, 1, 1, 2, 3, 3)  scala> val (prefix, rest) = list span (_ == list.head) prefix: list[int] = list(1, 1, 1) rest: list[int] = list(2, 3, 3) 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -