-
Notifications
You must be signed in to change notification settings - Fork 156
/
Bounded.scala
42 lines (32 loc) · 1.02 KB
/
Bounded.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package eu.timepit.refined.scalacheck.util
/**
* Auxiliary type class that provides the upper and lower bounds of a
* type `T`. This is needed for the `Arbitrary` instances of numeric
* refined types.
*/
trait Bounded[T] {
def minValue: T
def maxValue: T
}
object Bounded {
def apply[T](implicit b: Bounded[T]): Bounded[T] = b
def instance[T](min: T, max: T): Bounded[T] =
new Bounded[T] {
val minValue = min
val maxValue = max
}
implicit val byte: Bounded[Byte] =
instance(Byte.MinValue, Byte.MaxValue)
implicit val char: Bounded[Char] =
instance(Char.MinValue, Char.MaxValue)
implicit val double: Bounded[Double] =
instance(Double.MinValue, Double.MaxValue)
implicit val float: Bounded[Float] =
instance(Float.MinValue, Float.MaxValue)
implicit val int: Bounded[Int] =
instance(Int.MinValue, Int.MaxValue)
implicit val long: Bounded[Long] =
instance(Long.MinValue, Long.MaxValue)
implicit val short: Bounded[Short] =
instance(Short.MinValue, Short.MaxValue)
}