Skip to content

Instantly share code, notes, and snippets.

@tototoshi
Last active August 13, 2017 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tototoshi/a67b5a38be3f7de846628f5e28b58287 to your computer and use it in GitHub Desktop.
Save tototoshi/a67b5a38be3f7de846628f5e28b58287 to your computer and use it in GitHub Desktop.
SortedSet#map
scala> import scala.collection.immutable.SortedSet
import scala.collection.immutable.SortedSet
scala> case class Hoge(i: Int)
defined class Hoge
scala> SortedSet(1, 2, 3, 4, 5)
res0: scala.collection.immutable.SortedSet[Int] = TreeSet(1, 2, 3, 4, 5)
scala> SortedSet(1, 2, 3, 4, 5).map(Hoge.apply)
res1: scala.collection.immutable.Set[Hoge] = Set(Hoge(4), Hoge(1), Hoge(3), Hoge(5), Hoge(2))
scala> SortedSet(1, 2, 3, 4, 5).map(1+)
warning: there was one feature warning; re-run with -feature for details
res2: scala.collection.immutable.SortedSet[Int] = TreeSet(2, 3, 4, 5, 6)
scala> implicit val o: Ordering[Hoge] = Ordering.by(h => h.i)
o: Ordering[Hoge] = scala.math.Ordering$$anon$9@e27ba81
scala> SortedSet(1, 2, 3, 4, 5).map(Hoge.apply)
res3: scala.collection.immutable.SortedSet[Hoge] = TreeSet(Hoge(1), Hoge(2), Hoge(3), Hoge(4), Hoge(5))
@xuwei-k
Copy link

xuwei-k commented Aug 13, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment