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
11
votes
3 answers

In Scala, is there a shorthand for reducing a generic type's arity?

I want to call Scalaz's pure method to put a value into the State monad. The following works: type IntState[A] = State[Int, A] val a = "a".pure[IntState] a(1) (Int, java.lang.String) = (1,a) I can also eliminate the type alias (thanks Scalaz's…
Daniel Yankowsky
  • 6,956
  • 1
  • 35
  • 39
11
votes
1 answer

Why must fmap map every element of a List?

Having read the book Learn you a Haskell For Great Good, and the very helpful wiki book article Haskell Category Theory which helped me overcome the common category mistake of confusing category objects with the programming objects, I still have the…
Henry Story
  • 2,116
  • 1
  • 17
  • 28
11
votes
1 answer

Why does Scalaz show up in my project's API docs?

Suppose my entire project configuration is this simple build.sbt: scalaVersion := "2.11.4" libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.1.0" And this is my code: import scalaz.Equal import scalaz.syntax.equal._ object Foo { def…
Travis Brown
  • 138,631
  • 12
  • 375
  • 680
11
votes
1 answer

How to handle `Reader` monad and `Try`?

I'm reading this great article about dependency injection in scala with Reader monad. The original example is working well, but I did a little bit change on the return types of the UserRepository.get/find. It was User, but I changed it to…
Freewind
  • 193,756
  • 157
  • 432
  • 708
11
votes
1 answer

Why do we need scalaz.stream over iteratee?

Recently, I've been playing with scalaz.iteratee and Play's iteratee. I think that iteratee is a great idea to provide modularity instead of the old imperative while loop -- the aim is to use a function as a handler of each new line instead of…
Xiaohe Dong
  • 4,953
  • 6
  • 24
  • 53
11
votes
1 answer

Shapeless: generic lens parameterized by case class or field

Based on: import shapeless._ case class Content(field: Int) lens[Content] >> 'field I am trying to make a lens-creating method, something along: def makeLens[T <: Product](s: Symbol) = lens[T] >> s But it seems non-obvious. Is it possible to…
ponythewhite
  • 617
  • 3
  • 8
11
votes
3 answers

Applicative vs. monadic combinators and the free monad in Scalaz

A couple of weeks ago Dragisa Krsmanovic asked a question here about how to use the free monad in Scalaz 7 to avoid stack overflows in this situation (I've adapted his code a bit): import scalaz._, Scalaz._ def setS(i: Int): State[List[Int], Unit]…
Travis Brown
  • 138,631
  • 12
  • 375
  • 680
11
votes
1 answer

stacking StateT in scalaz

I'm trying to understand Monad Transformers in Scala by porting some examples from this tutorial by Dan Piponi: http://blog.sigfpe.com/2006/05/grok-haskell-monad-transformers.html I did a couple of easy ones: import Control.Monad.State import…
arya
  • 946
  • 5
  • 14
11
votes
2 answers

Scala - compose function n times

I have a function that looks like this: def emulate: (Cpu => Cpu) => (Cpu => Cpu) = render => { handleOpcode andThen handleTimers andThen handleInput andThen debug andThen render } I want to call the handleOpcode function…
Dominic Bou-Samra
  • 14,799
  • 26
  • 100
  • 156
11
votes
2 answers

Monadic fold with State monad in constant space (heap and stack)?

Is it possible to perform a fold in the State monad in constant stack and heap space? Or is a different functional technique a better fit to my problem? The next sections describe the problem and a motivating use case. I'm using Scala, but solutions…
David B.
  • 5,700
  • 5
  • 31
  • 52
11
votes
1 answer

How to avoid stair-stepping with Monad Transformers in scala?

I have the following code that uses the Reader monad for configuration and also has to deal with IO[Option[String]] and I've ended up with code that stair-steps in my encode function. How can I formulate a monad transformer for Reader and OptionT to…
cwmyers
  • 183
  • 7
11
votes
1 answer

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

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…
Redattack34
  • 125
  • 4
10
votes
2 answers

Is there a built in way of converting Option to a scalaz validation?

I've been looking but I can't find an implicit converter. Obviously it would be trivial to write one but I'm wondering if I've missed one in the scalaz library somehow!
Noel Kennedy
  • 12,128
  • 3
  • 40
  • 57
10
votes
2 answers

Scalaz validation and ApplicativeBuilder limits

We're using scalaz validation trait in our project to validate HTTP parameters. The common case is taking few validated values and performing neccessary action only if all of them are valid, returning list of errors otherwise: (pavam1Val.liftFailNel…
Digal
  • 247
  • 2
  • 10
10
votes
2 answers

How to find the size of an object in scala?

Is there a way to find out the memory/size occupied by an object in scala? Thanks in advance for replying me.
Pratap D
  • 311
  • 3
  • 7
  • 14