-
Notifications
You must be signed in to change notification settings - Fork 3
/
EqualComparable.scala
56 lines (48 loc) · 1.39 KB
/
EqualComparable.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.rallyhealth.vapors.v1
package algebra
import cats.{Eq, Functor, Semigroupal}
import shapeless.Id
/**
* Defines equality over an effect type `F` with a provided param `OP`
*
* @tparam W the wrapper (or effect) type over which equality is computed
* @tparam V the value type to compare for equality
* @tparam OP the custom output parameter type constructor (defined by the imported DSL).
* See [[dsl.DslTypes.OP]] for more details.
*/
trait EqualComparable[W[_], V, OP[_]] {
def isEqual(
left: W[V],
right: W[V],
)(implicit
opV: OP[W[V]],
opO: OP[W[Boolean]],
): W[Boolean]
}
object EqualComparable extends LowPriorityEqualComparable {
implicit def eq[V : Eq, OP[_]]: EqualComparable[Id, V, OP] =
new EqualComparable[Id, V, OP] {
override final def isEqual(
left: V,
right: V,
)(implicit
opV: OP[V],
opO: OP[Boolean],
): Boolean = Eq[V].eqv(left, right)
}
}
sealed trait LowPriorityEqualComparable {
implicit def semigroupalFunctorEq[W[_] : Functor : Semigroupal, V : Eq, OP[_]]: EqualComparable[W, V, OP] =
new EqualComparable[W, V, OP] {
override final def isEqual(
left: W[V],
right: W[V],
)(implicit
opV: OP[W[V]],
opO: OP[W[Boolean]],
): W[Boolean] = {
import cats.syntax.apply._
(left, right).mapN(Eq[V].eqv)
}
}
}