Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/src/main/scala-2.12/cats/instances/all.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ abstract class AllInstancesBinCompat
with AllInstancesBinCompat6
with AllInstancesBinCompat7
with AllInstancesBinCompat8
with AllInstancesBinCompat10

trait AllInstances
extends AnyValInstances
Expand Down Expand Up @@ -94,3 +95,5 @@ trait AllInstancesBinCompat7 extends SeqInstances
trait AllInstancesBinCompat8 extends DeadlineInstances

trait AllInstancesBinCompat9 extends InvariantInstances with InvariantInstancesBinCompat0

trait AllInstancesBinCompat10 extends CurrencyInstances
3 changes: 3 additions & 0 deletions core/src/main/scala-2.13+/cats/instances/all.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ abstract class AllInstancesBinCompat
with AllInstancesBinCompat7
with AllInstancesBinCompat8
with AllInstancesBinCompat9
with AllInstancesBinCompat11

trait AllInstances
extends AnyValInstances
Expand Down Expand Up @@ -99,3 +100,5 @@ trait AllInstancesBinCompat8 extends InvariantInstances
trait AllInstancesBinCompat9 extends DeadlineInstances

trait AllInstancesBinCompat10 extends InvariantInstancesBinCompat0

trait AllInstancesBinCompat11 extends CurrencyInstances
29 changes: 29 additions & 0 deletions core/src/main/scala/cats/instances/currency.scala
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]
}
41 changes: 41 additions & 0 deletions kernel-laws/jvm/src/test/scala/cats/kernel/laws/JvmLawTests.scala
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package kernel

package compat
import scala.annotation.{Annotation, StaticAnnotation}
import scala.jdk.javaapi.CollectionConverters

private[cats] object scalaVersionSpecific {

Expand All @@ -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(x)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def asScala: Iterable[A] = CollectionConverters.asScala(x)
def asScala: Iterable[A] = CollectionConverters.asScala(s)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Expand Up @@ -27,3 +27,4 @@ package object all
with AllInstancesBinCompat0
with AllInstancesBinCompat1
with AllInstancesBinCompat2
with AllInstancesBinCompat3
25 changes: 25 additions & 0 deletions kernel/src/main/scala/cats/kernel/instances/currency/package.scala
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
Loading