Skip to content

Instantly share code, notes, and snippets.

@poad
Created November 28, 2017 22:42
Show Gist options
  • Save poad/2c8a035950b6aafcb3b8ed4569e8bff3 to your computer and use it in GitHub Desktop.
Save poad/2c8a035950b6aafcb3b8ed4569e8bff3 to your computer and use it in GitHub Desktop.
ここが変だよScalaさん ref: https://qiita.com/poad1010/items/19e2c16a8877e82379f3
a - 1
a - 2
a - 3
b - 4
b - 5
b - 6
c is empty
false
val data = Map("a" -> Seq(1,2,3), "b" -> Seq(4,5,6), "c" -> Seq(), "d" -> Seq(7,8,9))
def conv(data: Map[String, Seq[Int]]): Boolean = {
data.foreach(kv => {
val key = kv._1
val value = kv._2
if (value.isEmpty) {
println(s"${key} is empty")
return false // ここで親のconvメソッドの戻り値が返せてしまう
}
value.map(v => {
s"${key} - ${v}"
})
.foreach(println)
})
true
}
println(conv(data))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment