-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removed Ops and replaced them with forwarders. #2766
Changes from 2 commits
355979e
60c2fe6
2d4cc2c
4a98735
f0e8cf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,11 @@ package arrow | |
|
||
import scala.reflect.macros.blackbox.Context | ||
|
||
<<<<<<< HEAD | ||
======= | ||
import cats.data.{EitherK, Tuple2K} | ||
|
||
>>>>>>> 60c2fe6336f1e4dff1cd7d7eb839c19f83778b63 | ||
/** | ||
* `FunctionK[F[_], G[_]]` is a functor transformation from `F` to `G` | ||
* in the same manner that function `A => B` is a morphism from values | ||
|
@@ -89,74 +92,14 @@ object FunctionK { | |
* | ||
* Additionally, the type parameters on `f` must not be specified. | ||
*/ | ||
def lift[F[_], G[_]](f: (F[α] ⇒ G[α]) forSome { type α }): FunctionK[F, G] = | ||
macro FunctionKMacros.lift[F, G] | ||
def lift[F[_]]: LiftPartiallyApplied[F] = new LiftPartiallyApplied | ||
|
||
} | ||
|
||
private[arrow] object FunctionKMacros { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't simply remove this code. we need to create two versions of it, one for scala 2.x with the current implementation and another with the new scala3 implementation. Like in this example |
||
|
||
def lift[F[_], G[_]](c: Context)( | ||
f: c.Expr[(F[α] ⇒ G[α]) forSome { type α }] | ||
)( | ||
implicit evF: c.WeakTypeTag[F[_]], | ||
evG: c.WeakTypeTag[G[_]] | ||
): c.Expr[FunctionK[F, G]] = | ||
c.Expr[FunctionK[F, G]](new Lifter[c.type](c).lift[F, G](f.tree)) | ||
// ^^note: extra space after c.type to appease scalastyle | ||
|
||
private[this] class Lifter[C <: Context](val c: C) { | ||
import c.universe._ | ||
|
||
def lift[F[_], G[_]](tree: Tree)( | ||
implicit evF: c.WeakTypeTag[F[_]], | ||
evG: c.WeakTypeTag[G[_]] | ||
): Tree = unblock(tree) match { | ||
case q"($param) => $trans[..$typeArgs](${arg: Ident})" if param.name == arg.name ⇒ | ||
typeArgs | ||
.collect { case tt: TypeTree => tt } | ||
.find(tt => Option(tt.original).isDefined) | ||
.foreach { param => | ||
c.abort(param.pos, s"type parameter $param must not be supplied when lifting function $trans to FunctionK") | ||
} | ||
|
||
val F = punchHole(evF.tpe) | ||
val G = punchHole(evG.tpe) | ||
private[arrow] final class LiftPartiallyApplied[F[_]](val dummy: Boolean = true) extends AnyVal { | ||
type T | ||
|
||
q""" | ||
new _root_.cats.arrow.FunctionK[$F, $G] { | ||
def apply[A](fa: $F[A]): $G[A] = $trans(fa) | ||
} | ||
""" | ||
case other ⇒ | ||
c.abort(other.pos, s"Unexpected tree $other when lifting to FunctionK") | ||
def apply[G[_]](f: F[T] => G[T]): FunctionK[F, G] = new FunctionK[F, G] { | ||
def apply[A](fa: F[A]): G[A] = f(fa.asInstanceOf[F[T]]).asInstanceOf[G[A]] | ||
} | ||
|
||
private[this] def unblock(tree: Tree): Tree = tree match { | ||
case Block(Nil, expr) ⇒ expr | ||
case _ ⇒ tree | ||
} | ||
|
||
private[this] def punchHole(tpe: Type): Tree = tpe match { | ||
case PolyType(undet :: Nil, underlying: TypeRef) ⇒ | ||
val α = TypeName("α") | ||
def rebind(typeRef: TypeRef): Tree = | ||
if (typeRef.sym == undet) tq"$α" | ||
else { | ||
val args = typeRef.args.map { | ||
case ref: TypeRef => rebind(ref) | ||
case arg => tq"$arg" | ||
} | ||
tq"${typeRef.sym}[..$args]" | ||
} | ||
val rebound = rebind(underlying) | ||
tq"""({type λ[$α] = $rebound})#λ""" | ||
case TypeRef(pre, sym, Nil) ⇒ | ||
tq"$sym" | ||
case _ => | ||
c.abort(c.enclosingPosition, s"Unexpected type $tpe when lifting to FunctionK") | ||
} | ||
|
||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merge error?