Type mismatch error in Scala -


i blocked since yesterday type mismatch error , don't see how correct it. maybe can me it.

def combine( head : (char,int), xs : occurrences) : list[occurrences] =  xs.map { case (x,i) => ( occu <- 1 head._2 ) yield list((x,i), (head._1, occu)) } 

here error :

type mismatch;  found :   list[scala.collection.immutable.indexedseq[list[(char, int)]]]    required: list[forcomp.anagrams.occurrences] 

the type occurrences defined type occurrences = list[(char, int)]

how can fix error?

you solve problem using flatmap concatenate (flatten) lists you.

def combine( head : (char,int), xs : occurrences) : list[occurrences] =   xs.flatmap { case (x,i) => (1 head._2).map(occu =>list((x,i), (head._1, occu))) } 

now each occurance it'll produce list has (x,i) tuple , (head._1, occu) tuple , of lists ++'d flatmap.

note i'm blindly converting code since know homework won't attempt analyze if algorithm correct.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -