-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Currency instances #4564
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
base: main
Are you sure you want to change the base?
Currency instances #4564
Changes from 4 commits
4669acb
9d4ec8a
fe4975b
58de8f0
17209a4
1ceeb9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2015 Typelevel | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package cats | ||
package instances | ||
|
||
import java.util.Currency | ||
|
||
trait CurrencyInstances extends cats.kernel.instances.CurrencyInstances { | ||
implicit val catsStdShowForCurrency: Show[Currency] = Show.fromToString[Currency] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2015 Typelevel | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package cats.kernel | ||
package laws | ||
|
||
import cats.kernel.compat.scalaVersionSpecific.* | ||
import cats.kernel.instances.currency.* | ||
import cats.kernel.laws.discipline.* | ||
import munit.DisciplineSuite | ||
import java.util.Currency | ||
import org.scalacheck.{Arbitrary, Cogen, Gen} | ||
|
||
class JvmLawTests extends TestsConfig with DisciplineSuite { | ||
implicit private val arbitraryCurrency: Arbitrary[Currency] = Arbitrary( | ||
Gen.oneOf(Currency.getAvailableCurrencies().asScala) | ||
) | ||
implicit private val cogenCurrency: Cogen[Currency] = Cogen[String].contramap(_.getCurrencyCode()) | ||
|
||
checkAll("Eq[Currency]", EqTests[Currency].eqv) | ||
checkAll("Hash[Currency]", HashTests[Currency].hash) | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -21,7 +21,8 @@ | |||||||||||||
|
||||||||||||||
package cats.kernel.compat | ||||||||||||||
import scala.annotation.{Annotation, StaticAnnotation} | ||||||||||||||
import scala.collection.{IterableLike, TraversableLike} | ||||||||||||||
import scala.collection.{mutable, IterableLike, TraversableLike} | ||||||||||||||
import scala.collection.convert.ImplicitConversionsToScala.* | ||||||||||||||
satorg marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
|
||||||||||||||
private[cats] object scalaVersionSpecific { | ||||||||||||||
|
||||||||||||||
|
@@ -50,4 +51,8 @@ private[cats] object scalaVersionSpecific { | |||||||||||||
that: T | ||||||||||||||
)(implicit w1: A => TraversableLike[El1, Repr1], w2: T => IterableLike[El2, Repr2]) = (a, that).zipped | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
implicit class setExtension[A](private val s: java.util.Set[A]) extends AnyVal { | ||||||||||||||
def asScala: mutable.Set[A] = `set asScala`(s) | ||||||||||||||
} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This extension method is only used for
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Besides, if this extension method is for the sake of testing only, I wonder if it'd make sense to move it from "main" to "test" scope? |
||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ package kernel | |
|
||
package compat | ||
import scala.annotation.{Annotation, StaticAnnotation} | ||
import scala.collection.mutable | ||
import scala.jdk.CollectionConverters.* | ||
|
||
private[cats] object scalaVersionSpecific { | ||
|
||
|
@@ -35,4 +37,8 @@ private[cats] object scalaVersionSpecific { | |
implicit class iterableOnceExtension[A](private val io: IterableOnce[A]) extends AnyVal { | ||
def reduceOption(f: (A, A) => A): Option[A] = io.iterator.reduceOption(f) | ||
} | ||
|
||
implicit class setExtension[A](private val s: java.util.Set[A]) extends AnyVal { | ||
def asScala: mutable.Set[A] = SetHasAsScala(s).asScala | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I doubt that import scala.jdk.javaapi.CollectionConverters
...
def asScala: Iterable[A] = CollectionConverters.asScala(x)
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2015 Typelevel | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package cats.kernel | ||
package instances | ||
|
||
import java.util.Currency | ||
|
||
trait CurrencyInstances { | ||
implicit val catsKernelStdHashForCurrency: Hash[Currency] = Hash.fromUniversalHashCode[Currency] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) 2015 Typelevel | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package cats.kernel | ||
package instances | ||
|
||
package object currency extends CurrencyInstances |
Uh oh!
There was an error while loading. Please reload this page.