Skip to content

Commit

Permalink
add @tailrec
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k authored Apr 28, 2024
1 parent 6a3e292 commit bd95b11
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/scala/scalaprops/ScalapropsMagnoliaCogen.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scalaprops

import magnolia1.{CaseClass, Magnolia, SealedTrait}
import scala.annotation.tailrec

object ScalapropsMagnoliaCogen {
type Typeclass[T] = scalaprops.Cogen[T]
Expand All @@ -19,6 +20,7 @@ object ScalapropsMagnoliaCogen {
def cogen[B](t: T, g: CogenState[B]) = {
val index = ctx.subtypes.indexWhere(_.cast.isDefinedAt(t))
if (index >= 0) {
@tailrec
def loop(i: Int, r: Rand): Rand = {
if (i <= 0) r
else loop(i - 1, g.gen.f(index, r)._1)
Expand Down

0 comments on commit bd95b11

Please sign in to comment.