Skip to content

Instantly share code, notes, and snippets.

@benhutchison
Created June 24, 2025 22:43
Show Gist options
  • Save benhutchison/ec9ee2633af32b9938be5577799f8ef0 to your computer and use it in GitHub Desktop.
Save benhutchison/ec9ee2633af32b9938be5577799f8ef0 to your computer and use it in GitHub Desktop.
Direct syntax doesn't work with Cats mapN operator but does work with equivalent pattern match
//> using scala 3.7.0
//> using dep org.typelevel::cats-effect:3.6.1
//> using dep io.github.dotty-cps-async::dotty-cps-async:1.1.2
//> using dep io.github.dotty-cps-async::cps-async-connect-cats-effect:1.1.0
import cats.*
import cats.implicits.*
import cats.effect.*
import cats.effect.implicits.*
import cps.*
import cps.monads.catsEffect.given
object MapNProblemExample:
//Error.. "Required:cps.AsyncShift[cats.syntax.Tuple2SemigroupalOps[Option, Int, Int]]) .."
// def notWork = async[IO]:
// (Option(1), Option(1)).mapN((a, b) => IO(a + b).await).getOrElse(42)
def work = async[IO]:
(Option(1), Option(1)).match
case (Some(a), Some(b)) => IO(a + b).await
case _ => 42
@benhutchison
Copy link
Author

full error:

[error] ./MapNIssue.scala:16:5
[error] Can't find AsyncShift (Found:    cps.runtime.CpsMonadSelfAsyncShift[cats.effect.IO, cps.CpsMonad[cats.effect.IO]]
[error] Required: cps.AsyncShift[cats.syntax.Tuple2SemigroupalOps[Option, Int, Int]]) or async functions) for qual=Apply(TypeApply(Ident(catsSyntaxTuple2Semigroupal),List(TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Option)], TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Int)], TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Int)])),List(Apply(TypeApply(Select(Ident(Tuple2),apply),List(TypeTree[AppliedType(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Option),List(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Int)))], TypeTree[AppliedType(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Option),List(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Int)))])),List(Apply(TypeApply(Select(Ident(Option),apply),List(TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Int)])),List(Literal(Constant(1)))), Apply(TypeApply(Select(Ident(Option),apply),List(TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Int)])),List(Literal(Constant(1)))))))) name = mapN, shiftedName=mapN_async, askedShiftedType=cps.AsyncShift[cats.syntax.Tuple2SemigroupalOps[scala.Option, scala.Int, scala.Int]]
[error]     (Option(1), Option(1)).mapN((a, b) => IO(a + b).await).getOrElse(42)
[error]     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error compiling project (Scala 3.7.0, JVM (17))
Compilation failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment