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

Traversing lists and streams with a function returning a future

Introduction Scala's Future (new in 2.10 and now 2.9.3) is an applicative functor, which means that if we have a traversable type F, we can take an F[A] and a function A => Future[B] and turn them into a Future[F[B]]. This operation is available in…
Travis Brown
  • 138,631
  • 12
  • 375
  • 680
35
votes
5 answers

Real World Functional Programming in Scala

Soooo... Semigroups, Monoids, Monads, Functors, Lenses, Catamorphisms, Anamorphisms, Arrows... These all sound good, and after an exercise or two (or ten), you can grasp their essence. And with Scalaz, you get them for free... However, in terms of…
31
votes
6 answers

How to combine Option values in Scala?

I want to be able to apply an operation f: (T,T) => T to Option[T] values in Scala. I want the result to be None if any of the two values is None. More specifically, I want to know if there is a shorter way to do the following: def opt_apply[T](f:…
Jeff
  • 953
  • 2
  • 11
  • 21
30
votes
5 answers

Convert a List of Options to an Option of List using Scalaz

I want to transform a List[Option[T]] into a Option[List[T]]. The signature type of the function is def lo2ol[T](lo: List[Option[T]]): Option[List[T]] The expected behavior is to map a list that contains only Somes into a Some containing a list of…
29
votes
2 answers

Why isn't Validation a Monad?

an example use case: def div2(i: Int): Validation[String, Int] = if (i%2 == 0) Validation.success(i/2) else Validation.failure("odd") def div4(i: Int) = for { a <- div2(i) b <- div2(a) } yield b error: Unable to unapply type…
Chris
  • 1,094
  • 1
  • 11
  • 26
28
votes
8 answers

Merge maps by key

Say I have two maps: val a = Map(1 -> "one", 2 -> "two", 3 -> "three") val b = Map(1 -> "un", 2 -> "deux", 3 -> "trois") I want to merge these maps by key, applying some function to collect the values (in this particular case I want to collect them…
Submonoid
  • 2,809
  • 2
  • 20
  • 25
27
votes
4 answers

What is a DList?

I tried googling for this but all I got were stories about minor celebrities. Given the lack of documentation, what is a DList?
oxbow_lakes
  • 133,303
  • 56
  • 317
  • 449
26
votes
1 answer

How to stack applicative functors in Scala

Applicative functors are often mentioned as an alternative to monads when your computation steps are independent. One of their often-mentioned advantages is that you don't need transformers when you want to stack applicatives, because F[G[X]] is…
kciesielski
  • 1,178
  • 9
  • 18
26
votes
1 answer

Threading extra state through a parser in Scala

I'll give you the tl;dr up front I'm trying to use the state monad transformer in Scalaz 7 to thread extra state through a parser, and I'm having trouble doing anything useful without writing a lot of t m a -> t m b versions of m a -> m b…
Travis Brown
  • 138,631
  • 12
  • 375
  • 680
25
votes
3 answers

Why does Scalaz use complex symbols and no in-code documentation?

I'm sometimes looking at Scalaz and find it pretty hard to understand for a beginner Scala programmer. implicit def KleisliCategory[M[_]: Monad]: Category[({type λ[α, β]=Kleisli[M, α, β]})#λ] = new Category[({type λ[α, β]=Kleisli[M, α, β]})#λ] { …
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
24
votes
1 answer

Why is List a Semigroup but Seq is not?

I'm fairly new to scalaz and I am trying to figure out why the following code works: import scalaz._ import Scalaz._ scala> Map[String,List[String]]() |+| Map[String,List[String]]() res3: scala.collection.immutable.Map[String,List[String]] =…
coltfred
  • 1,470
  • 9
  • 17
24
votes
4 answers

Finding my way through Scalaz

Possible Duplicate: Good scalaz introduction I would like to learn more about Scalaz, possibly using Scalaz7 to be avoid rewiring my brain once it is declared stable. My problem is that Scalaz contains a lot of functionality. While most of it is…
Andrea
  • 20,253
  • 23
  • 114
  • 183
23
votes
6 answers

Clojure's 'let' equivalent in Scala

Often I face following situation: suppose I have these three functions def firstFn: Int = ... def secondFn(b: Int): Long = ... def thirdFn(x: Int, y: Long, z: Long): Long = ... and I also have calculate function. My first approach can look like…
tenshi
  • 26,268
  • 8
  • 76
  • 90
23
votes
2 answers

Try[Result], IO[Result], Either[Error,Result], which should I use in the end

I'd like to know what should be the signature of my methods so that I handle different kind of failures elegantly. This question is somehow the summary of many questions I already had about error handling in Scala. You can find some questions…
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
22
votes
3 answers

What is a monad-transformer as distinct from a monad?

The question says it all, really. I know a (Scala) Monad looks like this: trait Monad[M[_]] { def pure[A](a : A) : M[A] def bind[A, B](ma : M[A], f : A => M[B]) : M[B] } What does a Monad Transformer look like? And what are they used…
oxbow_lakes
  • 133,303
  • 56
  • 317
  • 449
1
2
3
69 70