Created
June 21, 2010 18:49
-
-
Save runarorama/447295 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
class OrderedSequence[A: Order](v: FingerTree[A => Boolean, A]) extends NewType[FingerTree[A => Boolean, A]] { | |
val value = v | |
def +(a: A) = { | |
val spl = v.split(x => x(a)) | |
new OrderedSequence(spl._1 <++> (a <+: spl._2)) | |
} | |
override def toString = v.toString | |
} | |
object OrderedSequence { | |
def empty[A: Order] = { | |
implicit val r: Reducer[A, A => Boolean] = Reducer((a: A) => (b: A) => a gt b)(new Monoid[A => Boolean] { | |
def append(s1: A => Boolean, s2: => (A => Boolean)) = (a: A) => s1(a) || s2.apply(a) | |
val zero = (a: A) => false | |
}) | |
new OrderedSequence(FingerTree.empty[A => Boolean, A]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment