Skip to content

Instantly share code, notes, and snippets.

Avatar

rirakkumya rirakkumya

View GitHub Profile
View train.scala
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) {
View addressRun5.scala
List(Address(List("100-0001","100-0002"))) flatMap Addr.zip
// ->List[Addr.郵便番号] = List(100-0001, 100-0002)
View addressRun5.scala
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))
View addressRun4.scala
import Addr._
def lift(f: 住所 => 郵便番号): Option[住所] => Option[郵便番号] = _ map f
lift(Addr.zip)(Some(Address("100-1000")))
// -> Option[Addr.郵便番号] = Some(100-1000)
View addressRun2.scala
Some(Address("100-0000")) map Addr.zip
//-> Option[Addr.郵便番号] = Some(100-0000)
View addressRun3.scala
List(Address("100-0000"),Address("200-0000")) map Addr.zip 
//-> List[Addr.郵便番号] = List(100-0000, 200-0000)
View addressRun.scala
Addr.zip(Address("100-0000")) //-> Addr.郵便番号 = 100-0000
View address.scala
case class Address(zip:String)
object Addr {
type 住所 = Address
type 郵便番号 = String
def zip:住所 => 郵便番号 = _.zip
}
View compose.scala
trait Cat {
type A
type B
type C
def f:A => B
def g:B => C
def f_g:A => C = f andThen g
}
View cat.scala
trait Cat {
type A
type B
def f:A => B
}
You can’t perform that action at this time.