scala - Found Unit: Required [SomethingElse] -


i have following scala function , won't compile because finds unit tough requires [somethingelse]

def combine(trees: list[codetree]): list[codetree] = {    if(trees.length < 2) trees   else isortfortrees(trees.+:(new fork(trees.head, trees.tail.head, chars(trees.head).:::(chars(trees.tail.head)), weight(trees.head) + weight(trees.tail.head))))     def isortfortrees(mylist: list[codetree]): list[codetree] = {     if(mylist.isempty) nil     else insertfortrees(mylist.head, isortfortrees(mylist.tail))   }    def insertfortrees(tobeinserted: codetree, listobe: list[codetree]): list[codetree] = {     if(listobe.isempty || weight(tobeinserted) < weight(listobe.head)) tobeinserted :: listobe     else listobe.head :: insertfortrees(tobeinserted, listobe.tail)   }  } 

i cannot understand why unit returned ? both ends of if statement return list[codetree]. silly mistake made cannot find it. missing here?

the last expression in method method definition returns unit. move

if(trees.length < 2) trees else isortfortrees(trees.+:(new fork(trees.head, trees.tail.head, chars(trees.head).:::(chars(trees.tail.head)), weight(trees.head) + weight(trees.tail.head)))) 

to bottom of method , should work.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -