my face
paulgray.net

Scalaz Imports

those imports you always need but can never remember.

The Scalaz import Pattern:

Enrichment methods for typeclasses are located in:

import scalaz.syntax.{typeclass}._

Enrichment for standard libs are located in:

import scalaz.syntax.std.{std-class}._

Typeclasses for std library classes are usually located in:

import scalaz.std.{std-class}._

Id

import scalaz.Id.Id

val string: Id[String] = "adsf"

Equals

In order to use ===, you need the equals syntax, and an Equal[A] instance, where A is the type you're comparing.

import scalaz.syntax.equal._ // for ===
import scalaz.std.string._   // for Equal[String]

"foo" === "bar"

If you're comparing a generic type, such as Option, you'll need an instance of Equal[Option[A]]. The implicit Option equals build can make this easy if you have an instance of Equal[A].

import scalaz.syntax.equal._ // for ===
import scalaz.std.string._   // for Equal[String]
import scalaz.std.option._   // for optionEqual[A]

Option("foo") === Option("bar")

Disjunction

import scalaz.syntax.either._

1.right
"Error".left

Semigroup

for |+|, you need the semigroup syntax, and a Semigroup[A], where A is the type you're adding.

import scalaz.syntax.semigroup._  // for |+|
import scalaz.std.string._        // for Semigroup[String]

"foo" |+| "bar"

Traverse

For .traverse, you need the traverse syntax, a Traverse[F], where F is the collection type, and an Applicative[G], where G is the type you're traversing into.

import scalaz.syntax.traverse._  // for .traverse
import scalaz.std.list._         // for Traverse[List]
import scalaz.std.option._       // for Applicative[Option]

List(1, 2, 3).traverse {
  a => Option(a)
}

Suml

For .suml, you need the foldable syntax, a Foldable[F] where F is the type of the collection you're squashing, and a Monoid[A], where A is the type inside your foldable.

import scalaz.syntax.foldable._  // for .suml
import scalaz.std.list._         // for Foldable[List]
import scalaz.std.string._       // for Monoid[String]

List("foo", "bar", "baz").suml   // "foobarbaz"

import scalaz.std.option._       // for Monoid[Option]

List(Some("foo"), None, Some("baz")).suml // Some("foobaz")