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

Cats OptionT future not completing

I'm having an issue where my future (wrapped with OptionT) doesn't complete. When I explicitly await the result withoutn OptionT, I can see the correct output (See logs below Some(2,2)). But in my for comprehension, we never see the "Ids: " logs.…
smur89
  • 329
  • 1
  • 3
  • 15
0
votes
0 answers

Scala, Cats and Couchbase - how to connect these 3 things together?

I create an application where I would like to use Couchbase as db. I have done a research , but I did not find any good source of knowledge how to use Couchbase with Cats and Scala. The only thing is http://reactivecouchbase.org/ but it looks like…
Developus
  • 1,400
  • 2
  • 14
  • 50
0
votes
1 answer

Implement repository with State Monad (use IO and State together)

I have this repository : trait TrainRepository { def get(trainId: TrainId): IO[Option[Train]] def getAll: IO[List[Train]] def save(train: Train): IO[Train] } I would like to provide an in-memory implementation using a State Monad. But I am…
Dnomyar
  • 707
  • 5
  • 17
0
votes
2 answers

parMapN that finishes even when one program encounters an error

Using parMapN, multiple IOs can be executed in parallel, like this: import cats.implicits._ import cats.effect.{ContextShift, IO} import scala.concurrent.ExecutionContext implicit val cs: ContextShift[IO] =…
Florian Baierl
  • 2,378
  • 3
  • 25
  • 50
0
votes
0 answers

Create Validation.valid via type alias in the Cats from Scala

Here is a simple example that is not compiled: import cats.data.Validated object Ex { type FailSlow[A] = Validated[List[String], A] case class User(name: String, age: Int) //this works fine: def validBoth(name:String,…
Alexandr
  • 9,213
  • 12
  • 62
  • 102
0
votes
2 answers

how to return either value or throw error in Scala

I have a list of emails, for each one I'll look it up in email table to see if that email exist. if it does, do nothing else I'll throw error. here is my code; def lookupEmailStatus(email: EmailAddress, requestId: RequestId)( implicit ec:…
user468587
  • 4,799
  • 24
  • 67
  • 124
0
votes
0 answers

Implicit parameter for BiFunctor

I'm planning to use Bifunctor IO with a channel for errors. So I tried to provide an implicit instance for MonadError but it fails to compile. import cats.MonadError sealed trait AppErrors //... object App{ def runApp[F[_, _]:…
St.Antario
  • 26,175
  • 41
  • 130
  • 318
0
votes
0 answers

Combine errors cats Validated

I go up to competence on Cats Validated and I have a problem to concatenate my error accumulator. I get this error Error:(88, 17) discarded non-Unit value errorList ++= errors I don't know how can I resolve this error. My code : def…
Robert25
  • 103
  • 6
0
votes
0 answers

Continually stream with just algebra in Scala

Would it be possible to define a continuous stream of the same element with just algebra? If I look at the implementation of Streams in Scala I see the following method definition: def continually[A](elem: => A): Stream[A] = cons(elem,…
Anton
  • 27
  • 1
  • 4
0
votes
1 answer

type mismatch; found : cats.Show[shapeless.CNil] required: cats.Show[A] after adding scalac option -Ypartial-unification in sbt

I have below code. import enumeratum.{Enum, EnumEntry} sealed abstract class AppEnvironment extends EnumEntry object AppEnvironment extends Enum[AppEnvironment] { case object Local extends AppEnvironment case object Testing extends…
user51
  • 8,843
  • 21
  • 79
  • 158
0
votes
1 answer

How to map an Option inside a for comprehension with EitherT

Hi I am trying to execute a for comprehension like (for { player <- playerRepository.findById(playerId) // findById returns EitherT[Future, String, Player] teamOpt <- teamRepository.findByPlayer(playerId) // findByPlayer returns EitherT[Future,…
agusgambina
  • 6,229
  • 14
  • 54
  • 94
0
votes
1 answer

Fork Join with generic monad scala?

Is it possible to express in a generic way, using cats or scalaz this? val common: F[Common] = ... val a: F[A] = common.flatMap(commonToA) val b: F[B] = common.flatMap(commonToB) val result: F[(A,B)] = a someFunctionToProduct b And ensure that the…
caeus
  • 3,084
  • 1
  • 22
  • 36
0
votes
1 answer

List[EitherT[Future, String, CustomObj]] => EitherT[Future, String, List[CustomObj]]

How to use sequence function for List[EitherT[Future, String, CustomObj]] with custom class CustomObj ? I want something like that : import scala.language.postfixOps import cats.instances.list._ import cats.syntax.traverse._ import…
Dex
  • 13
  • 2
0
votes
0 answers

Functional way of implementing DB access with additional logic

Currently, my goal is to communicate with DB using CRUD approach. Between simple operation i may have some extra steps (additional business-logic which may throw some errors). import cats.effect.IO import scalikejdbc._ IO(NamedDB(MyDB) localTx { …
Nikita Ryanov
  • 1,520
  • 3
  • 17
  • 34
0
votes
1 answer

fs2.Stream observeAsync does not execute a given sink asynchronously

I'm experimenting with fs2.Stream concurrent features and got some misunderstanding about how it works. I would like to send stream content through some sink in parallel. Here is what I tried: object TestParallelStream extends App { val…
Some Name
  • 8,555
  • 5
  • 27
  • 77