/
Bounds.scala
30 lines (26 loc) · 911 Bytes
/
Bounds.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
package autowire
import scala.language.higherKinds
/**
* Utility classes to fit 0 or 2 context bounds into 1
*/
object Bounds{
/**
* Type representing two contexts bounds, in order to squeeze them into
* one. Can be used as a context bound via `: Bounds.Two[TypeA, TypeB]`
* and the implicits inside extracted via
* `implicit (t1, t2) = Bounds.Two()`
*/
class Two[T, T1[_], T2[_]]()(implicit val t1: T1[T], val t2: T2[T])
object Two{
implicit def twoBounds[T, T1[_], T2[_]](implicit t1: T1[T], t2: T2[T]): Two[T, T1, T2] = new Two()(t1, t2)
def apply[T, T1[_], T2[_]]()(implicit two: Two[T, T1, T2]): (T1[T], T2[T]) = (two.t1, two.t2)
}
/**
* Type representing the lack-of a context-bound. Can be used as a
* context bound via `: Bounds.None` an will always be satisfied.
*/
class None[T]
object None{
implicit def noBound[T]: None[T] = new None[T]
}
}