Scala Type Mismatch Mapping -


i trying create search function, user can search through list using key value, method im trying use returns type mismatch, have taken out needless code , shown required. how set points take int , not "any"?

"type not conform type int"

  val mapdata = readfile("data.txt")     def handletwo(): boolean = {     mnushowpointsforteam(currentpointsforteam)     true   }     def mnushowpointsforteam(f: (string) => (string, int)) = {     print("team>")     val data = f(readline)     println(s"${data._1}: ${data._2}")   }      def currentpointsforteam(team: string): (string, int) = {     val points = mapdata.get(team) match{       case some(p) => p       case none => 0     }     (team, points)   } 

the data.txt

sk1, 9, 7, 2, 0, 7, 3, 7, 9, 1, 2, 8, 1, 9, 6, 5, 3, 2, 2, 7, 2, 8, 5, 4, 5, 1, 6, 5, 2, 4, 1 sk2, 0, 7, 6, 3, 3, 3, 1, 6, 9, 2, 9, 7, 8, 7, 3, 6, 3, 5, 5, 2, 9, 7, 3, 4, 6, 3, 4, 3, 4, 1 sk4, 2, 9, 5, 7, 0, 8, 6, 6, 7, 9, 0, 1, 3, 1, 6, 0, 0, 1, 3, 8, 5, 4, 0, 9, 7, 1, 4, 5, 2, 8 sk5, 2, 6, 8, 0, 3, 5, 5, 2, 5, 9, 4, 5, 3, 5, 7, 8, 8, 2, 5, 9, 3, 8, 6, 7, 8, 7, 4, 1, 2, 3 sk6, 2, 7, 5, 9, 1, 9, 8, 4, 1, 7, 3, 7, 0, 8, 4, 5, 9, 2, 4, 4, 8, 7, 9, 2, 2, 7, 9, 1, 6, 9 sk7, 6, 9, 5, 0, 0, 0, 0, 5, 8, 3, 8, 7, 1, 9, 6, 1, 5, 3, 4, 7, 9, 5, 5, 9, 1, 4, 4, 0, 2, 0 sk8, 2, 8, 8, 3, 1, 1, 0, 8, 5, 9, 0, 3, 1, 6, 8, 7, 9, 6, 7, 7, 0, 9, 5, 2, 5, 0, 2, 1, 8, 6 sk9, 7, 1, 8, 8, 4, 4, 2, 2, 7, 4, 0, 6, 9, 5, 5, 4, 9, 1, 8, 6, 3, 4, 8, 2, 7, 9, 7, 2, 6, 6 

it looks want return tuple list[int], not single int.

if so

def currentpointsforteam(team: string): (string, list[int]) =    (team, mapdata.get(team).getorelse(list.empty))     // or maybe list(0) instead of list.empty 

if want return single int, have how go list[int] in map single value. maybe sum?

def currentpointsforteam(team: string): (string, int) =    (team, mapdata.get(team).map(_.sum).getorelse(0)) 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -