Skip to content

Instantly share code, notes, and snippets.

@mpilquist
mpilquist / State.scala
Created February 24, 2013 21:57
Example of computing Fibonacci sequence with Scala 2.10 and memoizing State monad
trait State[S, A] {
val run: S => (S, A)
def apply(s: S): (S, A) =
run(s)
def eval(s: S): A =
apply(s)._2
@channingwalton
channingwalton / StateMonad.scala
Created May 31, 2012 21:28
State Monad and Validation with Scalaz
import scalaz._
import Scalaz._
/**
* Use the state monad to 'process a trade' and store the new trade.
* As well as processing the trade, handle validation errors.
*/
object StateMonad extends App {
case class Trade(info: String)