Questions tagged [scala-cats]

Cats is a library that provides abstractions for functional programming in Scala.

Cats is a library that provides abstractions for functional programming in Scala.

The name is a playful shortening of the word category.

Official Website

Official Repository

929 questions
13
votes
1 answer

How to reason about stack safety in Scala Cats / fs2?

Here is a piece of code from the documentation for fs2. The function go is recursive. The question is how do we know if it is stack safe and how to reason if any function is stack safe? import fs2._ // import fs2._ def tk[F[_],O](n: Long):…
Lev Denisov
  • 2,011
  • 16
  • 26
13
votes
1 answer

Cats effect - parallel composition of independent effects

I want to combine multiple IO values that should run independently in parallel. val io1: IO[Int] = ??? val io2: IO[Int] = ??? As I see it, I have to options: Use cats-effect's fibers with a fork-join pattern val parallelSum1: IO[Int] = for { …
amitayh
  • 770
  • 1
  • 8
  • 19
13
votes
1 answer

Running queries in parallel in Doobie

Is it possible to run multiple queries in parallel, using Doobie? I have the following (pseudo)queries: def prepareForQuery(input: String): ConnectionIO[Unit] = ??? val gettAllResults: ConnectionIO[List[(String, BigDecimal)]] = ??? def…
mdm
  • 3,928
  • 3
  • 27
  • 43
13
votes
1 answer

How will Dotty change pure functional programming in Scala?

In this question from 2013, Mr. Odersky notes that "it's too early to tell" whether libraries like Scalaz will be able to exist (at least in their current state) under Dotty, due to the castration of higher-kinded and existential types. In the time…
kantianethics
  • 671
  • 5
  • 21
12
votes
1 answer

Doobie cannot find or construct a Read instance for type T

I'm using doobie to query some data and everything works fine, like this: case class Usuario(var documento: String, var nombre: String, var contrasena: String) def getUsuario(doc: String) = sql"""SELECT documento, nombre, contrasena FROM…
santiromf
  • 123
  • 1
  • 6
12
votes
1 answer

scala cats ambiguous implicit values

import cats._ import cats.implicits._ trait Console[F[_]]{ def readInput() : F[Int] def print(msg: String) : F[Unit] } class Foo { def doFoo[F[_]: Monad](number: Int)(implicit C: Console[F]) : F[Unit] = { C.readInput().flatMap{input =>…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
12
votes
1 answer

How to use Scala Cats Validated the correct way?

Following is my use case I am using Cats for validation of my config. My config file is in json. I deserialize my config file to my case class Config using lift-json and then validate it using Cats. I am using this as a guide. My motive for using…
advocateofnone
  • 2,527
  • 3
  • 17
  • 39
12
votes
2 answers

cats-effect:How to transform Map[x,IO[y]] to IO[Map[x,y]]

I have a map of string to IO like this Map[String, IO[String]], I want to transform it into IO[Map[String, String]]. How to do it?
Kumar Waghmode
  • 509
  • 2
  • 18
12
votes
1 answer

How can I use cartesian product |@| with latest versions of Cats?

I've migrated some code using cats 0.2 to cats 0.6, and my code is not wroking anymore : import cats.data.Validated import cats.std.all._ val valid1: Validated[List[String], Int] = valid(1) val valid2: Validated[List[String], Int] =…
Loic
  • 3,310
  • 4
  • 25
  • 43
11
votes
1 answer

Name of Bi - Functor type class with one contravariant and one covariant parameter

I'm looking to see if there is a standard typeclass for a Bi-Functor that has one Contravariant parameter and one Covariant parameter. punching the signature (c -> a) -> (b -> d) -> f a b -> f c d results in nothing that matches. Basically in Scala…
Nigel Benns
  • 1,236
  • 11
  • 14
11
votes
1 answer

Execute a `List` of `IO` in parallel

This is an example when we want to execute 3 IO in parallel def test: Unit = { val ioA = IO.shift *> IO(println("Running ioA")) // ioA: cats.effect.IO[Unit] = val ioB = IO.shift *> IO(println("Running ioB")) // ioB:…
nam
  • 3,542
  • 9
  • 46
  • 68
11
votes
3 answers

Scala cats, traverse Seq

I know I can traverse Lists import cats.instances.list._ import cats.syntax.traverse._ def doMagic(item: A): M[B] = ??? val list: List[A] = ??? val result: M[List[B]] = list.traverse(doMagic) And I can convert a Seq back and forth to List val seq:…
Victor Basso
  • 5,556
  • 5
  • 42
  • 60
11
votes
1 answer

Cats - how to use for-comprehension when `Monad` instance in scope?

How can I use for-comprehension on type M in the method below? def foo[M[_]: Monad](m1: M[Int], m2: M[Int]) = for { a <- m1 b <- m2 } yield (a + b) I'll get a value flatMap is not a member of type parameter M[Int] I can make it work…
Samuel
  • 16,923
  • 6
  • 62
  • 75
11
votes
1 answer

Why must fmap map every element of a List?

Having read the book Learn you a Haskell For Great Good, and the very helpful wiki book article Haskell Category Theory which helped me overcome the common category mistake of confusing category objects with the programming objects, I still have the…
Henry Story
  • 2,116
  • 1
  • 17
  • 28
10
votes
1 answer

What is lost after converting Monix `Task` to Cats `IO`?

This simplified case is where my question happen at... object Main extends IOApp{ def run(args:Seq[String]): IO[ExitCode]={ Task{...} .to[IO] .as(ExitCode.Success) } } Another option is Await.result(task), however which sounds not…
1
2
3
61 62