scala - accessing list.head, deconstruction vs method call -


i trying learn bit of scala , got stuck on small oddity when far can can write same in 2 supposedly equivalent ways, 1 runs , other not.

val test_array = array(1,2,3,4,5,6,7,8,9,10,3,4) val = test_array.sliding(2).tolist  def iter(lst: list[array[int]]): list[boolean] = lst match {   case h :: nil => list(false)   case h :: tail => tail.map(x => x.sameelements(lst.head)) ++ iter(tail) }  if(iter(it).contains(true)) ... 

and

val test_array = array(1,2,3,4,5,6,7,8,9,10,3,4) val = test_array.sliding(2).tolist  def iter(lst: list[array[int]]): list[boolean] = lst match {   case h :: nil => list(false)   case h :: tail => tail.map(x => x.sameelements(h)) ++ iter(tail) }  if(iter(it).contains(true)) ... 

the first example runs, second throws nosuchmethoderror: scala.collection.immutable.$colon$colon.hd$1()

the difference how access head. in 1 case use deconstruction way , other use list.head. why 1 run , other not?


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -