Skip to content

Commit

Permalink
Added a test case
Browse files Browse the repository at this point in the history
Signed-off-by: Darren Bishop <[email protected]>
  • Loading branch information
DarrenBishop committed Mar 27, 2024
1 parent bdc28e2 commit 8ef085e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions core/src/test/scala/simulacrum/typeclass.scala
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,30 @@ class TypeClassTest extends AnyWordSpec with Matchers {
1 ~ 2 shouldBe 3
}

"supports varargs in adapted methods" in {

@typeclass trait Vargs[T] {
@op("/:", true) def fold[T2](x: T, y: T2*)(f: (T, T2) => T): T
}

case class Sum(total: Int = 0) {
def add(operand: Int): Sum = Sum(total + operand)
}

implicit val sumVargs: Vargs[Sum] = new Vargs[Sum] {
def fold[T2](x: Sum, ys: T2*)(f: (Sum, T2) => Sum): Sum =
ys.foldLeft(x) { (ds, t2) => info("folding " + t2); f(ds, t2) }
}

import Vargs.ops._

val sum = Sum()
val ops = List(1, 2, 3, 4)

sum.fold(ops: _*) { _ add _ } shouldBe Sum(10)
sum./: ((ops ::: ops): _*) { _ add _ } shouldBe Sum(20)
}

"supports suppression of adapter methods" in {
@typeclass trait Sg[A] {
@noop def append(x: A, y: A): A
Expand Down

0 comments on commit 8ef085e

Please sign in to comment.