Skip to content

Instantly share code, notes, and snippets.

@dsugden
Created June 17, 2014 04:38
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 dsugden/c22b80123ecb01b091e0 to your computer and use it in GitHub Desktop.
Save dsugden/c22b80123ecb01b091e0 to your computer and use it in GitHub Desktop.
// 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