Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round-up of Scalaz type class instances for other libraries

I often find myself wanting (and then usually writing) Scalaz type class instances for classes in other Scala or Java libraries. To give just a few examples:

A monoid instance for Shapeless's HList gives you monoid instances for case classes with appropriately typed members almost for free.

An applicative functor instance for Lift's Box allows you for example to sequence a list of boxes:

scala> val boxen: List[Box[Int]] = Full(1) :: Full(2) :: Full(3) :: Nil
boxen: List[net.liftweb.common.Box[Int]] = List(Full(1), Full(2), Full(3))

scala> boxen.sequence
res0: net.liftweb.common.Box[List[Int]] = Full(List(1, 2, 3))

A monad instance for Dispatch 0.9's Promise (and Promise[Either[Throwable, _]], etc.) is hugely useful for all kinds of things.

An applicative functor instance for the standard library's Parser makes applicative parsing more concise and elegant. (I just noticed that Scalaz 7 now provides a monad instance for Parser.)

And so on...

These instances are almost always very general-purpose, and I'm sure lots of us have written lots of these lots of times. What I'm fishing for with this question is some kind of aggregator or clearinghouse for Scalaz type class instances. I'm not sure such a thing exists—I certainly haven't been able to find anything like it—but even just a collection of links to blog posts, GitHub repositories, or other resources would be useful to me.

I'd prefer Scalaz 7 instances, but I'll take anything I can get.

like image 523
Travis Brown Avatar asked Sep 14 '12 14:09

Travis Brown


1 Answers

Community wiki of Scalaz instances

Scalaz 7 instances

  • Easy case class instances (Monoid, Ordering, possibly serialization and others) - shapeless
  • Play! 2 instances - play-scalaz (Promise monad, Json serializers)
  • Akka 2.x Future - akkaz
like image 74
3 revs Avatar answered Sep 27 '22 17:09

3 revs