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

Unable to recover exception in Future in Scala

The following Scala code uses cats EitherT to wrap results in a Future[Either[ServiceError, T]]: package com.example import com.example.AsyncResult.AsyncResult import cats.implicits._ import…
Robo
  • 4,588
  • 7
  • 40
  • 48
0
votes
2 answers

Scala - Is there a function to map Seq[A] => Seq[Either[Throwable, B]]?

I am looking for a function that will map over a collection coll: Seq[A] while applying a function f: A => B and returning a Seq[Either[Throwable, B]] so that errors can be handled downstream. Is there a function similar to this that is pre-baked…
D Cohen
  • 157
  • 1
  • 7
0
votes
1 answer

Scala Cats Validated with Parameterized Validation Result

I am following the example in https://typelevel.org/cats/datatypes/validated.html but with a twist: the type of the elements in the NEL is not a DomainValidation but a DomainValidation[A] and I'm not sure how to do this. Below is my attempt but am…
luddy2018
  • 13
  • 3
0
votes
1 answer

Lifting functions to monad transformers in Scala cats

Suppose there's a trait with abstract methods having different signatures (see below). To enable for-comprehension, I could define the same signature Result[A] for every abstract method. However, to simplify trait's subclasses, I'd like to keep…
0
votes
2 answers

Scala-Cats :- Is it possible to combine errors from different NonEmptyLists?

Is there any possibility to combine different errors from multiple variables using NonEmptyList type ValidationResult[A] = ValidatedNel[String, A] def throwErrorsWhenNumberIsLessThan6(x:Int):ValidationResult[Int] = if(x<6) s"$x !> 6".invalidNel…
Puneeth Reddy V
  • 1,538
  • 13
  • 28
0
votes
2 answers

Traversing Either in Scala

I wrote the following simple code: import cats.effect.IO import cats.instances.either._ import cats.syntax.TraverseSyntax object Test extends App with TraverseSyntax{ val e: Either[String, IO[Int]] = Right(IO(2)) e.sequence //error…
St.Antario
  • 26,175
  • 41
  • 130
  • 318
0
votes
2 answers

How to explicitly summon and use Functor for function

import scala.language.higherKinds import cats.Functor import cats.instances.list._ import cats.instances.function._ val list1 = List(1, 2) val list2 = Functor[List].map(list1)(i => i + 1) But things don't work so smoothly for functions, val f1 =…
sarveshseri
  • 13,738
  • 28
  • 47
0
votes
1 answer

What is the purpose of using [T : Type] in cats?

I'm learning to use Scala cats library. Quite often I see this type of definition like implicit def validatedApplicative[E : Semigroup]: Applicative[Validated[E, ?]] = ??? def parallelValidate[E : Semigroup, A, B, C](v1: Validated[E, A], v2:…
Puneeth Reddy V
  • 1,538
  • 13
  • 28
0
votes
1 answer

Scala - Flatten Sequence of EitherT

Suppose I have the following: val ints: Seq[Int] = ??? def foo(i: Int): EitherT[Future, Error, Seq[String]] = ??? I want to invoke the foo with the ints and accumulate Seq[String] result to eventually return EitherT[Future, Error,…
gyoho
  • 799
  • 2
  • 9
  • 25
0
votes
1 answer

logback.xml appender not used with cats IOApp

I have a scala app which uses the AWS Kinesis Client Library. I am using logback with the logstash encoder to format the logs from my app and the KCL as JSON. My App is also written using cats.effects.IO. import cats.effects._ object Main extends…
0
votes
2 answers

cats.data.EitherT with traverse

I have a question about using Traverse together with EitherT. Let's say we have a code like this: def validate(s: String): EitherT[Future, NumberFormatException, Int] = { EitherT(Future.successful(try { Right(s.toInt) } catch { case e: …
tomas.tunkl
  • 141
  • 1
  • 2
  • 10
0
votes
1 answer

How to combine type parameter bounds and functors using Cats?

I am encountering a number of use cases where I am end of attempting to write Functor, Applicative, Monad, etc instances in contexts where I am also using type parameter bounds. For example... import cats._ trait Preference[A] extends…
davidrpugh
  • 4,363
  • 5
  • 32
  • 46
0
votes
1 answer

Apply, Applicative, Monad, etc for contravariant functors in cats?

I have the following trait... import cats._ import cats.implicits._ trait Preference[-A] { self => def compare(a1: A, a2: A): Int final def ordering[A1 <: A]: Ordering[A1] = { new Ordering[A1] { def compare(a1: A1, a2: A1): Int =…
davidrpugh
  • 4,363
  • 5
  • 32
  • 46
0
votes
1 answer

How to abstract over a second type parameter when defining functors?

Learning idiomatic FP with Scala and Cats. I have the following code... package org.economicsl.mechanisms import cats._ import cats.implicits._ trait Preference[-A] { self => def compare(a1: A, a2: A): Int final def ordering[A1 <: A]:…
davidrpugh
  • 4,363
  • 5
  • 32
  • 46
0
votes
1 answer

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

I have an List[IO[A]] and I want to convert it to an IO[List[A]] In scalaz I would use sequenceU but I don't find the equivalent in cats
nam
  • 3,542
  • 9
  • 46
  • 68