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

Mocking of BlazeClientBuilder[IO] to return mock client[IO]

I am using the BlazeClientBuilder[IO].resource method to get Client[IO]. Now, I want to mock the client for unit testing but cannot figure out how to do so. Is there a good way of mocking this and how would I do that? class ExternalCall(val…
Kumar Waghmode
  • 509
  • 2
  • 18
5
votes
2 answers

Efficient way to create abstract collection with cats

I have some code that uses Monix Observable for stream processing of a file. To test this code, I'd like for the operations I do on the Observable to be type independent so I can also perform them on any other data structure like List. That why I…
Martijn
  • 2,268
  • 3
  • 25
  • 51
5
votes
2 answers

How can I separate a list of ADTs into its variants?

Is it possible to somehow extend the solution to a sum type? sealed trait Group case class A extends Group case class B extends Group case class C extends Group def divide(l : List[Group]): //Something from what I can extract List[A], List[B] and…
simpadjo
  • 3,947
  • 1
  • 13
  • 38
5
votes
1 answer

Does Scala's list form a monoid under the concatenation operator?

First of all, sorry, but I'm not a native English speaker. I will however try to do my best. I'm actually studying some theoretical concepts as a hobby to deepen my understandings of functional programming and have some questions to check that I…
Argurth
  • 625
  • 6
  • 18
5
votes
2 answers

Can't call map method in function with cats library

I'm reading Advanced Scala With Cats. I stuck on this example at functor description (page 59): object FunctorsDemo extends App { import cats.instances.function._ import cats.syntax.functor._ val func1 = (x: Int) => x.toDouble val func2 =…
faoxis
  • 1,912
  • 5
  • 16
  • 31
5
votes
1 answer

Scala cats and traverse syntax for Either - doesn't compile

I am trying to use traverse (or sequence which is pretty much the same for my task) from cats library https://typelevel.org/cats/typeclasses/traverse.html . I want to traverse a List[A] with function A => Either[L,R] to get Either[L,List[R]] as a…
pkozlov
  • 746
  • 5
  • 17
5
votes
1 answer

Scala, Cats, Intellij IDEA: fix syntax & compile errors?

Using the Cats library for Scala in IntelliJ IDEA leads to errors even if terminal SBT works. Can we fix this? Or some workaround that isn't switching editor?
ticofab
  • 7,551
  • 13
  • 49
  • 90
5
votes
1 answer

How do I turn a cats IO into a Effect using http4s

I've got some code that returns an IO but I need a Effect in http4s. import cats.effect.{Effect, IO} class Service[F[_]: Effect] extends Http4sDsl[F] { val service: HttpService[F] = { HttpService[F] { case GET -> Root => …
Stephen
  • 4,228
  • 4
  • 29
  • 40
5
votes
2 answers

How to convert a Stream[IO, List[A]] to Stream[IO, A]

I want to parse a json file which output a collection of A. The signature of the Output is IO[List[A]] How can I convert this value to a Stream: Stream[IO, A] ? I can convert to a Stream[IO, List[A]] but it is not what I…
nam
  • 3,542
  • 9
  • 46
  • 68
5
votes
2 answers

could not find implicit value for parameter semigroupal

I just tried to compile the following code: import cats.Monoid import cats.instances.boolean._ // for Monoid import cats.instances.int._ // for Monoid import cats.instances.list._ // for Monoid import cats.instances.string._ // for Monoid import…
softshipper
  • 32,463
  • 51
  • 192
  • 400
5
votes
2 answers

Compose optional queries for for-comprehension in doobie?

I would like to run several queries in one transaction using a for-comprehension in doobie. Something like: def addImage(path:String) : ConnectionIO[Image] = { sql"INSERT INTO images(path) VALUES($path)".update.withUniqueGeneratedKeys('id',…
janne
  • 131
  • 1
  • 6
5
votes
2 answers

Stacking M, Either and Writer

I'm currently stacking Futures and Eithers using EitherT: type ErrorOr[A] = Either[Error, A] def getAge: Future[ErrorOr[Int]] = ??? def getDob(age: Int): ErrorOr[LocalDate] = ??? for { age <- EitherT(getAge) dob <-…
user404345
5
votes
1 answer

How to implement Functor[Dataset]

I am struggling on how to create an instance of Functor[Dataset]... the problem is that when you map from A to B the Encoder[B] must be in the implicit scope but I am not sure how to do it. implicit val datasetFunctor: Functor[Dataset] = new…
5
votes
1 answer

Scala and cats: Implicit conversion to identity monad

I have a function that computes sum of squares for numeric types as shown below. import cats.syntax.functor._ import cats.syntax.applicative._ import cats.{Id, Monad} import scala.language.higherKinds object PowerOfMonads { /** *…
Viswanath
  • 1,413
  • 13
  • 25
5
votes
2 answers

List[String] does not have a member traverse from cats

I am attempting to convert a List[Either[Int]] to anEither[List[Int]] using traverse from cats. Error [error] StringCalculator.scala:19:15: value traverseU is not a member of List[String] [error] numList.traverseU(x => { Code import…
vamsiampolu
  • 6,328
  • 19
  • 82
  • 183