scala-cats Questions
2
Solved
In Scala fs2 library for functional streams:
I am trying to understand the difference between flatMap, flatTap, evalMap and evalTap. They all seem to perform the same thing, which is transformatio...
Helenehelenka asked 12/11, 2019 at 14:58
1
This simplified case is where my question happen at...
object Main extends IOApp{
def run(args:Seq[String]): IO[ExitCode]={
Task{...}
.to[IO]
.as(ExitCode.Success)
}
}
Another option is Await...
Trussell asked 15/2, 2020 at 6:50
1
During a PR review, I was asked to replace Sync[F].delay with Sync[F].catchNonFatal because an exception might be thrown.
This does work:
scala> Sync[IO].delay(throw new Exception).recover{ ca...
Soapsuds asked 13/2, 2019 at 18:50
3
Solved
The standard library offers the unzip method on List:
scala>val l = List((1, "one"), (2, "two"), (3, "three"), (4, "four"), (5, "five"))
scala> l.unzip
// res13: (List[Int], List[String]) ...
Quadratic asked 18/7, 2019 at 16:38
4
Solved
Say I have a set of rules that have a validation function that returns IO[Boolean] at runtime.
case class Rule1() {
def validate(): IO[Boolean] = IO.pure(false)
}
case class Rule2() {
def validat...
Tort asked 4/12, 2022 at 14:47
4
Solved
I'm trying to send an email in the same transaction as inserting user into a database with Doobie.
I know that I can lift IO into ConnectionIO by using Async[ConnectionIO].liftIO(catsIO) where cats...
Age asked 9/1, 2020 at 4:22
1
Solved
I am trying to write some Scala code to have custom behaviour in an mtl style. For example, in order to expose the "write to DB" functionality abstracting over the specific effect I wrote...
Generalissimo asked 27/5, 2022 at 14:40
1
Solved
I want to define equality for some type that can be part of other objects or collections using cats/kitten. I don't want to have to define the equality for every other class.
For example:
import ca...
Fitz asked 16/10, 2021 at 0:2
3
Solved
I know I can traverse Lists
import cats.instances.list._
import cats.syntax.traverse._
def doMagic(item: A): M[B] = ???
val list: List[A] = ???
val result: M[List[B]] = list.traverse(doMagic)
A...
Brezhnev asked 16/2, 2018 at 13:58
4
Solved
I am trying to use OptionT to combine methods returning Future[Option[T]] in a for-comprehension.
import cats.data._
import cats.implicits._
import cats.instances.future._
for {
data <- Opti...
Encircle asked 13/4, 2017 at 9:29
1
Solved
I have an error type hierarchy for peeling bananas:
sealed trait PeelBananaError
object PeelBananaError {
case object TooRipe extends PeelBananaError
case object NotRipeEnough extends PeelBananaE...
Gizmo asked 21/5, 2021 at 18:38
1
Solved
When read the cats library's Functor source, I could not understand what the curly block after the return type of the function toFunctorOps does; My guess is that this block will be executed as par...
Coppage asked 2/5, 2021 at 0:3
1
Solved
I am using Doobie and in the examples that I found, it uses unsafeRunSync, like:
sql"select name from country"
.query[String] // Query0[String]
.to[List] // ConnectionIO[List[String]]
...
Niall asked 28/1, 2021 at 20:33
1
Solved
I'd like to apply effectual computation to the value inside MVar or Ref and atomically update it in case the computation succeeds or put back the initial value (in case of MVar)/simply do nothing(i...
Excrete asked 10/11, 2020 at 8:46
1
Solved
Is it possible to run multiple queries in parallel, using Doobie?
I have the following (pseudo)queries:
def prepareForQuery(input: String): ConnectionIO[Unit] = ???
val gettAllResults: Connecti...
Cursive asked 13/6, 2018 at 9:30
3
If I have a Future[Either[String, Int]] that represents either a possible error message (String) or a successful computation (Int), it is simple to move the Future's potential failure into the left...
Spanjian asked 28/2, 2019 at 17:30
3
Solved
When I have a function in Scala:
def toString[T: Show](xs: T*): String = paths.map(_.show).mkString
And the following type class instances in scope:
implicit val showA: Show[MyTypeA]
implicit val ...
Tc asked 12/8, 2020 at 16:3
1
Solved
I have an infinite fs2.Stream which may encounter errors. I'd like to skip those errors with doing nothing (probably log) and keep streaming further elements. Example:
//An example
val stream = fs2...
Misprint asked 14/7, 2020 at 21:33
1
Solved
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]{
//....
Bogeyman asked 22/5, 2020 at 7:30
2
Solved
I need to implement a transformation from one data structure to another:
A[B] => C[D]
I could just implement it as a method:
def transform(in: A[B]): C[D] = ???
But I would like to do it i...
Indigested asked 7/5, 2020 at 6:28
1
There is ApplicativeError[F,E] + F[A] and there is Either[E, A]. Both convey the message that the function could fail with an E or succeed with an A but I'm not sure about the different message the...
Radicel asked 28/4, 2020 at 14:57
0
The idea is to be able to unit test websocket endpoints on a router service. Any other kind of endpoint is fairly easy to test with a Request, but I can't figure out a way of easily testing websock...
Pontiff asked 18/3, 2020 at 11:35
2
Solved
I am trying to use Cats datatype Ior to accumulate both errors and successes of using a service (which can return an error).
def find(key: String): F[Ior[NonEmptyList[Error], A]] = {
(for {
b &...
Naresh asked 11/12, 2019 at 15:51
1
Solved
I was wondering if there exists a function (in scala or cats) which omits the result within flatMap. E.g.
Some("ignore this").ignoreArgumentFlatMap(Some("result"))
which would be the same as
So...
Letterhead asked 29/1, 2020 at 8:57
2
Solved
I have created two Http4s routes:
class FirstRoutes[F[_] : Async](service: FirstService[F]) extends Http4sDsl[F] {
def routes: HttpRoutes[F] = HttpRoutes.of[F] {
//... some code
}
}
class Se...
Recife asked 25/4, 2019 at 21:7
1 Next >
© 2022 - 2025 — McMap. All rights reserved.