-
-
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
reduceLeftM doesn't short-circuit #3201
Comments
FYI (to those following the issue out of curiosity like me), I had to supply type parameters for @ import $ivy.`org.typelevel::cats-core:2.1.0`
@ import cats.data.NonEmptyStream, cats.implicits._
import cats.data.NonEmptyStream, cats.implicits._
@ def f(i: Int): Either[Int, Int] = if (i < 100000) Right(i) else Left(i)
defined function f
@ val s = NonEmptyStream(0, Stream.from(1))
...
@ s.foldLeftM(0)((b, a) => f(a).map(_ + b))
cmd4.sc:1: no type parameters for method foldLeftM: (f: (Int, Int) => G[Int])(implicit G: cats.Monad[G])G[Int] exist so that it can be applied to arguments ((Int, Int) => scala.util.Either[Int,Int])
--- because ---
argument expression's type is not compatible with formal parameter type;
found : (Int, Int) => scala.util.Either[Int,Int]
required: (Int, Int) => ?G[Int]
val res4 = s.foldLeftM(0)((b, a) => f(a).map(_ + b))
^
cmd4.sc:1: type mismatch;
found : (Int, Int) => scala.util.Either[Int,Int]
required: (Int, Int) => G[Int]
val res4 = s.foldLeftM(0)((b, a) => f(a).map(_ + b))
^
cmd4.sc:1: Could not find an instance of Monad for G
val res4 = s.foldLeftM(0)((b, a) => f(a).map(_ + b))
^
Compilation Failed
@ type EitherInt[A] = Either[Int, A]
defined type EitherInt
@ s.foldLeftM[EitherInt, Int](0)((b, a) => f(a).map(_ + b))
res5: EitherInt[Int] = Left(100000)
@ s.reduceLeftM[EitherInt, Int](f)((b, a) => f(a).map(_ + b))
^C
Interrupted! (`repl.lastException.printStackTrace` for details) |
@kevinmeredith You definitely can provide the type parameters to resolve that issue, but you're far better off enabling |
It seems like it should be possible for
reduceLeftM
to short-circuit, since e.g.foldLeftM
does:This is probably related to #3200, which isn't itself a bug, but if we had a working
reduceLeftM
we could writereduceMapM
in terms of it.The text was updated successfully, but these errors were encountered: