scalaz7

Map and reduce/fold over HList of scalaz.Validation

独自空忆成欢 提交于 2019-12-03 07:30:40
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 |> nonEmpty[String]("no postal" )).toValidationNel |@| (country |> nonEmpty[String]("no country")).toValidationNel params { (postal, country) => ... } Now I thought it would be nice to reduce the boilerplate for better readability and for not having to explain to more junior team members what .toValidateNel and |@| mean. The first thought was List but then

Scalaz Functor typeclass special symbols

落花浮王杯 提交于 2019-12-01 11:13:04
Recently I have come across this Scalaz code (e.g. https://github.com/scalaz/scalaz/blob/series/7.2.x/core/src/main/scala/scalaz/Functor.scala ): def compose[G[_]](implicit G0: Functor[G]): Functor[λ[α => F[G[α]]]] = new CompositionFunctor[F, G] { implicit def F = self implicit def G = G0 } What is the meaning/purpose of the type expression inside the "Functor", i.e. λ[α => F[G[α]]]? Sofar, I have seen just type aliases like e.g. in http://like-a-boss.net/2014/09/27/type-lambda-in-scala.html new Functor[A, ({ type Alias[A] = Tuple2[X, A]})#Alias] Also, Intellij Idea (14.0.3) cannot resolve the

Scalaz Validation with applicative functor |@| not working

℡╲_俬逩灬. 提交于 2019-11-29 21:21:23
问题 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: ClassTag](instance: A, fieldNames: Option[Seq[String]] = None): ValidationResult = { val fields = classTag[A].runtimeClass.getDeclaredFields val fieldSubset = fieldNames match { case Some(names) => fields.filter { field => names.contains(field.getName) } case None =

Finding my way through Scalaz [duplicate]

喜欢而已 提交于 2019-11-29 20:11:49
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 meant to be independent of other parts, I would like to have a bird's eye view of the global funcitonality offered by Scalaz and how it is organized. As far as I know, Scalaz offers, among other things, Functor , Applicative and Monad traits, new monads such as Validation (edit: turns out it is only an applicative) monad transformers ( OptionT ,

How to use IO with Scalaz7 Iteratees without overflowing the stack?

倾然丶 夕夏残阳落幕 提交于 2019-11-29 12:34:08
问题 Consider this code (taken from here and modified to use bytes rather than lines of characters). import java.io.{ File, InputStream, BufferedInputStream, FileInputStream } import scalaz._, Scalaz._, effect._, iteratee.{ Iteratee => I, _ } import std.list._ object IterateeIOExample { type ErrorOr[+A] = EitherT[IO, Throwable, A] def openStream(f: File) = IO(new BufferedInputStream(new FileInputStream(f))) def readByte(s: InputStream) = IO(Some(s.read()).filter(_ != -1)) def closeStream(s:

Managing imports in Scalaz7

放肆的年华 提交于 2019-11-29 06:12:44
I am using scalaz7 in a project and sometimes I run into issues with imports. The simplest way get started is import scalaz._ import Scalaz._ but sometimes this can lead to conflicts. What I have been doing until now the following slightly painful process: work out a minimal example that needs the same imports as my actual code copy that example in a separate project compile it with the option -Xprint:typer to find out how the code looks after implicit resolution import the needed implicits in the original project. Although this works, I would like to streamline it. I see that scalaz7 has much

Finding my way through Scalaz [duplicate]

ぃ、小莉子 提交于 2019-11-28 16:01:17
问题 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 meant to be independent of other parts, I would like to have a bird's eye view of the global funcitonality offered by Scalaz and how it is organized. As far as I know, Scalaz offers, among other things, Functor , Applicative and Monad traits, new

Why is List a Semigroup but Seq is not?

余生长醉 提交于 2019-11-27 20:29:30
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]] = Map() but this doesn't... import scalaz._ import Scalaz._ scala> Map[String,Seq[String]]() |+| Map[String,Seq[String]]() <console>:14: error: value |+| is not a member of scala.collection.immutable.Map[String,Seq[String]] Map[String,Seq[String]]() |+| Map[String,Seq[String]]() I see the Map implicit for Semigroup, but I don't see the one for List or Seq.

why isn't Validation a Monad? (scalaz7)

南笙酒味 提交于 2019-11-27 19:04:02
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 scalaz.Validation[String,Int] into a type constructor of kind M[_] that is classified by the type class scalaz.Bind I guess the error is caused by the compiler can't find a Monad instance for Validation[String, Int] I can make one for myself, like: object Instances { implicit def validationMonad[E] = new Monad[({type L[A] = Validation[E, A]})#L] { override def point[A](a:

why isn't Validation a Monad? (scalaz7)

蹲街弑〆低调 提交于 2019-11-26 22:45:35
问题 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 scalaz.Validation[String,Int] into a type constructor of kind M[_] that is classified by the type class scalaz.Bind I guess the error is caused by the compiler can't find a Monad instance for Validation[String, Int] I can make one for myself, like: object Instances {