Part of the Scala Cats ecosystem for an IO type and associated effects.
Questions tagged [cats-effect]
191 questions
4
votes
1 answer
Confused about cats-effect Async.memoize
I'm fairly new to cats-effect, but I think I am getting a handle on it. But I have come to a situation where I want to memoize the result of an IO, and it's not doing what I expect.
The function I want to memoize transforms String => String, but…

fluffysheap
- 769
- 5
- 14
4
votes
1 answer
Understanding cats.effect.Concurrent with respect to Cancellation
Given:
build.sbt
scalaVersion := "2.13.2"
libraryDependencies += "org.typelevel" %% "cats-effect" % "2.1.3"
src/main/scala/net/Main.scala
package net
import cats.effect._
import cats.implicits._
import java.util.concurrent.TimeUnit
import…

Kevin Meredith
- 41,036
- 63
- 209
- 384
4
votes
1 answer
Where to use `ApplicativeError` instead of `Either`?
There is ApplicativeError[F,E] + F[A] and there is Either[E, A]. Both convey the message that the function could fail with an E or succeed with an A but I'm not sure about the different message they convey to the client about the intended way of…

Ashkan Kh. Nazary
- 21,844
- 13
- 44
- 68
4
votes
2 answers
What is the intent behind `F[Something[F]]`?
I see a lot of F[Request[F]], F[Monitor[F]] and F[Something[F]] around. Although I understand the mechanics of how to handle this, I don't have an intuitive understanding of why some effect (F) should appear like this (both wrapping around Something…

Ashkan Kh. Nazary
- 21,844
- 13
- 44
- 68
4
votes
1 answer
How do you flatten a for-comprehension with traverse in scala cats effect?
I have some code structurally identical to this and I'm not sure the best way to clean it up? The trivial IOs and additions are there so that the example compiles without needing additional methods.
I'd really like to not have it be so nested, is…

epigram-engineer
- 81
- 7
4
votes
2 answers
How to create cats IO monad from cats State
I am working with cats and I want to transform my val x: State[A, B] to StateT[IO, A, B]. Note: IO is from cats-effects.
How to do this elegantly?

Mike
- 812
- 9
- 25
4
votes
2 answers
Using race from cats-effect prevents app from exiting
I've got simple cats-effect app, which download site from the URL given as argument. During downloading app is supposed to display "loading bar" by writting dots (.) to console. I implemented it by doing race of two IOs one for downloading another…

Stu Redman
- 262
- 2
- 9
4
votes
1 answer
"Spawn" concurrent effect in a WebSocket endpoint
I have the following code:
class ApiRoutes2[F[_]](implicit F: ConcurrentEffect[F]) extends Http4sDsl[F] {
var queue = Queue.bounded[F, String](100)
def createService(queue: Queue[F, String]): F[Unit] = ???
val service: HttpRoutes[F] =…

Simão Martins
- 1,210
- 11
- 22
4
votes
1 answer
Cats Effect IO: Compose IO with Scala collections
This is a toy Scala program, that reads 10 numbers from the console and adds 1 to each prints them out:
import cats._
import cats.effect._
import cats.implicits._
object Main extends IOApp {
def printLine[A](x: A)(implicit show: Show[A]):…

pathikrit
- 32,469
- 37
- 142
- 221
4
votes
1 answer
Twitter Future & Cats Arrow
I'm trying to combine Twitter Future with Cats Kleisli and Arrow and I have a compilation error that I don't know how to solve it.
The code is the following:
package com.example
import scala.language.higherKinds
import cats.arrow.Arrow
import…

Octavian R.
- 1,231
- 8
- 12
3
votes
1 answer
Cats Effect 3 - Access to Blocking context
I am migrating from Cats Effect 2 to 3 and since Blocker is not available anymore I wonder how is it possible to run F in the blocking execution context?
Previously, the following code was used
val blocker: Blocker =…

Mike
- 347
- 1
- 2
- 15
3
votes
1 answer
How to make cats.effect.Console with timeout?
I want to take input from console in 3 seconds, otherwise in timeout case return "Timeout!". I wrote this function:
def withTimeout: IO[String] =
Console[IO].readLine.timeoutTo(3.seconds, IO.pure("Timeout!"))
But it doesn't stop after 3 seconds,…

Max Smirnov
- 477
- 3
- 10
3
votes
1 answer
Complex monad transformer for IO monad
I am trying to write a Cats MTL version of a function that would save an entity to a database. I want this function to read some SaveOperation[F[_]] from environment, execute it and handle possible failure. So far I came up with 2 version of this…

Leonid Bor
- 2,064
- 6
- 27
- 47
3
votes
1 answer
Fiber on the JVM with Scala IO implementations
My understanding is that IO Implementation like cats-effetcs or Zio use fibers, and this on the JVM.
I wonder what's the underlying lib or framework they are using, if the JVM e.g. 11 does not officially support fibers yet ?

MaatDeamon
- 9,532
- 9
- 60
- 127
3
votes
1 answer
Conversion between Option[F[ShoppingCart]] to F[Option[ShoppingCart]]
I have the following algebra in Scala (I am using the Tagless Final Pattern):
trait ShoppingCarts[F[_]] {
def create(id: String): F[Unit]
def find(id: String): F[Option[ShoppingCart]]
def add(sc: ShoppingCart, product: Product):…

riccardo.cardin
- 7,971
- 5
- 57
- 106