Question

Can anyone tell me why in this case:

Query(Users) foreach {case (userId, userName) =>       
    println(userId + ", " + userName) }

Scala recognizes userId, but in this case:

val l = List[(Int, String)]()

Query(Users) foreach {
   case (userId, userName) =>
     l::(foo(List[(userId, userName)])) 
}

it doesnt? (as in, the userId on the right of the "=>" is recognized in the second case but not the first)

Users is a slick-mounted database that looks like this:

object Users extends Table[(Int, String)]("Users") {

  def userId          = column[Int]("UserId", O.PrimaryKey, O.AutoInc)
  def userName        = column[String]("UserName")

  def * = userId ~ userName
}
Was it helpful?

Solution

I think what you mean is:

l::(foo(List((userId, userName))))

When you put stuff between the square brackets, you are attempting to type the list and I assume you actually wanted to add the Tuple of userId and userName to a List instead.

You could also write it like this if all you wanted to do was put it into that List and you did not need that Tuple extractor:

Query(Users) foreach { tup =>     
  l::(foo(List(tup))) 
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top