0

I have a list as below

    val S = Interval.open(1.0, 4.5)
    val A = Interval.open(1.0, 3.0)
    val B = Interval.open(2.0, 4.0)
    val C = Interval.openUpper(3.0, 4.5)
    val list = (S \ A).union(S \ B)
    println(list)

List([3.0, 4.5), (1.0, 2.0], [4.0, 4.5))

and I want to sort it.

 println(list.sorted)

But is giving the error as below

Error:(18, 18) No implicit Ordering defined for spire.math.Interval[Double].
    println(list.sorted)(Ordering)

But I'm not sure where that implicit be available.

  1. where that implicit might have declared.

How to find in library where that implicit is available ?

Curious
  • 921
  • 1
  • 9
  • 25
  • 4
    What makes you think that such an implicit exists? Is there a natural order such that that one `Interval` should obviously come before/after another? – jwvh Jan 31 '19 at 04:59
  • But there may exist the partial order as below https://en.wikipedia.org/wiki/Interval_order. and https://en.wikipedia.org/wiki/Partially_ordered_set#Formal_definition – Curious Jan 31 '19 at 07:27
  • @Curious What should be `list.sorted` for `list = List(Interval.open(0.0, 2.0), Interval.open(1.0, 3.0))` and for `list = List(Interval.open(1.0, 3.0), Interval.open(0.0, 2.0))`? – Dmytro Mitin Jan 31 '19 at 08:11
  • [PartiallyOrdered](https://www.scala-lang.org/api/2.12.8/scala/math/PartiallyOrdered.html) is a different trait. – Dmytro Mitin Jan 31 '19 at 08:11
  • 1
    I'm not sure, but it can be helpful to prepare a solution for your problem: https://stackoverflow.com/q/19345030/8291971 – Patryk Rudnicki Jan 31 '19 at 11:23

0 Answers0