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

Can I transform this asynchronous java network API into a monadic representation (or something else idiomatic)?

I've been given a java api for connecting to and communicating over a proprietary bus using a callback based style. I'm currently implementing a proof-of-concept application in scala, and I'm trying to work out how I might produce a slightly more…
AlecZorab
  • 672
  • 1
  • 5
  • 14
9
votes
3 answers

Scala: Try till first success on a list

What is the idiomatic way of applying a function A => Try[B] on a List[A] and return either the first succesful result Some[B] (it short-circuits) or if everything fails, returns None I want to do something like this: val inputs: List[String] =…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
9
votes
1 answer

|+| is a semigroup, why it needs a monoid implicit resolution

The aim of Semigroup is to make sure Associativity and closure The aim of monoid is based on Semigroup and provide additional Identity. When I use |+| semigroup appender, why I have define implicit monoid not implicit semigroup Here is the code I am…
Xiaohe Dong
  • 4,953
  • 6
  • 24
  • 53
9
votes
3 answers

Insert character in Scala String

For any given String, for instance val s = "abde" how to insert a character c: Char at position 2, after b ? Update Which Scala collection to consider for multiple efficient insertions and deletions at random positions ? (Assuming that a String…
elm
  • 20,117
  • 14
  • 67
  • 113
9
votes
2 answers

Scala infix type aliasing for >2 type parameters?

I know in Scala, you can do type ===>[A, B] = Map[A, B] and then you can use infix notation to define def foo: String ===> Int which is same as saying def foo: Map[String, Int]. Is there any way to exploit this infix notation to create types with >2…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
9
votes
1 answer

How to chain Future[\/[A,B]] in scala?

How I can do a for comprehension with the data of type Future[\/[String,Int]] Here is a starting point, which doesn't compile. import scala.concurrent.{ExecutionContext,future,Future} import scalaz._ import Scalaz._ import…
Johnny Everson
  • 8,343
  • 7
  • 39
  • 75
9
votes
1 answer

How to use >=> in Scala?

I am trying to use >=> (Kleisli arrow) in Scala. As I understand, it composes functions returning monads. Now I am trying it as follows: scala> val f = {i:Int => Some(i + 1)} f: Int => Some[Int] = scala> val g = {i:Int =>…
Michael
  • 41,026
  • 70
  • 193
  • 341
9
votes
2 answers

How to implement the `List` monad transformer in Scala?

I have a monad that is very similar to a collection monad. I'm currently trying to implement a monad transformer for it, but I'm failing. I've looked at the ListT implementation in Scalaz 6 and 7, but I cannot understand how it works. It uses some…
ziggystar
  • 28,410
  • 9
  • 72
  • 124
9
votes
2 answers

How to return a tuple inside an EitherT

I'm using Scalaz 7's EitherT to construct for-comprehensions that blend State and \/. So far so good; I get something that's basically: State[MyStateType, MyLeftType \/ MyRightType] and that allows me to build for-comprehensions that have nice…
James Moore
  • 8,636
  • 5
  • 71
  • 90
9
votes
1 answer

how does work scalaz.Validation loopSuccess and loopFailure

Could someone explain with real world examples how does work below methods of scalaz.Validation? I mean loopSuccess and loopFailure. Snippetes from source code (scalaz7): scalaz.Validation: /** Spin in tail-position on the success value of this…
pawel.panasewicz
  • 1,831
  • 16
  • 27
9
votes
1 answer

Applicative instance for a tuple with monoid and function inside

I was trying to convert a haskell example, I came across earlier, to scalaz. The original example was this: ("Answer to the ", (*)) <*> ("Ultimate Question of ", 6) <*> ("Life, the Universe, and Everything", 7) Which, as far as I am able to…
George
  • 8,368
  • 12
  • 65
  • 106
9
votes
2 answers

Where are the implicit Monoid[Int] etc. implemented

i try to learn/understand a little bit of scalaz. For that i started with the example: List(3, 4, 5).asMA.foldMap(x => x) => 12 //(3+4+5) def foldMap[B](f: A => B)(implicit r: Foldable[M], m: Monoid[B]) So somewhere has to be an…
Fabian
  • 1,224
  • 1
  • 11
  • 26
8
votes
2 answers

Is there a more idiomatic way of getting IO[Option[A]] from Option[IO[Option[A]] then using sequence and mapping join?

I'm running into quite a few places where I have something akin to def f(s: String): Option[Long] = ... def g(l: Long): IO[Option[Wibble]] = ... val a: IO[Option[Wibble]] = f(param).flatMap(g).sequence.map(_.join) Seeing the .sequence.map(_.join)…
rwallace
  • 127
  • 4
8
votes
1 answer

Composable using scalaz Arrow?

I have two functions. def process(date: DateTime, invoice: Invoice, user: User, reference: Reference) : (Action, Iterable[Billable]) def applyDiscount(billable: Billable) : Billable How can I compose these so that I have a single function of…
Travis Stevens
  • 2,198
  • 2
  • 17
  • 25
8
votes
4 answers

Does development with scalaz require an Unicode/APL-like keyboard?

Can scalaz be used without a keyboard containing the appropriate Unicode characters or does every Unicode identifier also have an "ASCII" equivalent (and if yes, is there any guarantee that it stays that way)? Are there special keyboard layouts for…
soc
  • 27,983
  • 20
  • 111
  • 215