diff --git a/core/src/main/scala-2.12/cats/instances/all.scala b/core/src/main/scala-2.12/cats/instances/all.scala index 1628094e95..04de602a17 100644 --- a/core/src/main/scala-2.12/cats/instances/all.scala +++ b/core/src/main/scala-2.12/cats/instances/all.scala @@ -33,6 +33,7 @@ abstract class AllInstancesBinCompat with AllInstancesBinCompat6 with AllInstancesBinCompat7 with AllInstancesBinCompat8 + with AllInstancesBinCompat10 trait AllInstances extends AnyValInstances @@ -94,3 +95,5 @@ trait AllInstancesBinCompat7 extends SeqInstances trait AllInstancesBinCompat8 extends DeadlineInstances trait AllInstancesBinCompat9 extends InvariantInstances with InvariantInstancesBinCompat0 + +trait AllInstancesBinCompat10 extends CurrencyInstances diff --git a/core/src/main/scala-2.13+/cats/instances/all.scala b/core/src/main/scala-2.13+/cats/instances/all.scala index f57d80ac52..54beb5114b 100644 --- a/core/src/main/scala-2.13+/cats/instances/all.scala +++ b/core/src/main/scala-2.13+/cats/instances/all.scala @@ -34,6 +34,7 @@ abstract class AllInstancesBinCompat with AllInstancesBinCompat7 with AllInstancesBinCompat8 with AllInstancesBinCompat9 + with AllInstancesBinCompat11 trait AllInstances extends AnyValInstances @@ -99,3 +100,5 @@ trait AllInstancesBinCompat8 extends InvariantInstances trait AllInstancesBinCompat9 extends DeadlineInstances trait AllInstancesBinCompat10 extends InvariantInstancesBinCompat0 + +trait AllInstancesBinCompat11 extends CurrencyInstances diff --git a/core/src/main/scala/cats/instances/currency.scala b/core/src/main/scala/cats/instances/currency.scala new file mode 100644 index 0000000000..f53bfd3d49 --- /dev/null +++ b/core/src/main/scala/cats/instances/currency.scala @@ -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] +} diff --git a/kernel-laws/jvm/src/test/scala/cats/kernel/laws/JvmLawTests.scala b/kernel-laws/jvm/src/test/scala/cats/kernel/laws/JvmLawTests.scala new file mode 100644 index 0000000000..e07cb0bed1 --- /dev/null +++ b/kernel-laws/jvm/src/test/scala/cats/kernel/laws/JvmLawTests.scala @@ -0,0 +1,41 @@ +/* + * 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 cats.kernel.laws.scalaVersionSpecific.* +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) +} diff --git a/kernel-laws/shared/src/test/scala-2.12/cats/kernel/laws/scalaVersionSpecific.scala b/kernel-laws/shared/src/test/scala-2.12/cats/kernel/laws/scalaVersionSpecific.scala new file mode 100644 index 0000000000..cbf9feb7db --- /dev/null +++ b/kernel-laws/shared/src/test/scala-2.12/cats/kernel/laws/scalaVersionSpecific.scala @@ -0,0 +1,32 @@ +/* + * 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.laws +import scala.annotation.{Annotation, StaticAnnotation} +import scala.collection.{mutable, IterableLike, TraversableLike} +import scala.collection.JavaConverters._ + +private[cats] object scalaVersionSpecific { + + implicit class iterableExtension[A](private val s: java.lang.Iterable[A]) extends AnyVal { + def asScala: Iterable[A] = iterableAsScalaIterable(s) + } +} diff --git a/kernel-laws/shared/src/test/scala-2.13+/cats/kernel/laws/scalaVersionSpecific.scala b/kernel-laws/shared/src/test/scala-2.13+/cats/kernel/laws/scalaVersionSpecific.scala new file mode 100644 index 0000000000..e11db668ae --- /dev/null +++ b/kernel-laws/shared/src/test/scala-2.13+/cats/kernel/laws/scalaVersionSpecific.scala @@ -0,0 +1,24 @@ +/* + * 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.laws + +private[cats] object scalaVersionSpecific diff --git a/kernel/src/main/scala-2.12/cats/kernel/instances/AllInstances.scala b/kernel/src/main/scala-2.12/cats/kernel/instances/AllInstances.scala index 8bc45b444e..54394e98ea 100644 --- a/kernel/src/main/scala-2.12/cats/kernel/instances/AllInstances.scala +++ b/kernel/src/main/scala-2.12/cats/kernel/instances/AllInstances.scala @@ -60,3 +60,5 @@ private[instances] trait AllInstancesBinCompat0 extends FiniteDurationInstances private[instances] trait AllInstancesBinCompat1 extends SortedMapInstances with SortedSetInstances private[instances] trait AllInstancesBinCompat2 extends DeadlineInstances + +private[instances] trait AllInstancesBinCompat3 extends CurrencyInstances diff --git a/kernel/src/main/scala-2.13+/cats/kernel/compat/scalaVersionSpecific.scala b/kernel/src/main/scala-2.13+/cats/kernel/compat/scalaVersionSpecific.scala index d59fe29167..4224b05a1a 100644 --- a/kernel/src/main/scala-2.13+/cats/kernel/compat/scalaVersionSpecific.scala +++ b/kernel/src/main/scala-2.13+/cats/kernel/compat/scalaVersionSpecific.scala @@ -24,6 +24,7 @@ package kernel package compat import scala.annotation.{Annotation, StaticAnnotation} +import scala.jdk.javaapi.CollectionConverters private[cats] object scalaVersionSpecific { @@ -35,4 +36,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: Iterable[A] = CollectionConverters.asScala(s) + } } diff --git a/kernel/src/main/scala-2.13+/cats/kernel/instances/AllInstances.scala b/kernel/src/main/scala-2.13+/cats/kernel/instances/AllInstances.scala index 773ffaa80d..850d851f44 100644 --- a/kernel/src/main/scala-2.13+/cats/kernel/instances/AllInstances.scala +++ b/kernel/src/main/scala-2.13+/cats/kernel/instances/AllInstances.scala @@ -62,3 +62,5 @@ private[instances] trait AllInstancesBinCompat0 extends FiniteDurationInstances private[instances] trait AllInstancesBinCompat1 extends SortedMapInstances with SortedSetInstances private[instances] trait AllInstancesBinCompat2 extends DeadlineInstances + +private[instances] trait AllInstancesBinCompat3 extends CurrencyInstances diff --git a/kernel/src/main/scala/cats/kernel/instances/CurrencyInstances.scala b/kernel/src/main/scala/cats/kernel/instances/CurrencyInstances.scala new file mode 100644 index 0000000000..06ac655c68 --- /dev/null +++ b/kernel/src/main/scala/cats/kernel/instances/CurrencyInstances.scala @@ -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] +} diff --git a/kernel/src/main/scala/cats/kernel/instances/all/package.scala b/kernel/src/main/scala/cats/kernel/instances/all/package.scala index ab6901c941..1f1f76368a 100644 --- a/kernel/src/main/scala/cats/kernel/instances/all/package.scala +++ b/kernel/src/main/scala/cats/kernel/instances/all/package.scala @@ -27,3 +27,4 @@ package object all with AllInstancesBinCompat0 with AllInstancesBinCompat1 with AllInstancesBinCompat2 + with AllInstancesBinCompat3 diff --git a/kernel/src/main/scala/cats/kernel/instances/currency/package.scala b/kernel/src/main/scala/cats/kernel/instances/currency/package.scala new file mode 100644 index 0000000000..52f50b0f30 --- /dev/null +++ b/kernel/src/main/scala/cats/kernel/instances/currency/package.scala @@ -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