Created
November 28, 2017 22:42
-
-
Save poad/2c8a035950b6aafcb3b8ed4569e8bff3 to your computer and use it in GitHub Desktop.
ここが変だよScalaさん ref: https://qiita.com/poad1010/items/19e2c16a8877e82379f3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a - 1 | |
a - 2 | |
a - 3 | |
b - 4 | |
b - 5 | |
b - 6 | |
c is empty | |
false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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