Last active
December 20, 2015 03:29
-
-
Save willf/6063944 to your computer and use it in GitHub Desktop.
arbitrary sort orderings using contramaps from scalaz (via Cody Allen)
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
import scalaz.Order | |
case class WeightedConcept(id: String, weight: Double) | |
val concepts = List(WeightedConcept("one", 1.0), WeightedConcept("two", 0.5)) | |
val weightOrder: Order[WeightedConcept] = implicitly[Order[Double]].contramap[WeightedConcept](_.weight) | |
concepts.sorted(weightOrder.toScalaOrdering) | |
concepts.sorted(weightOrder.reverseOrder.toScalaOrdering) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment