Comfy Cats Effect room. Ask questions. Rant about config file formats. Be nice!
WriterT
or StateT
.
parMapN
example missing ContextShift[IO]
. I thought it could be helpful to add one way to provide contextShift helpful noobs like me. So created a pull request https://github.com/typelevel/cats-effect/pull/372/files
Learning Question: I'm trying to run the cats.effect.Resource
example from https://typelevel.org/cats-effect/datatypes/resource.html#example. I get value map is not a member of cats.effect.Resource[cats.effect.IO,String]
. Wondering why is it looking for map
not flatMap
,
// example taken from https://typelevel.org/cats-effect/datatypes/resource.html#example
test("cats Resource") {
import cats.effect.{IO, Resource}
import cats.implicits._
def mkResource(data: String): Resource[IO, String] = {
val acquire = IO(println(s"Acquiring $data")) *> IO.pure(data)
def release(res: String) = IO(println(s"Releasing $res"))
Resource.make(acquire)(release)
}
val out: Resource[IO, String] = mkResource("outer")
val in: Resource[IO, String] = mkResource("inner")
// val rr = out.flatMap { a =>
// in.flatMap { b =>
// Resource.pure((a, b))
// }
// }
// out.map { o =>
// in.map { i =>
// (o, i)
// }
// }
val r = for {
outer <- out
inner <- in
} yield (outer, inner)
r.use { case (x, y) => IO(println(s"Using $x and $y")) }.unsafeRunSync
}
scalacOptions += "-Ypartial-unification"
Resource[IO, String]
(G[_, _]
) needs to fit into F[_]
so that you can fetch Monad[F]
to get flatMap
F[_]
be Resource[IO, ?]
Resource
so it can unify with F[_]
traverse
on Validated
or Either
(you need F[_]
for Applicative
, but they have two type parameters) and so on
*>
on Fiber[F, A]
(I hope you can see the pattern)
*>
on IO
or Option
won't expose the bug, since those types already have an F[_]
shape
partial-unification
at least https://typelevel.org/cats, might be useful to mention in cats-effect as well