Skip to content

Instantly share code, notes, and snippets.

@debasishg
Created October 24, 2013 12:07
Show Gist options
  • Select an option

  • Save debasishg/7136051 to your computer and use it in GitHub Desktop.

Select an option

Save debasishg/7136051 to your computer and use it in GitHub Desktop.
scala> List("a", "b", "AA", "d")
res0: List[String] = List(a, b, AA, d)
// List.sortBy, List.sorted and TreeMap all take an implicit scala.math.Ordering
// just define the following at the top of StorageRepoQueries
scala> object CaseInsensitiveOrdering extends Ordering[String] {
| def compare(a: String, b: String) = a.toLowerCase compare b.toLowerCase
| }
defined module CaseInsensitiveOrdering
// and pass the Ordering object in all places we call sort or create a TreeMap
scala> res0.sorted(CaseInsensitiveOrdering)
res6: List[String] = List(a, AA, b, d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment