Created
May 15, 2013 16:06
-
-
Save mpilquist/5585133 to your computer and use it in GitHub Desktop.
Example of using tagged boolean types in Scalaz 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz.std.option._ // Import the some and none functions | |
import scalaz.syntax.std.option._ // Import the syntax for calling ~ on Option | |
import scalaz.std.AllInstances._ // Import all typeclass instances for standard datatypes | |
~some(10) // 10 | |
~none[Int] // 0 | |
~some("test") // "test" | |
~none[String] // "" | |
//~some(false) // could not find implicit value for parameter z: scalaz.Monoid[Boolean] | |
// There's no Monoid[Boolean] but there is a Monoid[Boolean @@ Tags.Conjunction] and a Monoid[Boolean @@ Tags.Disjunction] | |
import scalaz.{@@, Tags} | |
~some(Tags.Conjunction(true)) // true | |
~none[Boolean @@ Tags.Conjunction] // true | |
~some(Tags.Disjunction(true)) // true | |
~none[Boolean @@ Tags.Disjunction] // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment