Created
June 17, 2014 04:38
-
-
Save dsugden/c22b80123ecb01b091e0 to your computer and use it in GitHub Desktop.
This file contains 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
// we desire this pattern Better => (Better,Int) | |
type BetterUpdate = Better => (Better,Int) | |
val firstF:BetterUpdate = Better.sum(1) | |
val secondF:BetterUpdate = Better.sum(2) | |
val thirdF:BetterUpdate = Better.sum(3) | |
// the external state is threaded through a sequence of computations | |
val composeSumResults:BetterUpdate = better => { | |
val (firstState,firstResult) = firstF(better) | |
val (secondState, secondResult) = secondF(firstState) | |
val (thirdStater, thirdResult) = thirdF(secondState) // now when this blows up, we have secondState in scope for inspection | |
(thirdStater, firstResult + secondResult + thirdResult) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment