Skip to content

Instantly share code, notes, and snippets.

@johnazariah
Created April 8, 2015 05:59
Show Gist options
  • Save johnazariah/ec3b7f8840142866b7f8 to your computer and use it in GitHub Desktop.
Save johnazariah/ec3b7f8840142866b7f8 to your computer and use it in GitHub Desktop.
Scala Wat
type LF = (Argument, State) => (State, Result)
case class _then(f : LF)
case class _else(f : LF)
def _if (ifFunc: LF) (thenFunc: _then) (elseFunc: _else) : LF =
(a, state) => ifFunc(a, state) match {
case (_, Accepted) => thenFunc.f(a, state)
case _ => elseFunc.f(a, state)
}
def conditionallyCompose(conditionFunc: LF, trueFunc: LF, falseFunc: LF) : LF =
_if (conditionFunc) (_then(trueFunc)) (_else(falseFunc))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment