Trying to understand what this means in the article below:
Finally, we use “sealed families of singleton objects extending functions” to organzse our filters, maps, and aggregations. In a nutshell, that means we can check equality on code paths as not to duplicate execution—which seemingly provides auto-magical distributed “memorization” but not via traditional AOP mechanisms.
Example run
$ bin/scala
Welcome to Scala version 2.10.6 (OpenJDK 64-Bit Server VM, Java 1.8.0_102).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :paste
// Entering paste mode (ctrl-D to finish)
sealed trait Transformer[P, Q] {
protected def transform(x: P): Q
def apply(x: P): Q = transform(x)
}
object Int2StringTransformer extends Transformer[Int, String] {
def transform(x: Int): String = x.toString
}
object List2SetTransformer extends Transformer[List[_], Set[_]] {
def transform(x: List[_]) = x.toSet
}
object Example {
def main(args: Array[String]) {
println(List2SetTransformer(List(10, 11)))
}
}
// Exiting paste mode, now interpreting.
defined trait Transformer
defined module Int2StringTransformer
defined module List2SetTransformer
defined module Example
scala> Example.main(Array())
Set(10, 11)
scala> Int2StringTransformer.transform(10)
res1: String = 10
Is that faster ? I read the article too and was confused ? What is the gain here ? Did you run any benchmark?