scala - Pattern matching on tail of arrays -


i trying implement distinct function on arrays this:

def distinct(a: array[int]): array[int] = match {     case array() =>     case array(head, tail @ _*) => head +: distinct(tail.toarray).filter(_ != head) } 

i don't like, have transform tail toarray every time. otherwise compiler complains tail sequence , not array. possible pattern match better in case?

it isn't sexy enough pattern matching, go way:

def distinct(a: array[int]): array[int] = match {     case array() =>     case htail   => htail.head +: distinct(htail.tail).filter(_ != htail.head) } 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -