-
Notifications
You must be signed in to change notification settings - Fork 155
/
auto.scala
33 lines (30 loc) · 983 Bytes
/
auto.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
package eu.timepit.refined
import eu.timepit.refined.api.RefType
/**
* Module that provides automatic refinements and automatic conversions
* between refined types (refinement subtyping) at compile-time.
*/
object auto {
/**
* Implicitly unwraps the `T` from a value of type `F[T, P]` using the
* `[[api.RefType]]` instance of `F`. This allows a `F[T, P]` to be
* used as it were a subtype of `T`.
*
* Example: {{{
* scala> import eu.timepit.refined.auto.autoUnwrap
* | import eu.timepit.refined.types.numeric.PosInt
*
* scala> def plusOne(i: Int): Int = i + 1
* | val x = PosInt.unsafeFrom(42)
*
* // converts x implicitly to an Int:
* scala> plusOne(x)
* res0: Int = 43
* }}}
*
* Note: This conversion is not needed if `F[T, _] <: T` holds (which
* is the case for `shapeless.tag.@@`, for example).
*/
implicit def autoUnwrap[F[_, _], T, P](tp: F[T, P])(implicit rt: RefType[F]): T =
rt.unwrap(tp)
}