Questions tagged [scalaz]

Scalaz provides type classes and purely functional data structures for Scala

Scalaz is a Scala library for functional programming.

It provides purely functional data structures to complement those from the Scala standard library. It defines a set of foundational type classes (e.g. Functor, Applicative, Monad) and corresponding instances for a large number of data structures.

More information is available on the Scalaz Project page

It is released under the BSD (open source) license.

1048 questions
450
votes
1 answer

Scalaz iteratees: "Lifting" `EnumeratorT` to match `IterateeT` for a "bigger" monad

If I have an EnumeratorT and a corresponding IterateeT I can run them together: val en: EnumeratorT[String, Task] = EnumeratorT.enumList(List("a", "b", "c")) val it: IterateeT[String, Task, Int] = IterateeT.length (it &= en).run : Task[Int] If the…
lmm
  • 17,386
  • 3
  • 26
  • 37
217
votes
8 answers

Good scalaz introduction

Recently scalaz caught my eye. It looks very interesting, but I have not found any good introduction to the library. Seems that scalaz incorporates a lot of ideas from haskell and mathematics. Most articles that I found assume that you already feel…
tenshi
  • 26,268
  • 8
  • 76
  • 90
106
votes
1 answer

Avoiding memory leaks with Scalaz 7 zipWithIndex/group enumeratees

Background As noted in this question, I'm using Scalaz 7 iteratees to process a large (i.e., unbounded) stream of data in constant heap space. My code looks like this: type ErrorOrT[M[+_], A] = EitherT[M, Throwable, A] type ErrorOr[A] = ErrorOrT[IO,…
Aaron Novstrup
  • 20,967
  • 7
  • 70
  • 108
92
votes
3 answers

Reader Monad for Dependency Injection: multiple dependencies, nested calls

When asked about Dependency Injection in Scala, quite a lot of answers point to the using the Reader Monad, either the one from Scalaz or just rolling your own. There are a number of very clear articles describing the basics of the approach (e.g.…
adamw
  • 8,038
  • 4
  • 28
  • 32
82
votes
1 answer

How do I replace a program written as a sequenced stream of state transitions with scalaz-stream?

I'm trying to understand how to reorganize a program which I would previously have written as a sequence of state transitions: I have some business logic: type In = Long type Count = Int type Out = Count type S = Map[Int, Count] val inputToIn:…
oxbow_lakes
  • 133,303
  • 56
  • 317
  • 449
79
votes
9 answers

Doing HTTP request in Scala

I am trying to issue a simple POST request to a webservice which returns some XML in Scala. It seems that Dispatch is the standard library used for this task, but I cannot find documentation for it. The main site, which I link above, explains at…
Andrea
  • 20,253
  • 23
  • 114
  • 183
77
votes
3 answers

Scalaz state monad examples

I haven't seen many examples of the scalaz state monad. There is this example but it is hard to understand and there is only one other question on stack overflow it seems. I'm going to post a few examples I've played with but I would welcome…
huynhjl
  • 41,520
  • 14
  • 105
  • 158
70
votes
2 answers

How does the Cats library in Scala relate to scalaz?

How does the Cats library relate to scalaz? The Cats project mentions it is descended from scalaz.
user2726995
  • 2,064
  • 2
  • 21
  • 26
53
votes
8 answers

How to reduce Seq[Either[A,B]] to Either[A,Seq[B]]?

Given a sequence of eithers Seq[Either[String,A]] with Left being an error message. I want to obtain an Either[String,Seq[A]] where I get a Right (which will be a Seq[A]), if all elements of the sequence are Right. If there is at least one Left (an…
ziggystar
  • 28,410
  • 9
  • 72
  • 124
53
votes
5 answers

Different Scala Actor Implementations Overview

I'm trying to find the 'right' actor implementation. I realized there is a bunch of them and it's a bit confusing to pick one. Personally I'm especially interested in remote actors, but I guess a complete overview would be helpful to many others.…
Stefan K.
  • 7,701
  • 6
  • 52
  • 64
51
votes
1 answer

Unexpected implicit resolution based on inference from return type

Given a typeclass where instance selection should be performed based on the return type: case class Monoid[A](m0: A) // We only care about the zero here implicit def s[T] : Monoid[Set[T]] = Monoid(Set.empty[T]) implicit def l[T] : Monoid[List[T]] =…
Patrick Prémont
  • 948
  • 7
  • 13
51
votes
1 answer

Function syntax puzzler in scalaz

Following watching Nick Partidge's presentation on deriving scalaz, I got to looking at this example, which is just awesome: import scalaz._ import Scalaz._ def even(x: Int) : Validation[NonEmptyList[String], Int] = if (x % 2 ==0) x.success…
oxbow_lakes
  • 133,303
  • 56
  • 317
  • 449
48
votes
1 answer

Using Scalaz Stream for parsing task (replacing Scalaz Iteratees)

Introduction I use Scalaz 7's iteratees in a number of projects, primarily for processing large-ish files. I'd like to start switching to Scalaz streams, which are designed to replace the iteratee package (which frankly is missing a lot of pieces…
Travis Brown
  • 138,631
  • 12
  • 375
  • 680
44
votes
4 answers

Turning A => M[B] into M[A => B]

For a monad M, Is it possible to turn A => M[B] into M[A => B]? I've tried following the types to no avail, which makes me think it's not possible, but I thought I'd ask anyway. Also, searching Hoogle for a -> m b -> m (a -> b) didn't return…
Noel M
  • 15,812
  • 8
  • 39
  • 47
44
votes
1 answer

How to understand traverse, traverseU and traverseM

I am confused about the usage case about traverse, traverseU and traverseM, I searched it in the scalaz website, the simple code example: def sum(x: Int) = x + 1 List(1,2,3).traverseU(sum) it looks like it is similar to (map and…
Xiaohe Dong
  • 4,953
  • 6
  • 24
  • 53
1
2 3
69 70