Useful 等の公開すべきでないものが公開されている。 型が書かれていない public なメンバも多く、API に対する意識が低い。
Pk, Id, NoAssigned 等は Magic のために導入された型だが、
imoprt Iteratee._ | |
lazy val takeOdds = { | |
val aux = for { | |
one <- headOption[Byte[Array]] // ダサい | |
_ <- headOption[Byte[Array]] // ダサい | |
} yield one | |
for { | |
odds <- aux |
!SLIDE | |
Play 2.0 の Action と BodyParser について学ぼう | |
---------------- | |
!SLIDE | |
自己紹介 | |
---------------- | |
* 望月 慎也 | |
* @lyrical_logical | |
* 株式会社レピダム |
lazy val fab: PartialFunction[Base, Int] = { | |
case A(base) => 1 + fabc(base) // PartialFunction#apply の呼び出し。危ない! | |
case B(left, right) => 1 + fabcd(left) + fabcd(right) // 同様 | |
} | |
// 全域関数だと scala コンパイラにはわからない! | |
lazy val fabcd: PartialFunction[Base, Int] = fab orElse { | |
case C => 1 | |
case D => 2 | |
} |
type 'a node = | |
| A: int -> int node | |
| B: string -> string node | |
module type Exists = sig | |
type t | |
val ret: t node | |
end | |
module type PolyFun = sig |
trait Zero[A] { val zero: A } | |
implicit val IntZero = new Zero[Int] { val zero = 0 } | |
implicit def RightProjectionWithFilter[A, B](r: Either.RightProjection[A, B])(implicit azero: Zero[A]) = new { | |
class WithFilter(p: B => Boolean) { | |
def map[C](f: B => C): Either[A, C] = r.filter(p).getOrElse(Left(azero.zero)).right.map(f) | |
def flatMap[AA >: A, C](f: B => Either[AA, C]): Either[AA, C] = r.filter(p).getOrElse(Left(azero.zero)).right.flatMap(f) | |
def withFilter(p0: B => Boolean): WithFilter = new WithFilter(b => p(b) && p0(b)) | |
} | |
def withFilter(p: B => Boolean): WithFilter = new WithFilter(p) |
def withRight[A, B] = new { def apply[R](f: (Either[A, B] => Either.RightProjection[A, B]) => R) = f(_.right) } | |
def withLeft[A, B] = new { def apply[R](f: (Either[A, B] => Either.LeftProjection[A, B]) => R) = f(_.left) } | |
withRight[Int, Int] { implicit ev => | |
for { | |
x <- Right(1) | |
y <- Right(2) | |
} yield x + y // => Right(3) | |
for { | |
x <- Right(1) |
trait Abs { def f(): Int } | |
trait ConA extends Abs { def f() = 1 } | |
trait ConB extends Abs { abstract override def f() = super.f + 1 } | |
trait Delegate extends Abs { | |
val abs: Abs | |
def f() = abs.f | |
} | |
class A { this: Abs => |
Inductive even : nat -> Prop := | |
| even_O : even 0 | |
| even_S : forall n, odd n -> even (S n) | |
with odd : nat -> Prop := | |
| odd_S : forall n, even n -> odd (S n). | |
Scheme even_mut := Induction for even Sort Prop | |
with odd_mut := Induction for odd Sort Prop. | |
Theorem daigakuseinosuugakuryoku : forall n m, |
parseOpt(request.body) map { json => | |
(json \\ "events" \\ "message").values | |
} collect { case msg : Map[String, String] => | |
hoge | |
} getOrElse { | |
huga | |
} |