Skip to content

Instantly share code, notes, and snippets.

@gkthiruvathukal
Created February 6, 2015 03:58
Show Gist options
  • Select an option

  • Save gkthiruvathukal/32b3189dea5e88c195df to your computer and use it in GitHub Desktop.

Select an option

Save gkthiruvathukal/32b3189dea5e88c195df to your computer and use it in GitHub Desktop.
Tuple Sort Scala Worksheet
val wlist = List("alpha", "gamma", "beta", "epsilon")
case class DerivedData(s : String, len : Int)
val tlist = wlist map { n => DerivedData(n, n.length) }
val sortedBy1 = tlist.sortWith( (l, r) => l.s < r.s)
println("sorted by component 1")
sortedBy1 foreach println
val sortedBy2 = tlist.sortWith( (l, r) => l.len < r.len)
println("sorted by component 2")
sortedBy2 foreach println
val wlist = List("alpha", "gamma", "beta", "epsilon")
val tlist = wlist map { n => (n, n.length) }
val sortedBy1 = tlist.sortWith( (l, r) => l._1 < r._1)
println("sorted by component 1")
sortedBy1 foreach println
// Trying to sort on field _2 causes Scala compiler to tank. Yikes.
val sortedBy2 = tlist.sortWith( (l, r) => l._2 < r._2)
println("sorted by component 2")
sortedBy2 foreach println
@gkthiruvathukal

Copy link
Copy Markdown
Author

This looks like a regression in 2.11.5. Apparently, both 2.10.4 and 2.11.4 can run TupleSort.sc just fine.

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