アジェンダ
- HListについて
- Genericについて
class Bench { | |
@Benchmark | |
def set2seq(): Unit = (1 to 100).combinations(2).toList.flatten.toSet.toSeq | |
@Benchmark | |
def distinct(): Unit = (1 to 100).combinations(2).toList.flatten.distinct | |
} |
// stream | |
// ====== | |
locally { | |
val a: Stream[Int] = unfold(10) { x => if (x == 0) none else (x, x - 1).some } | |
assert(a.toList === List(10,9,8,7,6,5,4,3,2,1)) | |
} | |
// Memo | |
// メモ化 | |
// ====== |
import scalaz._, Scalaz._ | |
val f = (_: Int) + 1 | |
val g = (_: Int) * 2 | |
// Arrow | |
// ======== | |
locally { | |
// andThen | |
assert((f >>> g)(1) === 4) |
scala> val size = "300x250" | |
size: String = 300x250 | |
scala> val Array(w, h) = size split "x" map (_.toInt) | |
w: Int = 300 | |
h: Int = 250 | |
scala> val Array(w, h, z) = size split "x" map (_.toInt) | |
scala.MatchError: [I@606d6d2c (of class [I) | |
... 33 elided |
import scalaz._, Scalaz._ | |
// Tree | |
// Tree構造。TreeLocを使うとDOMのように多彩なアクセスができる。 | |
// ================== | |
locally { | |
val tree = 'A'.node( | |
'B'.node( | |
'C'.leaf | |
), |
import scalaz._, Scalaz._ | |
val f = (_: Int) + 1 | |
val g = (_: Int) + 2 | |
val h = for { | |
x <- f | |
y <- g | |
} yield { | |
x + y |
implicit class RichFunction1[A, B](val f: A => B) extends AnyVal { | |
def |>[C](g: B => C) = f andThen g | |
def <|[C](g: C => A) = f compose g | |
} | |
val plus = (_: Int) + 1 | |
val minus = (_: Int) - 1 | |
val suffix = (_: Int) + "!" | |
val f = plus |> minus |> suffix |
scala> def s[A: ({type λ[A] = A => Ordered[A]})#λ](xs: List[A]): List[A] = xs.sorted | |
s: [A](xs: List[A])(implicit evidence$1: A => scala.math.Ordered[A])List[A] |
scala> def fid[F[_], A](a: F[A]): F[A] = a | |
warning: there was one feature warning; re-run with -feature for details | |
fid: [F[_], A](a: F[A])F[A] | |
scala> fid(List(1)) | |
res0: List[Int] = List(1) | |
scala> fid(Option(1)) | |
res1: Option[Int] = Some(1) |