2019-09-21から1日間の記事一覧

Scala Lazy!(Scala関数型デザインより)

「Scala関数型デザイン&プログラミング」の「第 5 章 正格 と 遅延」 ストリームによる、Lazy処理を行う。 コード package example.laziness import Stream._ trait Stream[+A] { def toListRecursive: List[A] = this match { case Cons(h,t) => h() :: t()…

ScalaのEither(Scala関数型デザインより)

「Scala関数型デザイン&プログラミング」の「第 4 章 例外 を 使わ ない エラー 処理」のEither編。 package example sealed trait Either[+E,+A] { def map[B](f: A => B): Either[E, B] = this match { case Right(a) => Right(f(a)) case Left(e) => Left…

ScalaのOption(Scala関数型デザインより)

「Scala関数型デザイン&プログラミング」の「第 4 章 例外 を 使わ ない エラー 処理」をやる。 package example sealed trait Option[+A] { def map[B](f: A => B): Option[B] = this match { case None => None case Some(x) => Some(f(x)) } def flatMap[…