Skip to content

Instantly share code, notes, and snippets.

case class Foo(a: String, b: Int)
object Foo {
def apply(a: String, b: String) = new Foo(a, b.toInt)
}
val format = jsonFormat2[Foo](new {
def apply(a: String, b: Int): Foo = Foo(a, b)
def unapply(f: Foo) = Foo.unapply(f)
start = Time.now
100.times do
letter_list = []
alphabet = ('a'..'z').to_a
100_000.times{ letter_list << alphabet[rand(26)] }
pick = letter_list.uniq[rand(26)]
before, after = letter_list.partition{|n| n > pick}
end
p (Time.now - start) * 1000
// Symbols converted to Strings in Scala retain their literal notation
// with the leading apostraphe, so we have to drop dat to get the same
// output as Ruby.
Seq('bradley, 'ryan, 'sam, 'scott).map(_.toString.drop(1).toUpperCase)
// Here's a for-comprehension, which doesn't look as nice in the trivial
// example, but if you're going to nest maps/filters/etc, can be much
// more readable in the complex/compound operations:
for(name <- Seq('bradley, 'ryan, 'sam, 'scott)) yield name.toString.drop(1).toUpperCase