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

How to use Scala Cats' Kleisli with Either

I'm trying to use Kleisli to compose functions returning a monad. It works for an Option: import cats.data.Kleisli import cats.implicits._ object KleisliOptionEx extends App { case class Failure(msg: String) sealed trait Context case class…
KaC
  • 613
  • 6
  • 14
4
votes
1 answer

Typelevel Cats.Effect vs Typlevel eff. which and why?

I want do do some programming that needs effects ( who doesn't :-). In particular something like scalaz Task to run some asynchronous data retrieval and ruturn a Future like effect that will handle the resuts on completion. I notice that typelevel…
Karl
  • 1,164
  • 9
  • 25
4
votes
1 answer

remove the filtered line from the file using scala fs2 file streaming

how to remove the filtered lines from the current streaming file using fs2 and get the count of filtered lines as the return type? ex: If the old.txt contains strings separated by a newline (\n): john sam chen yval .... and val myList =…
vkt
  • 1,401
  • 2
  • 20
  • 46
4
votes
2 answers

Bounds for type parameter of FunctionK

I'm using cats FreeMonad. Here's a simplified version of the algebra: sealed trait Op[A] object Op { final case class Get[T](name: String) extends Op[T] type OpF[A] = Free[Op, A] def get[T](name: String): OpF[T] = liftF[Op,…
racetrack
  • 3,766
  • 30
  • 30
4
votes
2 answers

Scala: Cats, OptionT[Future, T] and ApplicativeError

Some time ago I've started using Cats and found OptionT very useful to work with Future[Option[T]] in most cases. But I faced with one drawback, to use AplicativeError I need to define type alias type FutureOption[T] = OptionT[Future, X] to matching…
4
votes
3 answers

Collapse / Flatten cats Seq / List of cats.Validated

What I have is a List[Validated[NonEmptyList[ErrorType], T]] and I wish to flatten this into a Validated[NonEmptyList[ErrorType], T] My poor attempt is to collect all the errors and then make a new one. val errors = validations collect { case…
sksamuel
  • 16,154
  • 8
  • 60
  • 108
4
votes
1 answer

Encoding of three way inclusive-or type in Scala

I have some data that consists of three fields, let's say a String, an Int, and a Double. They are all optional, but the whole thing must contain at least one of those fields. I've tried cats.data.Ior, like type MyType = String Ior Int Ior Double.…
Haemin Yoo
  • 474
  • 5
  • 11
4
votes
1 answer

Processing multipart content in http4s

I would like to know how can I process multipart content using the http4s library. Imagine a service with the following snippet (the complete gist is here): case GET -> Root / "form" => Ok( """| | |
Labra
  • 1,412
  • 1
  • 13
  • 33
4
votes
2 answers

Calling generic function with Functor using subclass (cats/scalaz)

I've been messing around with some basic examples of Cats/Scalaz and also walking through tutorials to get a feel and I've hit a case which I'm sure there is a solution to. Is it possible to call a generalized function that takes a contextualized…
4
votes
1 answer

Cartesian builder for OptionT

I want to join 2 Future[Option[_]]: def foo: Future[Option[Int]] = ??? def baz: Future[Option[Int]] = ??? It is possible to join pair of Future: foo |@| baz map( (fooOpt, bazOpt) => ???) And possible to join pair of Option: Option(1) |@| Option(2)…
EnverOsmanov
  • 625
  • 1
  • 7
  • 17
4
votes
1 answer

Why does cats returns `Id[T]` in the evaluation of a Reader?

I've used Kleisli before and, when you evaluate the computation passing the dependency to it the monad returns the value that I need. Now I'm using Reader and I see that when I run the program the evaluation is returned wrapped in an Id. Why? Also,…
Alejandro Echeverri
  • 1,328
  • 2
  • 19
  • 32
4
votes
1 answer

Apply list of functions to value using Scala Cats

in haskell I could do the following to a string let f = sequence [id, reverse] f "test" I am at a bit of a loss how to approach this in a better method using Cats. I currently have something like val f = List(fun1,fun2) val data = "test" f map…
user2726995
  • 2,064
  • 2
  • 21
  • 26
4
votes
2 answers

Cats Writer Vector is empty

I wrote this simple program in my attempt to learn how Cats Writer works import cats.data.Writer import cats.syntax.applicative._ import cats.syntax.writer._ import cats.instances.vector._ object WriterTest extends App { type Logged2[A] =…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
4
votes
2 answers

Cats: how to find the specific type from implicits

I have this code which compiles and works fine import cats.implicits._ Cartesian[ValidResponse].product( getName(map).toValidated, readAge(map).toValidated ).map(User.tupled) However I don't like the import of cats.implicits._ because there…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
4
votes
1 answer

Scala Cats: is there an ensure method on Either?

I have this piece of code on the Xor object of cats Xor.right(data).ensure(List(s"$name cannot be blank"))(_.nonEmpty) Now since Xor has been removed, I am trying to write something similar using Either object Either.ensuring(name.nonEmpty,…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373