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
@startuml | |
participant ユーザー as User | |
participant アプリケーション as App | |
participant サーバー as Server | |
participant データベース as DB | |
Server -> User: マスクを公開 | |
User -> App: ガチャを引くボタンを押す |
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
case class Function[-A](f: A => Unit) | |
def function[A](x: A): Unit = () | |
trait SuperClass | |
trait SubClass extends SuperClass | |
val superClass = new SuperClass {} | |
val subClass = new SubClass {} | |
PartialFunction[SubClass, Unit]((x: SuperClass) => ()) |
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
object DatabaseAndHttpException { | |
implicit val databaseException = new :->[DatabaseException, DatabaseAndHttpException] { | |
def cast(a: DatabaseException): DatabaseAndHttpException = | |
DatabaseAndHttpException(s"database: ${a.m}") | |
} | |
implicit val httpException = new :->[HttpException, DatabaseAndHttpException] { | |
def cast(a: HttpException): DatabaseAndHttpException = | |
DatabaseAndHttpException(s"http: ${a.m}") | |
} |
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
object Coproduct { | |
implicit def coproductFunctor[F[_], G[_]](implicit F: Functor[F], G: Functor[G]) = | |
new Functor[({type L[A] = Coproduct[F, G, A]})#L] { | |
def map[A, B](a: Coproduct[F, G, A])(f: A => B): Coproduct[F, G, B] = a.value match { | |
case Left(e) => Coproduct[F, G, B](Left(F.map(e)(f))) | |
case Right(e) => Coproduct[F, G, B](Right(G.map(e)(f))) | |
} | |
} | |
} |
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
trait Applicative[F[_]] { | |
def pure[A](a: A): F[A] | |
def apply[A, B](f: F[A => B], a: F[A]): F[B] | |
} | |
trait Traversable[T[_]] { | |
def traverse[A, B, F[_] ](a: T[A])(g: A => F[B])(implicit f: Applicative[F]): F[T[B]] | |
} | |
trait Monoid[A] { |
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
trait Applicative[F[_]] { | |
def pure[A](a: A): F[A] | |
def apply[A, B](f: F[A => B], a: F[A]): F[B] | |
} | |
trait Traversable[T[_], F[_]] { | |
def traverse[A, B](f: A => F[B], a: T[A]): F[T[B]] | |
} | |
trait Monoid[A] { |
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
package hlist | |
sealed trait List[A] | |
case class Cons[A](h: A, t: List[A]) extends List[A] | |
case object Nil extends List[Nothing] | |
sealed trait HList | |
case class :*:[+A, +B <: HList](h: A, t: B) extends HList { | |
def :*:[C](x: C): C :*: A :*: B = hlist.:*:(x, this) | |
} |
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
sealed trait Regex | |
case object Empty extends Regex | |
case class Let(c: Char) extends Regex | |
case class Con(a: Regex, b: Regex) extends Regex | |
case class Alt(a: Regex, b: Regex) extends Regex | |
case class Star(a: Regex) extends Regex | |
sealed trait Value | |
case class RInt(n: Int) extends Value | |
case class RStr(s: String) extends Value |
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
def compile(re: Regex): List[VMInst] = { | |
def loop(re: Regex, n: Int): (List[VMInst], Int) = re match { | |
case Empty => (Nil, n) | |
case Let(c) => (List(C(c)), n + 1) | |
case Con(a, b) => | |
val (c1, i1) = loop(a, n) | |
val (c2, i2) = loop(b, i1) | |
(c1 ++ c2, i2) | |
case Alt(a, b) => | |
val (c1, i1) = loop(a, n + 1) |
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
import fpinscala.tailrec._ | |
object Counting { | |
def normal (n : Int) : Int = | |
if (n == 0) 0 | |
else 1 + normal(n - 1) | |
def cps (n : Int) : Int = { | |
def loop (i : Int, k : Int => TailRec[Int]) : TailRec[Int] = | |
if (i == 0) k(0) |