Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created March 26, 2016 13:49
Show Gist options
  • Save shigemk2/ade7752d2a7de8d40c18 to your computer and use it in GitHub Desktop.
Save shigemk2/ade7752d2a7de8d40c18 to your computer and use it in GitHub Desktop.
forのサンプル
case class Student(name: String, age: Int, grade: Int)
val list = List(
Student("Steve", 15, 1),
Student("Chad", 16, 2),
Student("Shigeru", 40, 1),
Student("Chloé", 18, 3)
)
val students = for {
student <- list
name <- student.name
} yield name
println(students)
val studentNames = for {
student <- list
} yield student.name
println(studentNames)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment