Skip to content

Commit 6ba7e4b

Browse files
committed
Convert back multi-method type class instances to anonymous classes
1 parent 7600153 commit 6ba7e4b

File tree

4 files changed

+16
-43
lines changed

4 files changed

+16
-43
lines changed

kernel/src/main/scala/cats/kernel/CommutativeGroup.scala

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,4 @@ object CommutativeGroup extends GroupFunctions[CommutativeGroup] {
1414
* Access an implicit `CommutativeGroup[A]`.
1515
*/
1616
@inline final def apply[A](implicit ev: CommutativeGroup[A]): CommutativeGroup[A] = ev
17-
18-
/**
19-
* Create a `CommutativeGroup` instance from the given inverse and combine functions and empty value.
20-
*/
21-
@inline def instance[A](emp: A, inv: A => A, cmb: (A, A) => A): CommutativeGroup[A] =
22-
new CommutativeGroup[A] {
23-
val empty = emp
24-
def inverse(a: A) = inv(a)
25-
def combine(x: A, y: A) = cmb(x, y)
26-
}
2717
}

kernel/src/main/scala/cats/kernel/Group.scala

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,4 @@ object Group extends GroupFunctions[Group] {
7474
* Access an implicit `Group[A]`.
7575
*/
7676
@inline final def apply[A](implicit ev: Group[A]): Group[A] = ev
77-
78-
/**
79-
* Create a `Group` instance from the given inverse and combine functions and empty value.
80-
*/
81-
@inline def instance[A](emp: A, inv: A => A, cmb: (A, A) => A): Group[A] =
82-
new Group[A] {
83-
val empty = emp
84-
def inverse(a: A) = inv(a)
85-
def combine(x: A, y: A) = cmb(x, y)
86-
}
8777
}

kernel/src/main/scala/cats/kernel/Hash.scala

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,6 @@ object Hash extends HashFunctions[Hash] {
5353
def hash(x: A) = x.hashCode()
5454
def eqv(x: A, y: A) = x == y
5555
}
56-
57-
/**
58-
* Create a `Hash` instance from the given hash and equality functions.
59-
*/
60-
@inline def instance[A](h: A => Int, e: (A, A) => Boolean): Hash[A] =
61-
new Hash[A] {
62-
def hash(x: A) = h(x)
63-
def eqv(x: A, y: A) = e(x, y)
64-
}
6556
}
6657

6758
trait HashToHashingConversion {

project/KernelBoiler.scala

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,11 @@ object KernelBoiler {
267267
block"""
268268
| implicit def catsKernelCommutativeGroupForTuple$arity[${`A..N`}](
269269
| implicit ${constraints("CommutativeGroup")}
270-
| ): CommutativeGroup[${`(A..N)`}] = CommutativeGroup.instance(
271-
| ${nullaryTuple("empty")},
272-
| x => ${unaryTuple("inverse")},
273-
| (x, y) => ${binTuple("combine")}
274-
| )"""
270+
| ): CommutativeGroup[${`(A..N)`}] = new CommutativeGroup[${`(A..N)`}] {
271+
| def empty = ${nullaryTuple("empty")}
272+
| def inverse(x: ${`(A..N)`}) = ${unaryTuple("inverse")}
273+
| def combine(x: ${`(A..N)`}, y: ${`(A..N)`}) = ${binTuple("combine")}
274+
| }"""
275275
}
276276
),
277277
InstanceDef(
@@ -326,11 +326,11 @@ object KernelBoiler {
326326
block"""
327327
| implicit def catsKernelGroupForTuple$arity[${`A..N`}](
328328
| implicit ${constraints("Group")}
329-
| ): Group[${`(A..N)`}] = Group.instance(
330-
| ${nullaryTuple("empty")},
331-
| x => ${unaryTuple("inverse")},
332-
| (x, y) => ${binTuple("combine")}
333-
| )"""
329+
| ): Group[${`(A..N)`}] = new Group[${`(A..N)`}] {
330+
| def empty = ${nullaryTuple("empty")}
331+
| def inverse(x: ${`(A..N)`}) = ${unaryTuple("inverse")}
332+
| def combine(x: ${`(A..N)`}, y: ${`(A..N)`}) = ${binTuple("combine")}
333+
| }"""
334334
}
335335
),
336336
InstanceDef(
@@ -342,10 +342,12 @@ object KernelBoiler {
342342
block"""
343343
| implicit def catsKernelHashForTuple$arity[${`A..N`}](
344344
| implicit ${constraints("Hash")}
345-
| ): Hash[${`(A..N)`}] = Hash.instance(
346-
| x => ${unaryMethod("hash").mkString(s"$tupleNHeader(", ", ", ")")}.hashCode(),
347-
| (x, y) => ${binMethod("eqv").mkString(" && ")}
348-
| )"""
345+
| ): Hash[${`(A..N)`}] = new Hash[${`(A..N)`}] {
346+
| def hash(x: ${`(A..N)`}) =
347+
| ${unaryMethod("hash").mkString(s"$tupleNHeader(", ", ", ")")}.hashCode()
348+
| def eqv(x: ${`(A..N)`}, y: ${`(A..N)`}) =
349+
| ${binMethod("eqv").mkString(" && ")}
350+
| }"""
349351
}
350352
),
351353
InstanceDef(

0 commit comments

Comments
 (0)