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
0
votes
2 answers

Working with Streams wrapped in Options

I am working with some nested Streams and would like to use the for comprehension syntax with them: def handleNestedStream(as : Stream[A]) : Stream[(A, B)] = { a <- as b <- makeBs(a) } yield (a, b) However, the makeBs function returns an…
mushroom
  • 6,201
  • 5
  • 36
  • 63
0
votes
1 answer

Where are the common typeclasses instances in scalaz?

I'm trying to understand how scalaz is organized, and I would like to know where the common monad (or other typeclasses) instances like Monad[Int], Monad[List] ... are defined. Take for example the Monad[List]. I saw that the scalaz.std module…
Guillaume Chérel
  • 1,478
  • 8
  • 17
0
votes
1 answer

Convert a monadic function to return point in another monad

let's suppose I have two monads F and M (Scalaz-style) and a function f: A => F[B]. I'd like to create a function g: A => F[M[B]] that applies f first then binds F monad with pure[M]. An example for clarity's sake: // here, F = Option and M =…
Wojciech Ptak
  • 683
  • 4
  • 14
0
votes
1 answer

Scalaz Writer Monad and filterM

I am working my way through learning scalaz and Learn You A Haskell For Greater Good and wonder how to translate the filterM example from LYAHFGG to Scala. fst $ runWriter $ filterM keepSmall [9,1,5,2,10,3] with keepSmall defined as keepSmall :: Int…
mjaskowski
  • 1,479
  • 1
  • 12
  • 16
0
votes
1 answer

Apply a Channel N times from an initial value

I have a function f and a channel c def f(i: Int) = Task.now(i + 1) val c = channel.lift(f) I would like to continuously apply the function f an arbitrary number of times (or indefinitely) to the output of the previous computation. I'm providing…
synapski
  • 323
  • 2
  • 12
0
votes
2 answers

How to define an implicit converter to a Monad?

I'm defining a trait which has an abstract type B which I want to use as a monad. To specify that B must be able to act as a monad, I declare an implicit monadB: trait A { type B[_] implicit def monadB: Monad[B] } Then, when I implement this…
Guillaume Chérel
  • 1,478
  • 8
  • 17
0
votes
1 answer

Create a OptionT[Future, A] from a lower-kinded type

I'm pretty new to scalaz, and I'm trying to figure out to convert various types to monad transformers. I'm stuck on trying to convert a Int to a OptionT[Future, Int], or even to EitherT[Future, String, Int]. I found a bunch of tutorials/SO answers…
dcastro
  • 66,540
  • 21
  • 145
  • 155
0
votes
1 answer

How does addition function parameters appeared in scala?

I am reading example about monad transformers in scalaz. Here is a piece of code: scala> def myName(step: String): Reader[String, String] = Reader {step + ", I am " + _} myName: (step: String)scalaz.Reader[String,String] scala> def localExample:…
Cherry
  • 31,309
  • 66
  • 224
  • 364
0
votes
1 answer

Type class implementation for hierarchy

I am studying Scala and trying to implement some abstractions for custom types. Defining scalaz monoids for concrete classes is quite straightforward. But how to declare one Monoid for the type hierarchy? Assuming this code: sealed trait Base case…
skapral
  • 1,128
  • 9
  • 26
0
votes
2 answers

How can I functionally iterate over a collection combining elements?

I have a sequence of values of type A that I want to transform to a sequence of type B. Some of the elements with type A can be converted to a B, however some other elements need to be combined with the immediately previous element to produce a B. I…
user180940
  • 324
  • 1
  • 18
0
votes
1 answer

pattern for composing functions

Following are a set of fictitious case classes. In reality we have got similar ADTs. case class Alphabet(a:Character) case class Word(alphabets: List[Alphabet]) case class Sentence(words : List[Word]) case class Paragraph(sentences :…
Vikas Pandya
  • 1,998
  • 1
  • 15
  • 32
0
votes
0 answers

Memory efficient stream traversal using the scalaz Traverse typeclass

I'm trying to traverse/sequence a large stream (e.g. scala.collection.immutable.Stream) using Scalaz' (version 7.1.2) Traverse typeclass, but I'm constantly running into a java.lang.OutOfMemoryError: GC overhead limit exceeded issue. My traversal…
Martin Studer
  • 2,213
  • 1
  • 18
  • 23
0
votes
1 answer

Scala implicit natural transform with monad failing to find functions for for comprehension

The code I have is this: class SourceService[Out[+_]](implicit monad:Monad[Out]) { def doSomething:Out[String] = monad.point("Result") } class SimplifiedPipe[Out[+_], In[+_]] (myService:SourceService[In]) (implicit monad:Monad[Out], pipe:…
J Pullar
  • 1,915
  • 2
  • 18
  • 30
0
votes
0 answers

Haskell Equality - Variance?

learning Scalaz shows how to make an Algebraic Data Type in Haskell and scalaz: data TrafficLight = Red | Yellow | Green deriving Eq and sealed trait TrafficLight case object Red extends TrafficLight case object Yellow extends TrafficLight case…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
0
votes
0 answers

Scalaz ValidationNel: traverse is not a member of List

Playing with Scalaz ValidationNel, I am trying to transform a List[ValidationNel[String, MyType]] to ValidationNel[String, List[MyType]] My code: import scalaz._ import scalaz.syntax.traverse._ import scalaz.std.list._ import Scalaz._ val ns:…
Jean Logeart
  • 52,687
  • 11
  • 83
  • 118