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

Why does the code with extension method compile?

I have two functions: override def build_url(dbType: DbDriverType, dbAddr: String, dbName: String): F[DbAddr] = dbType match { case PostgresSql => Applicative[F].pure(DbAddr("jdbc:postgresql://" |+| dbAddr |+| "/" |+| dbName)) case _…
softshipper
  • 32,463
  • 51
  • 192
  • 400
0
votes
1 answer

What does private[routes] mean?

I have the following code snippet: final class UserRoutes[F[_]: Defer: JsonDecoder: MonadThrow]( auth: Auth[F] ) extends Http4sDsl[F] { private[routes] val prefixPath = "/auth" private val httpRoutes: HttpRoutes[F] = HttpRoutes.of[F] { …
softshipper
  • 32,463
  • 51
  • 192
  • 400
0
votes
1 answer

Write laws or unit test for tagless algebras

I have written two tagless algebras and I would like to write the laws for one of them. The algebras are as follows: @newtype case class Variable(v: String) @newtype case class Value(v: String) trait Environment[F[_]] { def get(v: Variable):…
softshipper
  • 32,463
  • 51
  • 192
  • 400
0
votes
0 answers

value pure is not a member of io.databaker.db.DbParameter

I have the following code, that does not compile: import cats._ import cats.implicits._ import cats.data._ import cats.syntax.applicative._ // for pure import cats.syntax.applicativeError._ // for raiseError etc final class…
softshipper
  • 32,463
  • 51
  • 192
  • 400
0
votes
1 answer

The first final tagless approach

I am trying to use the first time tagless final pattern in Scala and struggling a bit. I have the following algebras definition: trait DbSetting[F[_]] { def read(url: String, user: String, pw: String): F[DbParameter] } trait Environment[F[_]] { …
softshipper
  • 32,463
  • 51
  • 192
  • 400
0
votes
1 answer

fs2 Stream scala No implicit of type : Stream.Compiler[Eval,G_]

I'm trying to create a Stream[Eval, String] as follows : import cats.Eval import cats.effect.{ExitCode, IO, IOApp} import fs2._ object StringEval extends IOApp { def evalString: Eval[String] = Eval.always{ val r = new…
Her sincerly
  • 373
  • 1
  • 13
0
votes
1 answer

Use mapN to apply values

I have the following code snippet: final case class Configuration(env: Env, user: String, password: String, address: String) trait DbSetup[F[_]] { type EnvT[A] = OptionT[F, A] def system: EnvT[Env] def user: EnvT[String] def password:…
softshipper
  • 32,463
  • 51
  • 192
  • 400
0
votes
1 answer

Generate apply methods creating a class

Scala 2.13 I have tons of similar traits of the form trait SomeTrait[F[_]]{ def someOp(): F[Unit] //... } and their implementations class SomeTraitImpl[F[_]: Sync] extends SomeTrait[F]{ //... } object SomeTrait{ def apply[F[_]:…
0
votes
1 answer

Testing Higher order functions scala + Cats Resource

I have one question. I'm using the following function together with the Scala cats Library. def process( client: Resource[IO, HttpClient] = HttpClientFactory.createClient() ): IO[Long] = client.use(httpClient => { for { …
Jorge Machado
  • 752
  • 1
  • 8
  • 28
0
votes
1 answer

Missing Implicit for Log Cats.Effect.IO

I am trying to get this simple example running using the redis4cats library: import cats.effect._ import cats.implicits._ import dev.profunktor.redis4cats.Redis import dev.profunktor.redis4cats.effect.Log.noop object QuickStart extends IOApp { …
Mojo
  • 1,152
  • 1
  • 8
  • 16
0
votes
2 answers

Combining two EitherT, return first if it succeeds else return second

Consider the following snippet: def foo(x:String): EitherT[F, Throwable, String] = ??? def bar(x:String): EitherT[F, Throwable, String] = ??? I want the following: On some input s, first call foo(s) and if it "fails" return the output of bar(s)…
Jus12
  • 17,824
  • 28
  • 99
  • 157
0
votes
1 answer

Scala how to call a future function on hashmap items

I have a hashmap map: Map[A, Seq[B]] and I want to call a future function (that returns Future[Either[Error, Unit]]) for each B in my map. For example, given the following function def fooFunc(hashMap: Map[A, Seq[B]]): Future[Either[Error, Unit]]…
khan7
  • 75
  • 2
  • 8
0
votes
1 answer

Require semigroup to be associative in scala

A semigroup is required to be associative, but I could define a Semigroup like: trait Semigroup[T] { def op(t1:T, t2:T) : T } def plus = new Semigroup[Int] { def op(t1:Int, t2:Int) = t1 - t2 } I am able to implement plus which is not…
Rob
  • 3,333
  • 5
  • 28
  • 71
0
votes
1 answer

Lifting A Future using EitherT.liftF When Value Is Already a Future

I have a value like this: val ss: Option[Future[List[Either[Error, File]]]] And what I want to do is to lift this to an EitherT.liftF[Future, Error, List[Either[Error, File]]] so what I did was this: ss match { case Some(value) =>…
Mojo
  • 1,152
  • 1
  • 8
  • 16
0
votes
2 answers

Mixing Future and F[] inside a for comprehension

I have hit a problem withe my for comprehension as follows: def doSomething(): F[String] = { for { _ <- Future.traverse(items)(item => doSomeWork(item)) // Future[] _ <- doSomeOtherWork(42) //F[] } yield (()) } The…
Mojo
  • 1,152
  • 1
  • 8
  • 16