部分関数のことだよ
そもそも関数ってなあに?
// My `foldLeft` solution to http://blog.tmorris.net/scala-exercises-for-beginners/ | |
object FoldExercises { | |
// Exercise 2 | |
def sum(x: List[Int]): Int = | |
x.foldLeft(0){_ + _} | |
// Exercise 3 | |
def length[A](x: List[A]): Int = |
case class User(id: String, name: String, options: Seq[String]) { | |
def options(os: String*): User = copy(options = options ++ os) | |
} | |
case class Group(id: String, name: String, subgroups: Seq[Group], options: Seq[String]) { | |
def options(os: String*): Group = copy(options = options ++ os) | |
} |
/** | |
* To compile: | |
* scalac -optimize ByteBufferPerf.scala | |
* | |
* JAVA_OPTS="-Xmx2g" scala IntArrayPerf 10 | |
* 49 62 48 45 48 45 48 50 47 45 | |
* | |
* JAVA_OPTS="-Xmx2g" scala ByteBufferPerf 10 | |
* 479 491 484 480 484 481 477 477 472 473 |
!SLIDE
!SLIDE
trait EnumLike { | |
type Value | |
def value: Value | |
} | |
trait StringEnumLike extends EnumLike { | |
type Value = String | |
} |
sealed trait Interact[A] | |
case class Ask(prompt: String) | |
extends Interact[String] | |
case class Tell(msg: String) | |
extends Interact[Unit] | |
trait Monad[M[_]] { | |
def pure[A](a: A): M[A] |