From 1c0f4a5628c17ba99796c9a0b56321dc50d14aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=E5=98=89=E9=98=B3?= Date: Thu, 3 Jan 2019 10:50:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=81=8F=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fjy8018/scala/PartitalFunctionApp.scala | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/scala/top/fjy8018/scala/PartitalFunctionApp.scala diff --git a/src/main/scala/top/fjy8018/scala/PartitalFunctionApp.scala b/src/main/scala/top/fjy8018/scala/PartitalFunctionApp.scala new file mode 100644 index 0000000..d9084c6 --- /dev/null +++ b/src/main/scala/top/fjy8018/scala/PartitalFunctionApp.scala @@ -0,0 +1,29 @@ +package top.fjy8018.scala + +import scala.util.Random + +/** + * 偏函数:被包在花括号内没有match的一组case语句 + * + * F嘉阳 + * 2019-01-03 10:42 + */ +object PartitalFunctionApp extends App { + + + val names = Array("A","B","C") + val name = names(Random.nextInt(names.length)) + name match { + case "A" => "AAAAAAAA" + case "B" => "BBBBBBBB" + case _ => "CCCCCCCC" + } + // -A 输入参数类型 -B 输出参数类型 + def say:PartialFunction[String,String]={ + case "A" => "AAAAAAAA" + case "B" => "BBBBBBBB" + case _ => "CCCCCCCC" + } + + println(say("A")) +}