Created
April 17, 2010 01:16
-
-
Save moonpolysoft/369156 to your computer and use it in GitHub Desktop.
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
| object ComparableSeq { | |
| implicit def seqToComparableSeq[A <: Comparable[A]](seq : Seq[A]) : ComparableSeq[A] = { | |
| new ComparableSeq(seq) | |
| } | |
| } | |
| class ComparableSeq[A <: Comparable[A]](seq : Seq[A]) extends Seq[A] with Ordered[Seq[A]] { | |
| def compare(lhs : Seq[A]) : Int = { | |
| if (seq.length > lhs.length) { | |
| 1 | |
| } else if (seq.length < lhs.length) { | |
| -1 | |
| } else { | |
| compareRecurse(seq.toList, lhs.toList) | |
| } | |
| } | |
| private def compareRecurse(rhs : List[A], lhs : List[A]) : Int = (rhs,lhs) match { | |
| case (Nil, Nil) => 0 | |
| case (rHead :: rTail, lHead :: lTail) => | |
| rHead compareTo lHead match { | |
| case 0 => compareRecurse(rTail,lTail) | |
| case i => i | |
| } | |
| } | |
| } |
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
| inferred type arguments [Byte] do not conform to method seqToComparableSeq's type parameter bounds [A <: java.lang.Comparable[A]] | |
| [error] case add : Ipv4Address => seqToComparableSeq(this.bytes).compare(add.bytes) | |
| [error] ^ | |
| [error] one error found |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment