Skip to content

Instantly share code, notes, and snippets.

View channingwalton's full-sized avatar
🏠
Working from home

Channing Walton channingwalton

🏠
Working from home
View GitHub Profile
// ------------------------------------------------------
// 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")))))
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)