This file contains hidden or 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
| def index(id:String) = Action { | |
| getFirstData(id) | |
| } | |
| private def getFirstData(id:String) = { | |
| Cache.get(id) match { | |
| case Some(id2) => getSecondData(id2) | |
| case None => NotFound | |
| } | |
| } | |
| private def getSecondData(id2:String) = { |
This file contains hidden or 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
| resolvers += "Scala Tools Snapshots" at "http://scala-tools.org/repo-snapshots/" | |
| libraryDependencies += "org.scalaz" %% "scalaz-core" % "6.0.4" | |
| libraryDependencies += "com.github.scala-incubator.io" %% "scala-io-core" % "0.3.0" | |
| libraryDependencies += "com.github.scala-incubator.io" %% "scala-io-file" % "0.3.0" | |
| libraryDependencies += "org.scala-tools.testing" %% "scalacheck" % "1.9" |
This file contains hidden or 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
| def f[a] = (d:List[Either[Throwable,a]]) => | |
| d.collect{case Left(x) => x}.headOption.toLeft(d.map{case Right(x) => x}) | |
| scala> Some(List(Right("4"),Right("3"))) map f | |
| res11: Option[Product with Either[Throwable,List[java.lang.String]] with Serializable] = Some(Right(List(4, 3))) | |
| scala> Some(List(Right("4"),Left(new RuntimeException),Right("3"))) map f | |
| res12: Option[Product with Either[Throwable,List[java.lang.String]] with Serializable] = Some(Left(java.lang.RuntimeException)) | |
| scala> Some(List(Right("4"),Left(new RuntimeException("a")),Right("3"),Left(new RuntimeException("b")))) map f |
This file contains hidden or 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
| Addr.zip(Address("100-0000")) //-> Addr.郵便番号 = 100-0000 |
This file contains hidden or 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
| import TrainOps._ | |
| import TrainService._ | |
| object TrainService { | |
| type ANSWER = Either[String, List[TrainStatus]] | |
| trait Train[A] { | |
| def status(x: A): ANSWER | |
| } | |
| case class TrainStatus(name: String, Status: String) | |
| case class 運行状況(area: String) { |
This file contains hidden or 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
| case class Address(zip:List[String]) | |
| object Addr { | |
| type 住所 = Address | |
| type 郵便番号 = String | |
| def zip:住所 => List[郵便番号] = _.zip | |
| } | |
| List(Address(List("100-0001","100-0002"))) map Addr.zip | |
| //->List[List[Addr.郵便番号]] = List(List(100-0001, 100-0002)) |
This file contains hidden or 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
| List(Address(List("100-0001","100-0002"))) flatMap Addr.zip | |
| // ->List[Addr.郵便番号] = List(100-0001, 100-0002) |
This file contains hidden or 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
| import Addr._ | |
| def lift(f: 住所 => 郵便番号): Option[住所] => Option[郵便番号] = _ map f | |
| lift(Addr.zip)(Some(Address("100-1000"))) | |
| // -> Option[Addr.郵便番号] = Some(100-1000) |
This file contains hidden or 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
| List(Address("100-0000"),Address("200-0000")) map Addr.zip | |
| //-> List[Addr.郵便番号] = List(100-0000, 200-0000) |
This file contains hidden or 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
| Some(Address("100-0000")) map Addr.zip | |
| //-> Option[Addr.郵便番号] = Some(100-0000) |
NewerOlder