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
| 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
| 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
| 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
| Some(Address("100-0000")) map Addr.zip | |
| //-> Option[Addr.郵便番号] = Some(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
| 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
| 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
| case class Address(zip:String) | |
| object Addr { | |
| type 住所 = Address | |
| type 郵便番号 = String | |
| def zip:住所 => 郵便番号 = _.zip | |
| } |
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
| trait Cat { | |
| type A | |
| type B | |
| type C | |
| def f:A => B | |
| def g:B => C | |
| def f_g:A => C = f andThen g | |
| } |
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
| trait Cat { | |
| type A | |
| type B | |
| def f:A => B | |
| } |
NewerOlder