This gist has been upgraded to a blog post here.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor.Actor | |
import akka.actor.ActorSystem | |
import akka.agent.Agent | |
import com.typesafe.config.ConfigFactory | |
import akka.event.Logging | |
import akka.actor.Props | |
import kafka.utils.Utils | |
import java.nio.ByteBuffer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object BenchmarkCommon { | |
import scala.util.Random | |
val DatasetSize = 10000 | |
val Iterations = 10000 | |
val ArrayPoolSize = 1000 | |
val ArrayPool = { | |
def randomArray(): Array[Int] = { | |
val array = new Array[Int](DatasetSize) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage examples: | |
val a = Vector(1,2,3).zipMany(Vector(1,2,3), Vector(5,6,7), Vector(8,9,10), Vector(11,12,13)) | |
Vector(Vector(1, 1, 5, 8, 11), Vector(2, 2, 6, 9, 12), Vector(3, 3, 7, 10, 13)) | |
a.unzipMany | |
Vector(Vector(1, 2, 3), Vector(1, 2, 3), Vector(5, 6, 7), Vector(8, 9, 10), Vector(11, 12, 13)) | |
// Implementation | |
import scala.collection._ | |
import scala.collection.generic.CanBuildFrom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Nested[A] { | |
def length(a: A): Int | |
def clone(a: A): A | |
} | |
object Nested { | |
implicit def nested[A] = new Nested[A] { | |
def length(a: A): Int = 1 | |
def clone(a: A): A = a | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection.generic.CanBuildFrom | |
import scala.collection.immutable.MapLike | |
import scala.collection.mutable | |
/** | |
* Immutable version of the PrefixMap demonstrated in the Scala collections | |
* guide here: http://www.scala-lang.org/docu/files/collections-api/collections-impl_6.html | |
* | |
* This version also has a smarter remove method (doesn't leave behind dead nodes with empty values) | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor._ | |
// need an actor system, make it implicit to it's used by all our repl based actors | |
implicit val system = ActorSystem("replActorSystem") | |
// this gives us an easy way to define simple actors | |
import ActorDSL._ | |
// make an actor that can be used to receive responses... just a good practice | |
implicit val sender = actor(new Act { become { case msg => println(s"Console sender recvd: $msg") } } ) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package aux | |
object Scaladores extends App { | |
implicit class AddOf(val num : Int) extends AnyVal { | |
def of[T <: MeasureUnit] = Value[T](num) | |
} | |
trait MeasureUnit | |
trait x[A <: MeasureUnit, B <: MeasureUnit] extends MeasureUnit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
case class Address(street : String, city : String, postcode : String) | |
case class Person(name : String, age : Int, address : Address) | |
// Exiting paste mode, now interpreting. | |
defined class Address | |
defined class Person |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> import syntax.typeable._ | |
import syntax.typeable._ | |
scala> val wat: Any = List(1, 2, 3, 4) | |
wat: Any = List(1, 2, 3, 4) | |
scala> wat.cast[List[Int]].map(_.sum) | |
res0: Option[Int] = Some(10) | |
scala> val wat2: Any = "foo" |
OlderNewer