Part of the Scala Cats ecosystem for an IO type and associated effects.
Questions tagged [cats-effect]
191 questions
6
votes
4 answers
Doobie - lifting arbitrary effect into ConnectionIO
I'm trying to send an email in the same transaction as inserting user into a database with Doobie.
I know that I can lift IO into ConnectionIO by using Async[ConnectionIO].liftIO(catsIO) where catsIO: IO[String]
But in my code I don't operate on IO,…

Leonti
- 10,400
- 11
- 43
- 68
6
votes
1 answer
Is there any way to lift content from IO to other container without run?
According to the cats official document: https://typelevel.org/cats-effect/typeclasses/liftio.html, if we want lift something from IO to other container, you should implement LiftIO trait, but the example explicitly run unsafeRunXXX method to fetch…

user3593261
- 560
- 4
- 17
6
votes
1 answer
value flatMap is not a member of type parameter F[Long] when using cats.effect
This perhaps been asked many times before, but none of the suggestions I've found help.
I have a simple Scala code that generates long number that depends on some side-effects. I'm wrapping thing in an IO monad, but according to the least power…

edio
- 652
- 1
- 8
- 21
6
votes
1 answer
Cannot find an implicit value for ContextShift[cats.effect.IO] in http4s version 19.0.0
I have a http4s project which uses ciris for configuration management.
The project is in github here.
libraryDependencies ++= Seq(
"is.cir" %% "ciris-cats",
"is.cir" %% "ciris-cats-effect",
"is.cir" %% "ciris-core",
"is.cir" %%…

user51
- 8,843
- 21
- 79
- 158
5
votes
4 answers
How to return upon encountering first "true" in a List[IO[Boolean]] in Scala Cats Effect
Say I have a set of rules that have a validation function that returns IO[Boolean] at runtime.
case class Rule1() {
def validate(): IO[Boolean] = IO.pure(false)
}
case class Rule2() {
def validate(): IO[Boolean] = IO.pure(false)
}
case class…

iamsmkr
- 800
- 2
- 10
- 29
5
votes
1 answer
How do I verbalize the term F[_] in scala/cats-effect
I'm learning the concept of F[_] as a constructor for other types, but how do you pronounce this to another human or say it in your head (for us internal monologue thinkers).
Similar to how x => x + 1 has an official verbalization of "x goes to x…

WhiteleyJ
- 1,393
- 1
- 22
- 29
5
votes
1 answer
Cats Effect: which thread pool to use for Non-Blocking IO?
From this tutorial https://github.com/slouc/concurrency-in-scala-with-ce#threading
async operations are divided into 3 groups and require significantly different thread pools to run on:
Non-blocking asynchronous operations:
Bounded pool with a very…

Teimuraz
- 8,795
- 5
- 35
- 62
5
votes
3 answers
Splitting the fs2 stream output to two files
I'm just starting my adventure with fs2 streams. What I want to achieve, is to read a file (a large one, this is why I use fs2), transform it and write the result to two different files (based on some predicate). Some code (from…

Dawid Łakomy
- 118
- 9
5
votes
1 answer
High level of what I will need to do to port ReactiveMongo scala to use cats effects?
Is it correct to say that if I wanted to use ReactiveMongo in something like http4s I will have to wrap all the Future calls that ReactiveMongo returns in a Cats IO effect?
At a high level, what are the steps I would need to incorporate…

Blankman
- 259,732
- 324
- 769
- 1,199
5
votes
1 answer
parSequence and parTraverse in tagless final
Using tagless final (without using IO, but rather a generic F) how can I abstract over something like this:
def doSomething(s: String): IO[Unit] = ???
List("authMethods", "secretEngines", "plugins", "CAs", "common").parTraverse(doSomething)
The…

Simão Martins
- 1,210
- 11
- 22
5
votes
1 answer
Scala: Cannot find an implicit value for ContextShift[cats.effect.IO]
I just started with scala and want to build a connection to my DB.
(My knowledge stems from the scala/doobie Tutorial's on https://www.scala-exercises.org/)
Now here is the Code:
import doobie._
import doobie.implicits._
import cats.effect._
import…

Ego_Akkarin
- 63
- 7
5
votes
1 answer
Elegant way to change either to error with tagless final
I often do things like:
import cats.effect.Sync
import cats.implicits._
case class User(name: String)
case object Error extends Exception
def validate[F[_]: Sync](name: String): F[Either[Error, User]] = Sync[F].pure(User(name).asRight)
def…

Stu Redman
- 262
- 2
- 9
5
votes
2 answers
How to write for comprehension in cats with IO monad
I have the following code:
import cats.effect.IO
import cats.data.State
import cats.data.StateT
import cats.implicits._
import cats.effect.LiftIO
abstract class Example {
object implicits {
implicit def myEffectLiftIO:…

Mike
- 812
- 9
- 25
5
votes
1 answer
Scala: http4s giving 401 Unauthorized for same request that works in curl/requests
I tried the following code using http4s v0.19.0:
import cats.effect._
def usingHttp4s(uri: String, bearerToken: String)(implicit cs: ContextShift[IO]): String = {
import scala.concurrent.ExecutionContext
import org.http4s.client.dsl.io._
…

pathikrit
- 32,469
- 37
- 142
- 221
4
votes
1 answer
How does the cats-effect IO monad really work?
I'm new to functional programming and Scala, and I was checking out the Cats Effect framework and trying to understand what the IO monad does. So far what I've understood is that writing code in the IO block is just a description of what needs to be…

ssmallya
- 133
- 3
- 11