Skip to content

Instantly share code, notes, and snippets.

@gseitz
Created April 13, 2012 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gseitz/2379907 to your computer and use it in GitHub Desktop.
Save gseitz/2379907 to your computer and use it in GitHub Desktop.
trait PolyParse[F[_]] {
def F: Functor[F]
def APP: Applicative[F]
def ALT: Alternative[F]
def C: Commitment[F]
def M: MonadFail[F]
}
def oneOf[FA](fas: List[FA])(implicit U: Unapply[PolyParse, FA]): U.M[U.A] = fas match {
case Nil => U.TC.M.fail[U.A]("failed to parse any of the possible choices".toList)
case (f :: fs) => U.TC.ALT.<|>(U.apply(f), oneOf(fs))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment