yield - Scala Comprehension Errors -


i working on of exercism.io exercises. current 1 working on scala dna exercise. here code , errors receiving:

for reference, dna instantiated strand string. dna can call count (which counts strand single nucleotide passed) , nucletidecounts counts of respective occurrences of each nucleotide in strand , returns map[char,int].

class dna(strand:string) {    def count(nucleotide:char): int = {     strand.count(_ == nucleotide)   }    def nucleotidecounts = (     {       n <- strand       c <- count(n)     } yield (n, c)   ).tomap  } 

the errors receiving are:

error:(10, 17) value map not member of int c <- count(n) ^

error:(12, 5) cannot prove char <:< (t, u). ).tomap ^

error:(12, 5) not enough arguments method tomap: (implicit ev: <:<[char,(t, u)])scala.collection.immutable.map[t,u]. unspecified value parameter ev. ).tomap ^

i quite new scala, enlightenment on why these errors occurring , suggestions fixing them appreciated.

for comprehensions work on traversable's have flatmap , map methods defined, error message pointing out.

in case count returns simple integer no need "iterate" on it, add result set.

for {   n <- strand } yield (n, count(n)) 

on side note solution not optimal in case of strand aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa count going called many times. recommend calling toset distinct chars only:

for {   n <- strand.toset } yield (n, count(n)) 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -