Created
February 6, 2013 06:26
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 list = List.range(0, 10) | |
// 偶数の場合に処理する部分関数 | |
val ifEven: PartialFunction[Int, Int] = { case e if e % 2 == 0 => e * 2 } | |
// 偶数以外の場合に処理する部分関数 | |
val ifElse: PartialFunction[Int, Int] = { case e => e * 3 } | |
// 部分関数を合成する. | |
// 偶数だったらifEven関数を、それ以外ならifElse関数を適用するイメージ | |
val proc = ifEven.orElse(ifElse) | |
// 合成した部分関数を適用する. | |
val rslt = list.collect(proc) | |
println(rslt) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment