Scalaz provides type classes and purely functional data structures for Scala
Questions tagged [scalaz7]
102 questions
8
votes
1 answer
Set sequencing type puzzle
Last night in responding to this question, I noticed the following:
scala> val foo: Option[Set[Int]] = Some(Set(1, 2, 3))
foo: Option[Set[Int]] = Some(Set(1, 2, 3))
scala> import scalaz._, Scalaz._
import scalaz._
import Scalaz._
scala>…

Travis Brown
- 138,631
- 12
- 375
- 680
8
votes
3 answers
How to split F[A \/ B] into (F[A], F[B])
I occasionally hit code like this:
val things : List[A \/ B] = ???
val (as, bs) : (List[A], List[B]) = ??? //insert something to do this
or in my current case I want Map[A, B \/ C] => (Map[A, B], Map[A, C])
Is there a nice way to do this in the…

AlecZorab
- 672
- 1
- 5
- 14
7
votes
1 answer
State transformations with a shapeless State monad
Scalaz State monad's modify has the following signature:
def modify[S](f: S => S): State[S, Unit]
This allows the state to be replaced by state of the same type, which does not work well when the state includes a shapeless value such as a Record…

Sim
- 13,147
- 9
- 66
- 95
7
votes
1 answer
Map and reduce/fold over HList of scalaz.Validation
I started out with something like this:
def nonEmpty[A] = (msg: String) => (a: Option[A]) => a.toSuccess(msg)
val postal: Option[String] = request.param("postal")
val country: Option[String] = request.param("country")
val params =
(postal |>…

Erik Kaplun
- 37,128
- 15
- 99
- 111
7
votes
1 answer
Scalaz: how to compose a map lens with a value lens?
There's an example of a Scalaz map lens here: Dan Burton calls it containsKey, and it's inspired by the Edward Kmett talk. There is also something called mapVPLens in Scalaz 7 which is useful for modifying values in a map.
My question is: if I have…

James McCabe
- 1,879
- 2
- 15
- 22
7
votes
1 answer
Why does scalaz's implementation of Monoid for Option evaluate the f2 function twice?
The definition of the scalaz's option monoid is as follows:
implicit def optionMonoid[A: Semigroup]: Monoid[Option[A]] = new Monoid[Option[A]] {
def append(f1: Option[A], f2: => Option[A]) = (f1, f2) match {
case (Some(a1), Some(a2)) =>…

coltfred
- 1,470
- 9
- 17
7
votes
1 answer
Scalaz - combining List and State Monad in for comprehension
I am planning to start using Monadic style in my Scala code for, amongst others, threading state. Here's a simplified example of combining 3 monadic functions (and caring only about the side effects)
import scalaz._
import Scalaz._
object MonadTest…

nietaki
- 8,758
- 2
- 45
- 56
7
votes
2 answers
Combining validations with scalaz 7
Given the following functions:
def foo( a: A ): ValidationNEL[String,Seq[B]] = ...
def bar( b: B ): ValidationNEL[String,C] = ...
I would like to combine them such as to build a function, which calls foo then eventually calls bar on each elements…

paradigmatic
- 40,153
- 18
- 88
- 147
6
votes
0 answers
Switching between EitherT and Validation to accumulate error or traverse
Say I have the following function:
def getRemoteThingy(id: Id): EitherT[Future, NonEmptyList[Error], Thingy]
Given a List[Id], I can easily easily retrieve a List[Thingy] by using Traverse[List]:
val thingies: EitherT[Future, NonEmptyList[Error],…

blouerat
- 692
- 4
- 12
6
votes
1 answer
Logging and ignoring exception from Task in scalaz-streams
Let's take an example from some scalaz-stream docs, but with a theoretical twist.
import scalaz.stream._
import scalaz.concurrent.Task
val converter: Task[Unit] =
io.linesR("testdata/fahrenheit.txt")
.filter(s => !s.trim.isEmpty &&…

kareblak
- 412
- 1
- 3
- 12
6
votes
2 answers
How to use playframework 2.3 with specs2 2.4 instead of specs2 2.3.x
Recently, specs2 was updated to version 2.4, which uses scalaz 7.1 instead of 7.0.x now. Once I update my specs2 dependency in my play! 2.3 project to use version 2.4, all tests fail with the following exception:
[error] Uncaught exception when…

ingenue
- 118
- 2
- 6
6
votes
1 answer
Scalaz Validation with applicative functor |@| not working
I'm trying to use Scalaz 7 Validation in my app. However, I'm having an issue getting the |@| applicative functor to coalesce my failures. Here's the code I have:
type ValidationResult = ValidationNel[String, Unit]
def validate[A:…

cdmckay
- 31,832
- 25
- 83
- 114
6
votes
1 answer
How to I convert between monad stacks with transformers in scalaz 7
I'm struggling with understanding monad stacks and monad transformers with Scalaz7. I feel I'm pretty close to the answer but just can't get my head around a particular step.
The following code looks on disk for an ffmpeg binary, then creates an…

cwmyers
- 183
- 7
6
votes
1 answer
Best way to handle object's fields validation => Either / Try (scala 2.10) / ValidationNEL (scalaz)
Let's assume an object constructed using a builder pattern.
This builder pattern would contain a build method focusing on fields validation and then on conversion to the targeted type.
This validation could be implemented…

Mik378
- 21,881
- 15
- 82
- 180
5
votes
2 answers
Missing Functor and Monad instances when using scala.concurrent.Future with EitherT
I'm trying to use Scalaz EitherT with a scala.concurrent.Future. When trying to use it in a for-comprehension:
import scalaz._
import Scalaz._
val et1:EitherT[Future, String, Int] = EitherT(Future.successful(1.right))
val et2:EitherT[Future,…

ssanj
- 2,169
- 3
- 19
- 28