-
Notifications
You must be signed in to change notification settings - Fork 347
Remove typeclass from interval constructor #605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| def apply(t: T) = contains(t) | ||
| def &&(that: Interval[T]) = intersect(that) | ||
| def intersect(that: Interval[T])(implicit ord: Ordering[T]): Interval[T] | ||
| def apply(t: T)(implicit ord: Ordering[T]) = contains(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make apply and && final
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| * TODO: It might be good to have types for these properties in algebird. | ||
| */ | ||
| def mapNonDecreasing[U: Ordering](fn: T => U): Interval[U] | ||
| def mapNonDecreasing[U](fn: T => U): Interval[U] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we need a test for mapNonDecreasing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So a law might be: forAll intervals and values t, if we map t and the interval, contains returns the same value.
To make the function non-decreasing we will need to do something like make a new fn and apple the first and if the result is less return the input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| */ | ||
| def toLeftClosedRightOpen(implicit s: Successible[T]): Option[Intersection[InclusiveLower, ExclusiveUpper, T]] = { | ||
| implicit val ord = lower.ordering | ||
| def toLeftClosedRightOpen(implicit s: Successible[T]): Option[Intersection[InclusiveLower, ExclusiveUpper, T]] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to see if we can just jump Successible and Predecessible up to Ordering. I can't think of a good reason to have Partial there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it works great!
| * that are contained in this Intersection | ||
| */ | ||
| def leastToGreatest(implicit s: Successible[T]): Iterable[T] = { | ||
| def leastToGreatest(implicit s: Successible[T], ord: Ordering[T]): Iterable[T] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need ord now that Successible has an Ordering right?
| * that are contained in this Intersection | ||
| */ | ||
| def greatestToLeast(implicit p: Predecessible[T]): Iterable[T] = { | ||
| def greatestToLeast(implicit p: Predecessible[T], ord: Ordering[T]): Iterable[T] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need ord here, right?
| * The law is: | ||
| * prev(t) | ||
| * .map { n => partialOrdering.lteq(n, t) && (!partialOrdering.equiv(t, n)) } | ||
| * .map { n => ordering.lteq(n, t) && (!ordering.equiv(t, n)) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be more succinct now: prev(t).map(ordering.lt(_, t)).getOrElse(true)
| * The law is: | ||
| * next(t) | ||
| * .map { n => partialOrdering.lteq(t, n) && (!partialOrdering.equiv(t, n)) } | ||
| * .map { n => ordering.lteq(t, n) && (!ordering.equiv(t, n)) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar: next(t).map(ordering.lt(t, _)).getOrElse(true)
200139d to
d9deab1
Compare
Current coverage is 80.64% (diff: 73.21%)@@ develop #605 diff @@
==========================================
Files 110 110
Lines 4924 4940 +16
Methods 4468 4502 +34
Messages 0 0
Branches 456 438 -18
==========================================
+ Hits 3951 3984 +33
+ Misses 973 956 -17
Partials 0 0
|
Moves the
Orderinginputs from the constructor to the methods that need it, as discussed in #600 .