• What are advantages of ApplicativeBuilder? 2018-02-12

    Applicative provides "operator" <*>, which I can use as follows: val f: (Int, Int) => Int = {(x, y) => x + y} 1.some <*> (2.some <*> f.curried.some) In addition to that scalaz provides ApplicativeBuilder: (1.some |@|

    Tags: scalaz, applicative
  • Recursively walk values in Map 2015-03-19

    I am attempting to walk a Map[String,List[String]] recursively to extract and flatten all values associated with a Map val x = Map("a" -> List("b","c","d"), "b" -> List("f","g","h"), "f" -> List("i","j","k"), "g" -> List("p","q","r")) For

    Tags: scala, scala collections, scalaz, scala 2.10
  • context bound of scalar.Coyoneda.liftTF 2015-01-26

    Finished watching thought-provoking video "Composable application architecture with reasonably priced monads" from RĂșnar Bjarnason, I started to write the examples provided in the video in Scalaz. I am having a little surprise when implementing the w

    Tags: monads, scala, scalaz, writer monad
  • What should I import for Scalaz' traverse functionalities 2014-12-18

    In every examples I read about Scalaz' traverse features, the following imports were done: import scalaz._ import Scalaz._ It seems I can't use traverseU until I import Scalaz._. How does Scalaz object inject traverseU to my collections? I'm complete

    Tags: scala, scalaz
  • Semigroup-like thing where the append operation can fail 2014-06-28

    Suppose I have some type with an associative binary operation that feels a lot like append except that the operation may fail. For example, here's a wrapper for List[Int] that only allows us to "add" lists with the same length: case class Foo(xs: Lis

    Tags: scala, scalaz
  • Use Scalaz >> and >>= in the same expression 2014-04-01

    In Haskell I use often >>= and >> to compose monadic actions. For example: > Just 1 >>= Just . (+1) >> Just () Just () In Scala there is only flatMap, so I decided to use Scalaz >>= and >>. The problem is that I

    Tags: monads, scala, scalaz
  • How to avoid a stack overflow with State monad 2013-12-03

    I encountered a stack overflow using scalaz State Monad. Here is the culprit iterator.toList.traverseS_(collectOne). the iterator contains a lot of elements (10M) Q1 : iterator.toList force the evaluation, that I want avoid. But I need a list to call

    Tags: scala, scalaz
  • Correct usage of scalaz Future for async execution 2013-10-02

    I guess i don't fully understand how scalaz Futures works. I'm trying to port one project from scala futures to scalaz implementation, but the problem is that performance with scalaz Future is lower. The simplest example is loading a profile on authe

    Tags: asynchronous, scala, future, scalaz, spray
  • Iteratee input from Standard IO 2013-08-18

    I'm using scalaz 6.0 with scala. I'm using iteratees to read from an input stream. Here's the simple file called simple.txt I have. This Is A test My iteratee will build up an io monad to print the lines def printLines: IterV[String, IO[Unit]] = { de

    Tags: scala, stdio, iteratee, scalaz
  • Avoiding repetition using lenses whilst deep-copying into Map values 2012-04-20

    I have an immutable data structure where I have nested values in Maps, like so: case class TradingDay(syms: Map[String, SymDay] = Map.empty) case class SymDay(sym: String, traders: Map[String, TraderSymDay] = Map.empty) case class TraderSymDay(trader

    Tags: scala, scalaz, lenses
  • how to translate Haskell into Scalaz? 2012-03-30

    One of my high school students and I are going to try to do a port of Haskell's Parsec parser combinator library into Scala. (It has the advantage over Scala's built-in parsing library that you can pass state around fairly easily because all the pars

    Tags: haskell, scala, functor, scalaz
  • Scalaz : validating in a for-comprehension and logging 2012-03-27

    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 (e

    Tags: logging, validation, scalaz
  • Group values by a key with any Monoid 2012-03-15

    I would like to write a method mergeKeys that groups the values in an Iterable[(K, V)] by the keys. For example, I could write: def mergeKeysList[K, V](iter: Iterable[(K, V)]) = { iter.foldLeft(Map[K, List[V]]().withDefaultValue(List.empty[V])) { cas

    Tags: monads, scala, scalaz, monoids
  • Compose Scalaz validations 2012-02-24

    I would like to use Scalaz for validations and like to be able to reuse the validation functions in different contexts. I'm totally new to Scalaz btw. Let's say I have these simple checks: def checkDefined(xs: Option[String]): Validation[String, Stri

    Tags: scala, scalaz
  • How to compose function to applicatives with scalaz 2012-02-23

    While learning Scalaz 6, I'm trying to write type-safe readers returning validations. Here are my new types: type ValidReader[S,X] = (S) => Validation[NonEmptyList[String],X] type MapReader[X] = ValidReader[Map[String,String],X] and I have two fun

    Tags: validation, scala, scalaz, applicative
  • Scalaz iteratee, create Enumerator for BufferedReader 2012-02-22

    How is it possible to create Enumerator for BufferedReader? I found rather old article: and it looks like it doesn't work with Scalaz 6.0.4 I try to create

    Tags: scala, scalaz
  • Scalaz Validation: aggregate errors or return any success 2012-02-08

    How is it possible to implement with scalaz such behaviour: "Fail1".failNel[Int] and "Fail2".failNel[Int] to Failure("Fail1", "Fail2") "Fail1".failNel[Int] and 100.successNel[String] to Success(100) My solution looks to complicated and I guess exists

    Tags: scala, scalaz
  • Using scalaz state in a more complicated computation 2012-02-08

    I'm trying to understand how to use scalaz State to perform a complicated stateful computation. Here is the problem: Given a List[Int] of potential divisors and a List[Int] of numbers, find a List[(Int, Int)] of matching pairs (divisor, number) where

    Tags: functional programming, scala, scalaz
  • Combining the elements of 2 lists 2012-02-06

    Assume we have two lists : val l1=List("a","b","c") val l2 = List("1","2","3") What I want is : List("a1", "b2", "c3") that is, adding the nth element of l1 with the nth element of l2 A way to achieve it is : (l1 zip l2).map (c => {c._1+c._2}) I j

    Tags: scala, scalaz, applicative
  • Scalaz Validation, validate inner value 2012-02-06

    I have a Validation object val v = Validation[String, Option[Int]] I need to make a second validation, to check if actual Integer value is equals to 100 for example. If I do val vv = => if (intValue == 100) intValue.success[St

    Tags: validation, scala, scalaz

Copyright (C), All Rights Reserved.

processed in 4.810 (s). 9 q(s)