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
22
votes
2 answers

Is the Writer Monad effectively the same as the State Monad?

There's a great tutorial here that seems to suggest to me that the Writer Monad is basically a special case tuple object that does operations on behalf of (A,B). The writer accumulates values on the left (which is A) and that A has a…
jordan3
  • 877
  • 5
  • 13
22
votes
2 answers

How do you use scalaz.WriterT for logging in a for expression?

How do you use scalaz.WriterT for logging?
Keynan
  • 1,338
  • 1
  • 10
  • 18
21
votes
1 answer

Lifting a bijection into a functor

Maybe I'm missing something obvious, but I'm trying to clean up some boilerplate in a project that uses Scalaz 7, and I'm not finding one particular puzzle piece that seems pretty simple and possibly useful. Suppose we have a bijection between two…
Travis Brown
  • 138,631
  • 12
  • 375
  • 680
21
votes
3 answers

Comonad example in Scala

What is Comonad, if it's possible describe in Scala syntax. I found scalaz library implementation, but it's not clear where it can be useful.
Stas
  • 751
  • 1
  • 11
  • 22
20
votes
1 answer

Layering State with Either in scalaz

In Integrating State with Either (slide 88), given the pattern of State layered under Either, is there a recommended approach for adding another type of state, e.g., logging via something like Writer? It seems the new state has to live between the…
Sim
  • 13,147
  • 9
  • 66
  • 95
20
votes
1 answer

Error handling monads in Scala? Try vs Validation

scalaz.Validation is said to be more powerful than the Try monad, because it can accumulate errors. Are there any occasions where you might choose Try over scalaz.Validation or scalaz.\/ ?
James McCabe
  • 1,879
  • 2
  • 15
  • 22
19
votes
2 answers

a clean way to combine two tuples into a new larger tuple in scala?

Let's say I have the following tuples: scala> val t1 = Tuple2("abcd", "efg") t1: (java.lang.String, java.lang.String) = (abcd,efg) scala> val t2 = Tuple2(1234, "lmnop") t2: (Int, java.lang.String) = (1234,lmnop) scala> val t3 = Tuple3("qrs",…
jxstanford
  • 3,339
  • 3
  • 27
  • 39
19
votes
1 answer

Is it just a coincidence that Kleisli, ReaderT, and Reader are the same in Scalaz

In Scalaz Kleisli[F, A, B] is a wrapper for A => F[B]. ReaderT[F, A, B] -- reader monad transformer -- is just an alias of Kleisli[F, A, B]. Reader[A, B] monad is a specialization of ReaderT with identity monad Id: type Reader[A, B] =…
Michael
  • 41,026
  • 70
  • 193
  • 341
19
votes
2 answers

Validation versus disjunction

Suppose I want to write a method with the following signature: def parse(input: List[(String, String)]): ValidationNel[Throwable, List[(Int, Int)]] For each pair of strings in the input, it needs to verify that both members can be parsed as…
Travis Brown
  • 138,631
  • 12
  • 375
  • 680
19
votes
2 answers

Using context bounds "negatively" to ensure type class instance is absent from scope

tl;dr: How do I do something like the made up code below: def notFunctor[M[_] : Not[Functor]](m: M[_]) = s"$m is not a functor" The 'Not[Functor]', being the made up part here. I want it to succeed when the 'm' provided is not a Functor, and fail…
nadavwr
  • 1,820
  • 16
  • 20
19
votes
5 answers

Converting a tuple of options to an option of tuple with Scalaz or Shapeless

Having (Some(1), Some(2)) I expect to get Some((1, 2)) and having (Some(1), None) I expect to get None
Nikita Volkov
  • 42,792
  • 11
  • 94
  • 169
18
votes
2 answers

Map on Scalaz Validation failure

import scalaz._ import Scalaz._ "abc".parseInt This will return a Validation[NumberFormatException, Int]. Is there a way I can apply a function on the failure side (such as toString) to get a Validation[String, Int]?
huynhjl
  • 41,520
  • 14
  • 105
  • 158
18
votes
1 answer

Monads VS Applicative functors for Futures

Suppose I want to aggregate data from 2 remote services, and serve response as fast as I can: def loadUser: Future[User] def loadData: Future[Data] case class Payload(user: User, data: Data) I understand that this one executes async tasks…
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
18
votes
4 answers

A little help on understanding Scalaz Future and Task

I'm trying to understand the idea and purpose behind scalaz concurrent package, primarily Future and Task classes, but when using them in some application, it's now far from simple sequential analog, whereas scala.concurrent.Future, works more then…
user1078671
18
votes
2 answers

Combining EitherT and Future

I have an app that does a lot of calls to different backend systems, and hoping to use for-comprehensions to simplify the process flow across the backend systems. I'm looking to combine EitherT (scalaz) and Future (scala 2.10) so I can capture the…
Mark Sivill
  • 825
  • 1
  • 9
  • 18
1 2
3
69 70