Created
November 3, 2014 01:28
-
-
Save vmarquez/74353ca4c1ce264f02c0 to your computer and use it in GitHub Desktop.
Option to State
This file contains hidden or 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
def OtoS[A](o: Option[A => A]): State[A,A] = | |
o match { | |
case Some(f) => State[A,A](a => { | |
val na = f(a) | |
(na,na) | |
}) | |
case None => State[A,A](a => (a,a)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment