Scalaz provides type classes and purely functional data structures for Scala
Questions tagged [scalaz7]
102 questions
2
votes
1 answer
Monadic Reduce in the State Monad
I'm stuck trying to reduce a list inside a state monad using a function returning State:
def op(t1: T, t2: T): State[S, T]
val list: State[S, List[T]]
I'd like to reduce the list to get a State[S, T]

Magnus Eklund
- 649
- 6
- 9
2
votes
0 answers
How to use scalaz' ContT monad transformer to implement a while loop
I'm trying to understand how to use the ContT monad transformer in Scalaz 7 to implement a while loop in a functional way while preventing stack overflows. A simple example illustrating the usage of ContT would be very helpful.

Martin Studer
- 2,213
- 1
- 18
- 23
2
votes
1 answer
Scalaz Functor typeclass special symbols
Recently I have come across this Scalaz code (e.g. https://github.com/scalaz/scalaz/blob/series/7.2.x/core/src/main/scala/scalaz/Functor.scala):
def compose[G[_]](implicit G0: Functor[G]): Functor[λ[α => F[G[α]]]] =
new CompositionFunctor[F, G]…

user2039784
- 199
- 9
2
votes
1 answer
How to use sequence from scalaz to transform T[G[A]] to G[T[A]]
I have this code to transform List[Future[Int]] to Future[List[Int]] by using scalaz sequence.
import scalaz.concurrent.Future
val t = List(Future.now(1), Future.now(2), Future.now(3)) //List[Future[Int]]
val r = t.sequence…

Xiaohe Dong
- 4,953
- 6
- 24
- 53
2
votes
2 answers
Why getOrElse would lose type inference in scalaz
When I use Either type in Scalaz, it is a very good design, but method getOrElse would lose type inference.
val either = ~3.right[String] | "123" // either: String
val either = 3.right[String] | "123" // either: Any
why val either =…

Xiaohe Dong
- 4,953
- 6
- 24
- 53
2
votes
1 answer
What happened to the Scalaz http module?
I am currenlty reading the book Scala in Action and while reading I'm trying to do the programming exercises. However, I'm stuck now on chapter 6.3 where I have to use Scalaz.
The thing is, the http module of Scalaz 6.0.3 is used. In this chapter I…

Marin
- 861
- 1
- 11
- 27
2
votes
1 answer
Puzzling behavior in scalaz-stream with chunk and zipWithIndex
I am trying to process a stream of data using scalaz-stream with an expensive operation※.
scala> :paste
// Entering paste mode (ctrl-D to finish)
def expensive[T](x:T): T = {
println(s"EXPENSIVE! $x")
x
}
^D
// Exiting paste…

underspecified
- 979
- 1
- 7
- 15
2
votes
1 answer
How to use applicative functors to combine Scalaz validations
Cannot figure out if it is possible to write something like this using Scalaz 7. I have tried to express myself with the comments inside the code block.
def validate1(p: String) = ValidationNel[String, Value] = ...
def validate2(p: String) =…

Lauri
- 4,670
- 2
- 24
- 17
2
votes
1 answer
scalaz Trampoline and IO
This question is related to this other question but reduced to a much simpler case:
I assume the following imports:
import scalaz._, Scalaz._
import Free._, effect._
I have the following generators:
val fromOneIO: () => IO[Int] = {
var i = 0; ()…

huynhjl
- 41,520
- 14
- 105
- 158
2
votes
1 answer
Using Scalaz7 with Play
I am having a little trouble in using Scalaz7 together with Play. Right now I am using the standard Play distribution with Scala 2.9.1 and scalaz-core 7.0-SNAPSHOT. This lives in the repository http://repo.typesafe.com/typesafe/repo/ which does not…

Andrea
- 20,253
- 23
- 114
- 183
2
votes
4 answers
Scala: extracting a repeated value from a list
I have often the need to check if many values are equal and in case extract the common value. That is, I need a function that will work like follows:
extract(List()) // None
extract(List(1,2,3)) // None
extract(List(2,2,2)) // Some(2)
Assuming one…

Andrea
- 20,253
- 23
- 114
- 183
2
votes
1 answer
Scalaz 7: Idiomatic way of turning values in Either to plain values plus logged errors?
Given a function f: A => E \/ B, what is an idiomatic way to gather the B results for some list of As while logging the Es?
I came up with the following (partially while answering this SO question):
import scalaz._, Scalaz._
type Logger[+A] =…

ron
- 9,262
- 4
- 40
- 73
2
votes
1 answer
Scalaz 7 - why using type alias results in ambigous typeclass resolution for Reader
Code to test with:
import scalaz.{Reader, Applicative}
class ReaderInstanceTest {
type IntReader[A] = Reader[Int, A]
val a = Applicative[({type l[A] = Reader[Int, A]})#l] // fine
val b = Applicative[IntReader]
// ^…

ron
- 9,262
- 4
- 40
- 73
1
vote
2 answers
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 syntax.monad._
((x: Int) => x + 1) map {_ * 7}
and it…

MaatDeamon
- 9,532
- 9
- 60
- 127
1
vote
2 answers
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]],
task3: Task[Option[C]])
…

Matthias Langer
- 994
- 8
- 22