Skip to content

Instantly share code, notes, and snippets.

@cb372
Created September 8, 2013 12:54
Show Gist options
  • Save cb372/6484517 to your computer and use it in GitHub Desktop.
Save cb372/6484517 to your computer and use it in GitHub Desktop.
Mapping a Set
Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_09).
Type in expressions to have them evaluated.
Type :help for more information.
scala> case class Foo(a: Int, b: Int)
defined class Foo
scala> Set(Foo(1, 10), Foo(2, 10), Foo(3, 20))
res0: scala.collection.immutable.Set[Foo] = Set(Foo(1,10), Foo(2,10), Foo(3,20))
scala> res0.map(_.b)
res1: scala.collection.immutable.Set[Int] = Set(10, 20)
scala> res1.size
res2: Int = 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment