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
70
votes
2 answers

How does the Cats library in Scala relate to scalaz?

How does the Cats library relate to scalaz? The Cats project mentions it is descended from scalaz.
user2726995
  • 2,064
  • 2
  • 21
  • 26
53
votes
8 answers

How to reduce Seq[Either[A,B]] to Either[A,Seq[B]]?

Given a sequence of eithers Seq[Either[String,A]] with Left being an error message. I want to obtain an Either[String,Seq[A]] where I get a Right (which will be a Seq[A]), if all elements of the sequence are Right. If there is at least one Left (an…
ziggystar
  • 28,410
  • 9
  • 72
  • 124
27
votes
1 answer

Making sense of Scala FP Libraries

Just for the sake of quick clarity for someone who wants to start working with Scala FP library, on a journey to become better at pure FP. Would someone clarify the difference/relation between Cats and Cats-Effect, Cats-Effects IO? On top of that,…
MaatDeamon
  • 9,532
  • 9
  • 60
  • 127
26
votes
1 answer

Cats-effect and asynchronous IO specifics

For few days I have been wrapping my head around cats-effect and IO. And I feel I have some misconceptions about this effect or simply I missed its point. First of all - if IO can replace Scala's Future, how can we create an async IO task? Using…
ukulele
  • 317
  • 4
  • 9
26
votes
1 answer

How to stack applicative functors in Scala

Applicative functors are often mentioned as an alternative to monads when your computation steps are independent. One of their often-mentioned advantages is that you don't need transformers when you want to stack applicatives, because F[G[X]] is…
kciesielski
  • 1,178
  • 9
  • 18
25
votes
4 answers

missing Cats Functor[Future] instance

I am trying to use OptionT to combine methods returning Future[Option[T]] in a for-comprehension. import cats.data._ import cats.implicits._ import cats.instances.future._ for { data <- OptionT(repo.getData(id)) ... } The compiler error I am…
kostja
  • 60,521
  • 48
  • 179
  • 224
21
votes
1 answer

How to flatten a sequence of cats' ValidatedNel values

I need to flatten a sequence of cats.data.ValidatedNel[E, T] values to a single ValidatedNel value: val results: Seq[cats.data.ValidatedNel[E, T]] = ??? val flattenedResult: cats.data.ValidatedNel[E, T] I can do it like this: import…
Tvaroh
  • 6,645
  • 4
  • 51
  • 55
20
votes
1 answer

Stacking monadic effects in a Free Monad in Scala

I'm learning about the Free monad in Scala, and I've put together a simple example of algebra that I can lift into a Free monad using cats. Here's my algebra sealed trait ConsultationOp[A] object consultation { case class Create(c: Consultation)…
Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
19
votes
1 answer

Difference between flatMap, flatTap, evalMap and evalTap

In Scala fs2 library for functional streams: I am trying to understand the difference between flatMap, flatTap, evalMap and evalTap. They all seem to perform the same thing, which is transformation of the stream values. What is the difference and…
Lev Denisov
  • 2,011
  • 16
  • 26
18
votes
2 answers

cats-effect: How to transform `List[IO]` to `IO[List]`

I created a list of IO[Unit] in order to retrieve data from a list of URL. But now how I convert it back to a single IO[Unit] ?
nam
  • 3,542
  • 9
  • 46
  • 68
18
votes
1 answer

Monads VS Applicative functors for Futures

Suppose I want to aggregate data from 2 remote services, and serve response as fast as I can: def loadUser: Future[User] def loadData: Future[Data] case class Payload(user: User, data: Data) I understand that this one executes async tasks…
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
17
votes
1 answer

Doobie and DB access composition within 1 transaction

Doobie book says that it's a good practice to return ConnectionIO from your repository layer. It gives an ability to chain calls and perform them in one transaction. Nice and clear. Now let's imagine we are working on REST API service and our…
Eugene Zhulkov
  • 505
  • 3
  • 13
15
votes
2 answers

Cats: Non tail recursive tailRecM method for Monads

In cats, when a Monad is created using Monad trait, an implementation for method tailRecM should be provided. I have a scenario below that I found impossible to provide a tail recursive implementation of tailRecM sealed trait Tree[+A] final…
tharindu_DG
  • 8,900
  • 6
  • 52
  • 64
15
votes
1 answer

False errors when using cats library in IntelliJ

I am using the cats Scala library and the IntelliJ IDE seems to be struggling with the use of implicits: Here is a simple example: import cats.std.all._ import cats.Traverse.ops._ def useSequence[A](ls : List[Option[A]]) : Option[List[A]] = { …
mushroom
  • 6,201
  • 5
  • 36
  • 63
14
votes
2 answers

Scala-Cats Validated: value mapN is not a member of ValidatedNel tuple

Scala community. Currently I'm trying to implement custom model/single parameter validation using cats Validated Monad. But, after removal of Cartesian product since 1.0 I'm unable to use (v1 |@| v2) map (f) and unable to compile my code: import…
dev
  • 145
  • 1
  • 7
1
2 3
61 62