Created
February 21, 2014 12:41
-
-
Save gakuzzzz/9133588 to your computer and use it in GitHub Desktop.
PartialFunction
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
scala> val list: Seq[PartialFunction[Int, String]] = Seq({case 1 => "a"}, {case 2 => "b"}, {case 3 => "c"}) | |
list: Seq[PartialFunction[Int,String]] = List(<function1>, <function1>, <function1>) | |
scala> list.reduceLeft(_ orElse _).apply(100) | |
scala.MatchError: 100 (of class java.lang.Integer) | |
at scala.PartialFunction$$anon$1.apply(PartialFunction.scala:248) | |
at scala.PartialFunction$$anon$1.apply(PartialFunction.scala:246) | |
at $anonfun$3.applyOrElse(<console>:7) | |
at $anonfun$3.applyOrElse(<console>:7) | |
at scala.runtime.AbstractPartialFunction$mcLI$sp.apply$mcLI$sp(AbstractPartialFunction.scala:33) | |
at scala.runtime.AbstractPartialFunction$mcLI$sp.apply(AbstractPartialFunction.scala:33) | |
at scala.runtime.AbstractPartialFunction$mcLI$sp.apply(AbstractPartialFunction.scala:25) | |
at $anonfun$2.applyOrElse(<console>:7) | |
at $anonfun$2.applyOrElse(<console>:7) | |
at scala.PartialFunction$OrElse.apply(PartialFunction.scala:162) | |
at $anonfun$1.applyOrElse(<console>:7) | |
at $anonfun$1.applyOrElse(<console>:7) | |
at scala.PartialFunction$OrElse.apply(PartialFunction.scala:162) | |
at .<init>(<console>:9) | |
at .<clinit>(<console>) | |
at .<init>(<console>:7) | |
at .<clinit>(<console>) | |
at $print(<console>) | |
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) | |
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) | |
at java.lang.reflect.Method.invoke(Method.java:606) | |
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:734) | |
at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:983) | |
at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:573) | |
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:604) | |
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568) | |
at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:745) | |
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:790) | |
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:702) | |
at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:566) | |
at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:573) | |
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:576) | |
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:867) | |
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:822) | |
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:822) | |
at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135) | |
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:822) | |
at scala.tools.nsc.interpreter.ILoop.main(ILoop.scala:889) | |
at xsbt.ConsoleInterface.run(ConsoleInterface.scala:69) | |
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) | |
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) | |
at java.lang.reflect.Method.invoke(Method.java:606) | |
at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:102) | |
at sbt.compiler.AnalyzingCompiler.console(AnalyzingCompiler.scala:77) | |
at sbt.Console.sbt$Console$$console0$1(Console.scala:23) | |
at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply$mcV$sp(Console.scala:24) | |
at sbt.TrapExit$.sbt$TrapExit$$executeMain$1(TrapExit.scala:33) | |
at sbt.TrapExit$$anon$1.run(TrapExit.scala:42) | |
scala> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
多分 apply でもチェックするようにしないと最後のものがapplyされてしまう?