Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
46 views

What does `=>` mean in scala generics?

Reading both the documentation for Scalaz and Cats, I notice that they frequently use => in their generic/polymorphic field. For example, from the scalaz page on applicatives, it has the following ...
Leif Andersen's user avatar
0 votes
1 answer
533 views

Need to remove Akka Framework from project due to licensing changes [closed]

I have recently joined a new company and have been assigned to a project that utilizes technologies such as Scala, SNMP, Akka Framework, Kafka, Kubernetes, and Spark. With Lightbend's recent change in ...
Kailash's user avatar
  • 89
2 votes
1 answer
120 views

What do the generic type constraints ":<:" and ":+:" mean in this Scala example?

From this talk about nanopass compilers in 2017 (https://github.com/sellout/recursion-scheme-talk/blob/master/nanopass-compiler-talk.org) I found the code snippet below. In this code snipped, I see ...
Charles Josephs's user avatar
1 vote
3 answers
133 views

Is it possible to control the number of argument in a function when using varargs in compile time(Scala)?

Let us suppose, we have to create the OddList[+T] which contains only odd number of elements. Now can we do something like this OddList(1,2) //Works fine OddList(1,2,3) //Compilation error if there ...
Pranjut's user avatar
  • 1,767
1 vote
1 answer
297 views

Automatically deriving a transformer from a rich case class to a simple case class?

I have a simple case class that represents a pet: case class Pet(name: String, age: Int) Now say I have a case class that has a 1:1 mapping to Pet, but where all of the properties have been wrapped ...
Cory Klein's user avatar
  • 54.6k
1 vote
1 answer
766 views

Do cats and scalaz create performance overhead on application?

I know it is totally a nonsense question but due to my illiteracy on programming skill this question came to my mind. Cats and scalaz are used so that we can code in Scala similar to Haskell/in pure ...
John's user avatar
  • 2,761
1 vote
0 answers
71 views

Scalaz Implicit Resolution Confusion

I'm running into a situation with Scalaz that's confusing me a bit. Let's say we have the following types defined. import scalaz.* import Scalaz.* type Example[A] = Unit \/ Success[A] case class ...
Silvio Mayolo's user avatar
1 vote
0 answers
66 views

Suggestions for creating a Scalaz Tree out of a polymorphic set of Nodes in a JSON tree

I have previously used C++ with tools like Antlr to read a DSL and convert it into an AST/symbol table and then used tree walkers to create object models which were then elaborated and then the ...
depappas's user avatar
4 votes
0 answers
156 views

Where should I put typeclass instances?

Lets say I develop a new public data structure, lets call it FancyList. It has no external dependencies and everybody loves it. This FancyList turns out to be a Functor, Monad, MonoidK, and Traverse. ...
cmhteixeira's user avatar
0 votes
2 answers
382 views

How do I change the version of a dependency in a Scala application that I haven't set?

I am trying to build a Scala play application and a dependency is suddenly failing to download due to the repo no longer being up Full stack trace below. I used to get the scalaz-stream v0.7a ...
Pete Leaman's user avatar
0 votes
1 answer
358 views

value sequence is not a member of cats.Applicative[F]

I'm migrating some scalaz based code to typelevel cats. project/plugins.sbt addCompilerPlugin("org.typelevel" % "kind-projector" % "0.11.3" cross CrossVersion.full) ...
user51's user avatar
  • 9,911
2 votes
2 answers
285 views

How to create a Functor for an ADT used in a cats Free Monad

I am writing a DSL using case classes with the help of the cats.free.Free Monad library. The DSL is to be interpreted by Actors receiving the message, so each actor has to first unwrap a command using ...
Henry Story's user avatar
  • 2,136
1 vote
2 answers
165 views

mutable.Map deep merge

Is there a concise way to deeply merge two mutable maps in Scala? case class K1(i: Int) case class K2(i: Int) def deepMerge(map: mutable.Map[K1, Map[K2, List[Int]]], mergee: mutable.Map[...
St.Antario's user avatar
  • 27.1k
0 votes
1 answer
197 views

diverging implicit expansion for type scala.math.Ordering

I'm sorry for this question but I haven't been able to get an answer from the previous questions. I have a Scala class case class Problem ( ref: Ref, v1: Option[String], v2: ...
Shashwat Sharma's user avatar
3 votes
1 answer
112 views

Compare Two UUID Using Scalaz ===

What do I need to do to compare two Java UUIDs? Do I need to create an instance of the Equal typeclass for java.util.UUID?
Mojo's user avatar
  • 1,182
0 votes
1 answer
54 views

Not Sure How to Write the Implicit for Equality Using Scalaz

In Cats I can do import cats.Eq implicit val eq: Eq[Foo] = Eq.fromUniversalEquals[Foo] How do I do this using Scalaz (7.3.1)? I tried this from the examples in the repo but I got a compile ...
Mojo's user avatar
  • 1,182
1 vote
1 answer
71 views

How is scalaz able to do "A \/ B", and how can I do my own "B.??" or "A <??> B"

I am relatively new to scala implicits, but if I wanted to be able to do 5.??, I would do: class MyInt(int: Int) { // Useless, just to make a point def ?? : Int = int * 100 } implicit def ...
Deaddorks's user avatar
2 votes
2 answers
3k views

Composing Multiple Futures and Option in Scala with ZIO

I just started evaluating ZIO to improve the programming model and the performance of my asynchronous Scala code. In my code base I deal with Future[Option[T]] often, and to this point I have dealt ...
Vidya's user avatar
  • 30.2k
2 votes
2 answers
80 views

scalaz Monoid for SortedMap

I believe scalaz has monoid instances for both Map and SortedMap. But this doesn't work scala> import scalaz._, Scalaz._ import scalaz._ import Scalaz._ scala> Map(1 -> 1) |+| Map(1 -> ...
GuoLiang Oon's user avatar
1 vote
1 answer
76 views

How to customize monad transformer in scalaz

I'm learning scalaz these days. When I compare scalaz with Haskell, I find that it's hard to customize my own monad transformer. The code I can do in Haskell like this: newtype Box a = Box a ...
Jacky Wong's user avatar
4 votes
1 answer
441 views

Handling multiple error types via either/disjunction Scala

I have 3 distinct modules each with its own error type. Following is a very simplified version. object ModuleA { case class ErrorA(msg: String) def getA: ErrorA \/ String = "1".right } object ...
Mridul's user avatar
  • 41
4 votes
1 answer
405 views

Replace scalaz ListT with semantically equivalent cats functionality

cats does not provide ListT monad transformer so how could we rewrite the following snippet which uses scalaz ListT in a for-comprehension to a semantically equivalent snippet in cats import scalaz._ ...
Mario Galic's user avatar
  • 48.3k
4 votes
2 answers
1k views

How to use Monoid Scala?

trait Monoid[A] { def op(a1: A, a2: A): A def zero: A } def mapMergeMonoid[K, V](V: Monoid[V]): Monoid[Map[K, V]] = new Monoid[Map[K, V]] { override def op(a1: Map[K, V], a2: Map[K, V]): Map[...
andrew17's user avatar
  • 925
1 vote
4 answers
1k views

Are there any triple equals === methods outside of Cats in Scala?

I have spent a while searching on Google for a non-Cats triple equals method, but can't find anything apart from Scalaz. Unfortunately, I have been unable to work out the import for === in this ...
J Hubbard's user avatar
  • 107
9 votes
4 answers
4k views

List[Try[T]] to Try[List[T]] in Scala

I would like to know how to convert a List[Try[T]] into Try[List[T]] in Scala? I have tried using an accumulator and folding right but it doesn't seem ideal.
Valahu's user avatar
  • 823
1 vote
1 answer
365 views

How to call Await.ready for function returning EitherT[Future,Failure,Result]

(1) I have a function returns EitherT as createData(m):EitherT[Future, Failure, Result] (2) I want to do the following transformation sequentially so that wait for each call to createData complete ...
Tom's user avatar
  • 83
0 votes
1 answer
244 views

How to convert Free monads to Free applicatives

I am using cats library and want to convert Free Monad to Free Applicative. We have a lot of code in Free monads.. But now some parts of the application has to run in parallel. There are options to ...
abhishek's user avatar
0 votes
0 answers
139 views

How to do EitherT[Future, Failure, Iterator[A]] map with index

I use EitherT[Future, Failure, Iterator[A]]. The regular scala can map with index as below. myList.zipWithIndex.map { case (element, index) => println(element, index) s"${element}(${index})...
Tom's user avatar
  • 83
0 votes
1 answer
447 views

How to set initial value for foldLeft When Using EitherT[Future, Failure, Option[B]]

I am using EitherT[Future, Failure, Option[B]] in the following function which does foldLeft. How to set Initial value for foldLeft in the code below ? def doWork[A, B](seq: Set[A])(f: A => ...
Tom's user avatar
  • 83
7 votes
4 answers
5k views

How to elegantly perform multiple effects in parallel with ZIO

I know that I can use import zio.Task def zip3Par[A, B, C](a: Task[A], b: Task[B], c: Task[C]): Task[(A, B, C)] = a.zipPar(b).zipWithPar(c) { case ((a, b), c) => (a, b, c) } def zip4Par[A, B, ...
Matthias Langer's user avatar
1 vote
0 answers
40 views

How to fix State monoid type in the following code

I am using State monoid to update the state of an object as listed in Functional and Reactive Domain modeling book while working CQRS. As I understand, if you do not want to return any value, you can ...
Srini's user avatar
  • 79
1 vote
1 answer
727 views

IO Monad vs Reader Monad

I wonder is there any relation between IO Monad and the Reader monad ? Can the Environment in the Reader monad be an effect ? If so, how does ZIO or Cats IO, scalaz-effects deal with Reader Monad ...
MaatDeamon's user avatar
  • 9,602
3 votes
1 answer
231 views

Type classes vs Data Types in functional Libraries in scala such as Cats and ScalaZ

ScalaZ and Cats both have this notion of type class and Data Types. Although I understand type classes, and type classes instances, I don't understand their use of the term "data types". Things ...
MaatDeamon's user avatar
  • 9,602
4 votes
2 answers
124 views

Lift \/[A, B] into EitherT[Future, A, B]

How to lift \/[Error, Int] into EitherT[Future, Error, Int] using point/liftM syntax such that lifting is on the right-hand side? I have the following scenario for { r1 <- f1: EitherT[Future, ...
Mario Galic's user avatar
  • 48.3k
3 votes
1 answer
304 views

Monad for-comprehensions with implicit Monad fails, use inheritance?

I am running into this famous 10 year old ticket in Scala https://github.com/scala/bug/issues/2823 Because I am expecting for-comprehensions to work like do-blocks in Haskell. And why shouldn't they, ...
rausted's user avatar
  • 959
0 votes
1 answer
79 views

Scalaz |-> counterpart in Cats

I noticed that the Scalaz |-> operator is not implemented in Cats. Is there a function offering similar semantics?
LuGo's user avatar
  • 5,025
3 votes
1 answer
293 views

How to manage the hierarchy of State in Functional Programming?

Say I have a Student class which has lots of actions: final case class Student(name: String, knowledge: List[String]) { def learn(item: String) : Student = this.copy(knowledge = knowledge :+ item) }...
Ukonn Ra's user avatar
  • 754
1 vote
2 answers
274 views

Scalaz 7 how to use Functor with Function1

Hi i am starsting to learn Scalaz. I want to get a function and map over it with another function. although i am able to write this: import scalaz._, Scalaz._ import std.function._ import ...
MaatDeamon's user avatar
  • 9,602
2 votes
1 answer
46 views

import scalaz monad syntax outside of function

Is there a way I can avoid importing monad syntax in the body of all my functions? Here's what I'm stuck writing: object Example { def doMonadThings[M[_]: Monad, A](ma: M[A]): M[A] = { val ...
codenoodle's user avatar
0 votes
2 answers
1k views

onSuccess and onFailure doesn't return anything when they are last statement in def

I am trying to work with collection of futures and having trouble with returning the result from a def based on future status. Below is my code: final case class StagesToRun(stages : Set[StageRun]) ...
Explorer's user avatar
  • 1,637
2 votes
1 answer
322 views

How do error handling monads like Eithers achieve referential transparency?

From reading about FP, my understanding of the benefits of removing side-effects is that if all our functions are pure/have referential transparency (something that can only be achieved without side-...
suleydaman's user avatar
3 votes
1 answer
1k views

Problem with Intellij and Heap Size Minimum

I am importing this project https://github.com/scalaz/scalaz into the Intellij. But I get a problem with minimum heap size. I am not sure where the size is beeing set. Any advices to fix this ...
Mojo's user avatar
  • 1,182
4 votes
1 answer
502 views

Is there a library in F# that is similar to scalaz, cats and arrow (Kotlin)?

What is a recommended approach in F# to use "high level" functional patterns? For Scala there are scalaz and cats, even there is Arrow for Kotlin, though I have not found anything similar for F#.
sampai's user avatar
  • 114
1 vote
2 answers
2k views

How to elegantly combine multiple Tasks containing options in ZIO

I'm looking for the most elegant implementation of import scalaz.zio.Task def combineTasks[A, B, C, D](task1: Task[Option[A]], task2: Task[Option[B]], ...
Matthias Langer's user avatar
2 votes
1 answer
872 views

The difference between IO and UIO in scalaz ZIO

What is the difference between IO and UIO in the new version from ZIO for example UIO[Long] and IO[Nothing, Long]?
NaseemMahasneh's user avatar
1 vote
2 answers
149 views

Defining Monad, Applicative, and Functor instances for a type class

Let's say I have defined a type class for Caching computations. trait Cached[F[_], A] { def value: F[A] } Intuitively, Cached wraps the computation so we can either evaluate it at run time or load ...
Ashkan's user avatar
  • 1,673
2 votes
1 answer
382 views

What is the difference between the Store Comonad and a Representable Store Comonad in functional programming?

The Representable Store Comonad and the Store Comonad offers similar features... When should we use one over the other, and what are the benefits?
Valy Dia's user avatar
  • 2,851
0 votes
0 answers
233 views

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]...
Anton's user avatar
  • 27
5 votes
1 answer
84 views

What is a Cohoist in scalaz?

The scalaz defines a Cohoist: trait Cohoist[F[_[_], _]] extends ComonadTrans[F] { def cohoist[M[_], N[_]: Comonad](f: M ~> N): F[M, ?] ~> F[N, ?] } where ComonadTrans is defined: ...
Valy Dia's user avatar
  • 2,851
4 votes
2 answers
3k views

Scala: Find and update one element in a list

I am trying to find an elegant way to do: val l = List(1,2,3) val (item, idx) = l.zipWithIndex.find(predicate) val updatedItem = updating(item) l.update(idx, updatedItem) Can I do all in one ...
Wonay's user avatar
  • 1,240

1
2 3 4 5
21