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
1 answer

Type resolution with flatMap

why do i need to add the type annotation at the first line? c.get[List[String]]("primary-group") is Decoder.Result[List[String]] after flatMap it should keep the top type and be Decoder.Result[String] but it changes to Either[DecodingFailure,…
user1698641
  • 211
  • 1
  • 12
0
votes
1 answer

OptionalT fromOptional and liftF in ScalaZ

I´ve been watching some examples of monads transformers with Cats, and I was trying to reproduce those in Scalaz Here I have a for comprehension where I first receive an optional which I flatMap with OptionalT, and the second function return a…
paul
  • 12,873
  • 23
  • 91
  • 153
0
votes
1 answer

Monad of Nothing doesn't work in cats

I am having issues with cats/monads/understanding. Please consider following snippet: import cats._ import cats.implicits._ final case class My[T]() implicit val monadMy: Monad[My] = new Monad[My] { ... } // this compiles def test11[A, B](m:…
Dmytro Starosud
  • 397
  • 1
  • 15
0
votes
1 answer

Applicative style using cats library

This is a follow-up to my previous question: Suppose I want to use Applicative to apply function A => B => C to List[A] and List[B]. I believe it looks like that in Haskell: pure f <*> as <*> bs // apply f to List[A] and List[B] or f <$> as <*> bs…
Michael
  • 41,026
  • 70
  • 193
  • 341
0
votes
3 answers

Merging 2 Eithers with Cats Cartesian

I wrote this code import cats.Cartesian import cats.instances.option._ val x = Some(1) val y = Some(2) Cartesian[Option].product(x, y) This gave me Some((1, 2)). Good! So I tried again import cats.Cartesian import cats.instances.either._ val x :…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
0
votes
1 answer

Hide for comprehension

I´m working in a DSL using monads and for comprenhension. Since my client has no idea of Scala I´m trying to hide so much syntax as I can. So far I have this DSL (for { * <- Given("A message", message(path = "esb", version = TWO)) * <-…
paul
  • 12,873
  • 23
  • 91
  • 153
0
votes
2 answers

How can I define an instance of a typeclass in scala that can be used for all subclasses of a particular type?

I am trying to define an instance of Show (from cats 0.9) that can be used for all members of an ADT as follows: import $ivy.`org.typelevel::cats:0.9.0`, cats.Show sealed abstract class Colour(val name: String) implicit val ColourShow = new…
Rich Ashworth
  • 1,995
  • 4
  • 19
  • 29
0
votes
2 answers

Scala: How to use Functors for multi type parameter trait

I have and ADT which is basically a wrapper over Function1: case class Abstract[M[_], A, B](f:M[A] => M[B]) { def fn: M[A] => M[B] = { case x: M[A] => f(x) } } I want to map over these, so I defined a Functor like so: trait AbstractAPI[E] { …
ixaxaar
  • 6,411
  • 3
  • 24
  • 33
0
votes
2 answers

Check lists of numbers and accumulate errors

Suppose I need to check if a given list of numbers starts with of one or more 1, one or more 2 and one or more 3. If the check fails I would like to get all errors accumulated, e.g. val check: List[Int] => Either[String, Unit] = ??? check(Nil) …
Michael
  • 41,026
  • 70
  • 193
  • 341
0
votes
1 answer

Scala type inference does not work with type bounds, unless the type is specified explicitly

I'm trying to create a documentation wrapper around functions in scala like, so that the wrapper can be queried for its containing function's documentation, like so: trait WrappedFunction1[A, B] { def f : Function1[A, B] def doc: String def…
ixaxaar
  • 6,411
  • 3
  • 24
  • 33
0
votes
1 answer

Chaining Cats Validated with andThen

I am reading this article http://typelevel.org/cats/datatypes/validated.html It says that Validated can be used to do Sequential validations using "andThen" method. This means we stop at the first error and not collect all the errors. I tried the…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
0
votes
1 answer

How to provide an execution context to a future functor?

Using Cats, I have my functor declarations in a package object. This works fine, except for the futureFunctor, as it requires an implicit ExecutionContext: package object util { implicit val futureFunctor: Functor[Future] = new Functor[Future] { …
Lasf
  • 2,536
  • 1
  • 16
  • 35
0
votes
2 answers

Validating list of strings

This is a follow up to my previous question. Suppose I need to write a function validate in order to make sure that a given list of strings consists of "a", "b", and one or more "c". def validate(ss: List[String]): Either[NonEmptyList[MyError],…
Michael
  • 41,026
  • 70
  • 193
  • 341
0
votes
1 answer

value pure is not a member of

I have written this code import scala.concurrent._ import scala.concurrent.ExecutionContext.Implicits.global import cats.Applicative import cats.data.OptionT import cats.instances.future._ import cats.syntax.applicative._ object PureTest extends…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
0
votes
1 answer

Cannot upgrade Cats from 0.7.8 to 0.9.0

My project is using Cats 0.7.8 and Scala 2.11.8. If I update by build.sbt file and change my cats dependency from "org.typelevel" % "cats-core_2.11" % "0.7.8" to "org.typelevel" % "cats-core_2.11" % "0.9.0" and then try to do a sbt clean compile I…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
1 2 3
61
62