-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Adding FiniteDuration instances #2544
Merged
LukaJCB
merged 9 commits into
typelevel:master
from
calvinbrown085:finite-duration-instances
Oct 7, 2018
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e870942
Adding FiniteDuration instances
bff4dbc
Adding finiteDuration instances to cats core
cc8a9e7
not duplicating, just re-using an instance
112c3a2
Adding instances where they need to go
ac971aa
Adding tests to LawTests and a FiniteDurationSuite
639aa16
Merge branch 'master' of https://github.com/typelevel/cats into finit…
45bc92b
Fixing regex error
5efb422
Merge branch 'master' of github.com:calvinbrown085/cats into finite-d…
33cf30d
Fixing bin incompatibility
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package cats | ||
package instances | ||
|
||
import scala.concurrent.duration.FiniteDuration | ||
|
||
trait FiniteDurationInstances extends cats.kernel.instances.FiniteDurationInstances { | ||
implicit val catsStdShowForFiniteDuration: Show[FiniteDuration] = | ||
Show.fromToString[FiniteDuration] | ||
} |
This file contains 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
This file contains 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
This file contains 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
32 changes: 32 additions & 0 deletions
32
kernel/src/main/scala/cats/kernel/instances/finiteDuration.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package cats.kernel | ||
package instances | ||
|
||
import scala.concurrent.duration.{ Duration, FiniteDuration } | ||
|
||
|
||
trait FiniteDurationInstances { | ||
implicit val catsKernelStdOrderForFiniteDuration: Order[FiniteDuration] with Hash[FiniteDuration] = new FiniteDurationOrder | ||
implicit val catsKernelStdGroupForFiniteDuration: CommutativeGroup[FiniteDuration] = new FiniteDurationGroup | ||
} | ||
class FiniteDurationOrder extends Order[FiniteDuration] with Hash[FiniteDuration] { | ||
def hash(x: FiniteDuration): Int = x.hashCode() | ||
|
||
def compare(x: FiniteDuration, y: FiniteDuration): Int = x compare y | ||
|
||
override def eqv(x: FiniteDuration, y: FiniteDuration): Boolean = x == y | ||
override def neqv(x: FiniteDuration, y: FiniteDuration): Boolean = x != y | ||
override def gt(x: FiniteDuration, y: FiniteDuration): Boolean = x > y | ||
override def gteqv(x: FiniteDuration, y: FiniteDuration): Boolean = x >= y | ||
override def lt(x: FiniteDuration, y: FiniteDuration): Boolean = x < y | ||
override def lteqv(x: FiniteDuration, y: FiniteDuration): Boolean = x <= y | ||
|
||
override def min(x: FiniteDuration, y: FiniteDuration): FiniteDuration = x min y | ||
override def max(x: FiniteDuration, y: FiniteDuration): FiniteDuration = x max y | ||
} | ||
|
||
class FiniteDurationGroup extends CommutativeGroup[FiniteDuration] { | ||
def empty: FiniteDuration = Duration.Zero | ||
def inverse(x: FiniteDuration): FiniteDuration = -x | ||
def combine(x: FiniteDuration, y: FiniteDuration): FiniteDuration = x + y | ||
override def remove(x: FiniteDuration, y: FiniteDuration): FiniteDuration = x - y | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cats | ||
package tests | ||
|
||
import cats.laws.discipline.SerializableTests | ||
|
||
import scala.concurrent.duration.{ DurationInt, FiniteDuration } | ||
|
||
class FiniteDurationSuite extends CatsSuite { | ||
checkAll("Show[FiniteDuration]", SerializableTests.serializable(Show[FiniteDuration])) | ||
|
||
test("show works for FiniteDuration"){ | ||
Show[FiniteDuration].show(23.minutes) should ===("23 minutes") | ||
Show[FiniteDuration].show(10.seconds) should === ("10 seconds") | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 is binary incompatible, you should create another
AllInstancesBinCompat0
trait here, and then mix that intoall
. :)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.
Ah, that might be what I am missing :) Thank you
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.
Of course :)