scalaz

Convert scala 2.10 future to scalaz.concurrent.Future // Task

一世执手 提交于 2019-12-31 10:42:33
问题 did anybody come to piece of code how to properly convert scala's Future (2.10) to new scalaz7 future ? I know hot to convert scalaz future via scala Promise to scala Future, but not sure how to do it properly around For example import scalaz.concurrent.{Future => Zuture} import scala.concurrent.Future I want to have implementation of implicit def scalaF2scalazF[A](in:Future[A]):Zuture[A]=??? Then obviously would be piece of cake to write implicit def scalaF2scalazTask[A](in:Future[A]):Task[A

Using Scalaz Stream for parsing task (replacing Scalaz Iteratees)

房东的猫 提交于 2019-12-29 10:09:03
问题 Introduction I use Scalaz 7's iteratees in a number of projects, primarily for processing large-ish files. I'd like to start switching to Scalaz streams, which are designed to replace the iteratee package (which frankly is missing a lot of pieces and is kind of a pain to use). Streams are based on machines (another variation on the iteratee idea), which have also been implemented in Haskell. I've used the Haskell machines library a bit, but the relationship between machines and streams isn't

Using Scalaz Stream for parsing task (replacing Scalaz Iteratees)

允我心安 提交于 2019-12-29 10:08:33
问题 Introduction I use Scalaz 7's iteratees in a number of projects, primarily for processing large-ish files. I'd like to start switching to Scalaz streams, which are designed to replace the iteratee package (which frankly is missing a lot of pieces and is kind of a pain to use). Streams are based on machines (another variation on the iteratee idea), which have also been implemented in Haskell. I've used the Haskell machines library a bit, but the relationship between machines and streams isn't

Implicit parameter resolution given multiple type parameters

五迷三道 提交于 2019-12-24 13:06:04
问题 I'm using a type class that requires its types A to have instances of Scalaz's Order[A] . In my use case, A is a Java class--in particular Joda Time's LocalDate . This class has a natural ordering as it implements Comparable . I couldn't find an Order instance for Comparable s in Scalaz itself, so I tried writing one myself: implicit def comparableOrder[A, B] (implicit ev0: <:<[A, B], ev1: <:<[A, Comparable[B]]): Order[A] = new Order[A] { override def order(x: A, y: A): Ordering = Ordering

Why awakeEvery was removed from scalaz-stream

一世执手 提交于 2019-12-24 12:44:05
问题 I found that there is no more awakeEvery inside scalaz.stream.Process in modern scalaz-stream. How to run something with period then? 回答1: It was moved to the scalaz.stream.time package: import scalaz.stream._ scala> implicit val sc = new java.util.concurrent.ScheduledThreadPoolExecutor(1) sc: java.util.concurrent.ScheduledThreadPoolExecutor = java.util.concurrent.ScheduledThreadPoolExecutor@6b9013a5[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0] scala>

Trampolining scalaz' Monad.whileM_ to prevent stack overflow

假装没事ソ 提交于 2019-12-24 11:25:58
问题 I'm using scalaz' Monad.whileM_ to implement a while loop in a functional way as follows: object Main { import scalaz._ import Scalaz._ import scala.language.higherKinds case class IState(s: Int) type IStateT[A] = StateT[Id, IState, A] type MTransT[S[_], A] = EitherT[S, String, A] type MTrans[A] = MTransT[IStateT, A] def eval(k: Int): MTrans[Int] = { for { state <- get[IState].liftM[MTransT] _ <- put(state.copy(s = (state.s + 1) % k)).liftM[MTransT] } yield (k + 1) } def evalCond(): MTrans

Scalaz nested Validation: could not find implicit value

喜欢而已 提交于 2019-12-24 05:41:25
问题 Playing with Scalaz ValidationNel, I have the following nested Validations that I am trying to flatten: import scala.xml.{NodeSeq, Node, Elem} import scalaz._ import Scalaz._ val duration: ValidationNel[String, Int] = // ... val nodes: ValidationNel[String, NodeSeq] = // ... val r: ValidationNel[String, List[MyType]] = (duration |@| nodes) { (d, ns) => val n: ValidationNel[String, List[MyType]] = ns.toList.traverse[({ type l[X] = ValidationNel[String, X] })#l, MyType](extractMyType(_, d)) n }

How to use Scalaz's traverse and traverseU with Either

╄→尐↘猪︶ㄣ 提交于 2019-12-24 05:32:10
问题 Is it possible to use Scalaz' traverse and traverseU with Either instead of Option ? For the following code: val list = List(1, 2, 3) def f(i: Int): Either[Int, String] = if (i > 2) Left(i) else Right("must be lower than 3") I want to traverse list with f and either return the first Right(msg) if there is one or more failure, or Left(list) if everything went right. 回答1: Is there any reason why you're not using Validation and NonEmptyList by scalaz? You can easily do something like def f(i:

Composing functions that return an option

六眼飞鱼酱① 提交于 2019-12-24 04:26:11
问题 Suppose I have a few functions of type Int => Option[Int] : def foo(n: Int): Int => Option[Int] = {x => if (x == n) none else x.some} val f0 = foo(0) val f1 = foo(1) I can compose them with >=> as follows: val composed: Int => Option[Int] = Kleisli(f0) >=> Kleisli(f1) Suppose now I need to compose all functions from a list: val fs: List[Int => Option[Int]] = List(0, 1, 2).map(n => foo(n)) I can do it with map and reduce : val composed: Int => Option[Int] = fs.map(f => Kleisli(f)).reduce(_ >=>

How can scalaz' Functor be given a higher-kinded type with a context bound?

◇◆丶佛笑我妖孽 提交于 2019-12-23 13:24:45
问题 I want to define a Functor instances for the following classes: class RequiresManifest[A: Manifest] { def value: A } class RequiresAnyRef[A <: AnyRef] { def value: A } class RequiresBothManifestAndAnyRef[A <: AnyRef: Manifest] { def value: A } Is this possible ? Alternatively can a 'BoundedFunctor trait be defined ? something like this: trait BoundedFunctor[F[_], Bound[_]] { def fmap[A: Bound, B: Bound](r: F[A], f: A => B): F[B] } Here's my motivating example: How can I defined a Functor for