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
10
votes
13 answers

Scala functional programming gymnastics

I am trying to do the following in as little code as possible and as functionally as possible: def restrict(floor : Option[Double], cap : Option[Double], amt : Double) : Double Obviously the following works: = (floor -> cap) match { case…
oxbow_lakes
  • 133,303
  • 56
  • 317
  • 449
10
votes
1 answer

Scala: question marks in type parameters

I'm trying to understand the following piece of code (from the Scalaz library): def kleisliIdApplicative[R]: Applicative[Kleisli[Id, R, ?]] = ... I'm assuming that a type of the form T[P0, ?] is a type-constructor that takes a parameter. However…
Damian Nadales
  • 4,907
  • 1
  • 21
  • 34
10
votes
2 answers

The object-functional impedance mismatch

In OOP it is good practice to talk to interfaces not to implementations. So, e.g., you write something like this (by Seq I mean scala.collection.immutable.Seq :)): // talk to the interface - good OOP practice doSomething[A](xs: Seq[A]) = ??? not…
lambdista
  • 1,850
  • 9
  • 16
10
votes
1 answer

What's the difference between Task and IO in Scalaz?

These two Scalaz types scalaz.concurrent.Task[+A] scalaz.effect.IO[A] seem very conceptually similar. They both: Represent a potentially side-effecting computation Produce a success (A) or failure (Exception) result Have Monad instances Can be…
Chris Martin
  • 30,334
  • 10
  • 78
  • 137
10
votes
5 answers

Already existing functional way for a retry-until in Scala?

Is there a functional/Scala way to call a function repeatedly until it succeeds, while reacting to failed attempts? Let me illustrate with an example. Suppose I want to read an integer from standard-in, and retry if the user did not in fact enter an…
Sebastian N.
  • 1,962
  • 15
  • 26
10
votes
1 answer

How do I get the scalaz IDEA live templates working for the symbolic methods?

Many of the methods in scalaz have symbolic unicode equivalents, such as forever and ∞ (of course, I have this the wrong way round, the symbolic methods really have ASCII equivalents). The project contains a live templates XML file for IDEA so these…
oxbow_lakes
  • 133,303
  • 56
  • 317
  • 449
10
votes
1 answer

How to use Scalaz 7's EitherT with liftM

If I have a monad transformer type taking two type arguments, I can use liftM to lift values into the transformed monad: scala> val o = 1.point[List].liftM[OptionT] o: scalaz.OptionT[List,Int] = OptionT(List(Some(1))) However if I try the same…
Hugh
  • 8,872
  • 2
  • 37
  • 42
10
votes
2 answers

Scalaz Lens Composition

Really simple question here. After watching an excellent introduction to lenses: http://www.youtube.com/watch?v=efv0SQNde5Q I thought I might attempt one of the simple examples covered in the talk: import…
10
votes
1 answer

Flattening Nested Scalaz Validations

I'm fairly new to scalaz and I've started out with validations. I have some validation functions of the form: def validateXyz(...): ValidationNEL[String, String] = ... I'm then using the applicative style to combine multiple validations and then…
Chris Turner
  • 400
  • 1
  • 7
9
votes
1 answer

Scalaz : validating in a for-comprehension and logging

I admit that the title is not very explicit : sorry for that. Assume I have a for-comprehension : for {v1<-Validation1(input) v2<-Validation2(v1) v3<-Validation3(v2) } yield result Validation1, Validation2 and Validation3 do some checking…
bhericher
  • 667
  • 4
  • 13
9
votes
6 answers

Summing a List of Options with Applicative Functors

I have a List[Option[Int]] and want to sum over it using applicative functors. From [1] I understand that it should be something like the following import scalaz._ import Scalaz._ List(1,2,3).map(some(_)).foldLeft(some(0))({ case (acc,value) =>…
Manuel Schmidt
  • 2,429
  • 1
  • 19
  • 32
9
votes
2 answers

Writing type class instances for nested classes in Scala

In this recent Stack Overflow question, the author wanted to change a list of parsers of some type into a parser that returns lists of that type. We can imagine doing this with Scalaz's sequence for applicative functors: import…
Travis Brown
  • 138,631
  • 12
  • 375
  • 680
9
votes
1 answer

Use Unapply to extract identical type classes

I have the following situation, given two types MA and MB, I would like to be able to prove that they both not only have an Applicative but also that they both have the same underlying shape. I tried doing the following: type UnapplyM[TC[_[_]], MA,…
wheaties
  • 35,646
  • 15
  • 94
  • 131
9
votes
2 answers

Can I automatically implement classes?

In Scalaz every Monad instance is automatically an instance of Applicative. implicit val listInstance = new Monad[List] { def point[A](a: => A) = List(a) def bind[A, B](fa: List[A])(f: A => List[B]) = fa flatMap f } List(2) <*> List((x: Int)…
ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155
9
votes
1 answer

What are Tower[A] and IvoryTower in Scalaz?

When I looked at scalaz.effect.IO source code, I noticed that it has a method apply with the following signature: sealed trait IO[A] { def apply(rw: Tower[IvoryTower]): Trampoline[(Tower[IvoryTower], A)] } Tower[A] and IvoryTower are defined…
ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155