This file contains hidden or 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
// 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 |
This file contains hidden or 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
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 |
This file contains hidden or 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
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) |