Skip to content

Instantly share code, notes, and snippets.

@klaeufer
Last active December 30, 2015 19:59
Show Gist options
  • Select an option

  • Save klaeufer/7877992 to your computer and use it in GitHub Desktop.

Select an option

Save klaeufer/7877992 to your computer and use it in GitHub Desktop.
minimal scalaz monoid example
import scalaz._ // general scalaz support
import syntax.monoid._ // monoid syntax as used below
import std.anyVal._ // some instances to work with
import std.list._ // some more instances
import std.option._ // some more instances
import syntax.std.option._ // postfix methods for options
object monoidExample {
val res0 = ∅[Int] // or: mzero[Int]
val res1 = 3 |+| 4 // or: 3 `mappend` 4
val res2 = ∅[List[Int]]
val res3 = List(1, 2, 3) |+| List(4, 5)
val res4 = none[Option[Int]]
val res5 = 3.some |+| 4.some
val res6 = 3.some |+| none
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment