Skip to content

Commit

Permalink
Add toElement helper in ErasedProductInstances1
Browse files Browse the repository at this point in the history
  • Loading branch information
joroKr21 committed Sep 15, 2022
1 parent e04a7cd commit 96568d2
Showing 1 changed file with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private[shapeless3] final class ErasedProductInstances1[K, FT](val mirror: Mirro
lazy val i = i0()

inline def toProduct(x: Any): Product = x.asInstanceOf[Product]
private def toElement(x: Any) = toProduct(x).productElement(0)
private def fromElement(x: Any) = mirror.fromProduct(Tuple1(x))

final def erasedMapK(f: Any => Any): ErasedProductInstances[K, ?] =
Expand All @@ -78,45 +79,45 @@ private[shapeless3] final class ErasedProductInstances1[K, FT](val mirror: Mirro
}
}

final def erasedMap(x0: Any)(f: (Any, Any) => Any): Any =
fromElement(f(i, toProduct(x0).productElement(0)))
final def erasedMap(x: Any)(f: (Any, Any) => Any): Any =
fromElement(f(i, toElement(x)))

final def erasedTraverse[F[_]](x: Any)(map: Map[F])(pure: Pure[F])(ap: Ap[F])(f: (Any, Any) => F[Any]): F[Any] =
map(f(i, toProduct(x).productElement(0)), fromElement)
map(f(i, toElement(x)), fromElement)

final def erasedMap2(x0: Any, y0: Any)(f: (Any, Any, Any) => Any): Any =
fromElement(f(i, toProduct(x0).productElement(0), toProduct(y0).productElement(0)))
final def erasedMap2(x: Any, y: Any)(f: (Any, Any, Any) => Any): Any =
fromElement(f(i, toElement(x), toElement(y)))

final def erasedFoldLeft(x0: Any)(a: Any)(f: (Any, Any, Any) => CompleteOr[Any]): Any = {
f(a, i, toProduct(x0).productElement(0)) match {
final def erasedFoldLeft(x: Any)(a: Any)(f: (Any, Any, Any) => CompleteOr[Any]): Any = {
f(a, i, toElement(x)) match {
case Complete(r) => r
case acc => acc
}
}

final def erasedFoldLeft2(x0: Any, y0: Any)(a: Any)(f: (Any, Any, Any, Any) => CompleteOr[Any]): Any = {
f(a, i, toProduct(x0).productElement(0), toProduct(y0).productElement(0)) match {
final def erasedFoldLeft2(x: Any, y: Any)(a: Any)(f: (Any, Any, Any, Any) => CompleteOr[Any]): Any = {
f(a, i, toElement(x), toElement(y)) match {
case Complete(r) => r
case acc => acc
}
}

final def erasedFoldRight(x0: Any)(a: Any)(f: (Any, Any, Any) => CompleteOr[Any]): Any = {
f(i, toProduct(x0).productElement(0), a) match {
final def erasedFoldRight(x: Any)(a: Any)(f: (Any, Any, Any) => CompleteOr[Any]): Any = {
f(i, toElement(x), a) match {
case Complete(r) => r
case acc => acc
}
}

final def erasedFoldRight2(x0: Any, y0: Any)(a: Any)(f: (Any, Any, Any, Any) => CompleteOr[Any]): Any = {
f(i, toProduct(x0).productElement(0), toProduct(y0).productElement(0), a) match {
final def erasedFoldRight2(x: Any, y: Any)(a: Any)(f: (Any, Any, Any, Any) => CompleteOr[Any]): Any = {
f(i, toElement(x), toElement(y), a) match {
case Complete(r) => r
case acc => acc
}
}

final def erasedProject(x0: Any)(p: Int)(f: (Any, Any) => Any): Any =
f(i, toProduct(x0).productElement(0))
final def erasedProject(x: Any)(p: Int)(f: (Any, Any) => Any): Any =
f(i, toElement(x))
}

object ErasedProductInstances1 {
Expand All @@ -139,7 +140,7 @@ private[shapeless3] final class ErasedProductInstancesN[K, FT](val mirror: Mirro

private def traverseProduct[F[_]](x: Product, f: (Any, Any) => F[Any])(pure: Pure[F], map: Map[F], ap: Ap[F]): F[Any] =
val n = is.length
if n == 0 then pure(x)
if n == 0 then pure(fromEmptyProduct)
else
var acc = pure(Vector.empty[Any])
var i = 0
Expand Down

0 comments on commit 96568d2

Please sign in to comment.