scalaステップ24-抽出器とモードマッチング
569 ワード
/**
* ( )
* unapply
* , ( )
*/
object :> {
def unapply[A](list: List[A]) = {
Some((list.init, list.last))//init
}
}
object Extractor_Advanced {
def main(args: Array[String]): Unit = {
// : ,last 9
(1 to 9).toList match { case _ :> 9 => println("Hadoop") }
(1 to 9).toList match { case _ :> 8 :> 9 => println("Spark")} //
(1 to 9).toList match { case :>(:>(_, 8), 9) => println("Flink")}
}
}