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
// ------------------------------------------------------ | |
// Combined List/Option/Either | |
// ------------------------------------------------------ | |
object MonadTransformers extends App { | |
import scalaz._, Scalaz._ | |
import EitherT._ | |
type OptionTList[α] = ({ type λ[α] = OptionT[List, α] })#λ[α] | |
val c1: EitherT[OptionTList, String, String] = eitherT[OptionTList, String, String](OptionT[List, \/[String, String]](List(some(\/-("c1a")), some(\/-("c1b"))))) |
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
object MonadWriterExample extends App { | |
import scalaz._ | |
import Scalaz._ | |
implicit val monadWriter = EitherT.listenableMonadWriter[Writer, String, String] | |
case class Person(firstName: String, age: Int, car: Option[String]) | |
def notEmpty(s: String) = Option(s).filter(x ⇒ !x.isEmpty && !x.forall(_.isWhitespace)) match { | |
case Some(r) ⇒ monadWriter.right[String](r) |