Skip to content

Instantly share code, notes, and snippets.

@shigemk2

shigemk2/for.scala

Created Mar 26, 2016
Embed
What would you like to do?
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