Skip to content

Instantly share code, notes, and snippets.

@gustafnk
Created October 31, 2010 19:21
Show Gist options
  • Select an option

  • Save gustafnk/657020 to your computer and use it in GitHub Desktop.

Select an option

Save gustafnk/657020 to your computer and use it in GitHub Desktop.
It seems impossible to get a good syntax in CoffeeScript for the CallStream pattern: * http://dbj.org/dbj/?p=514 * http://weblogs.asp.net/bleroy/archive/2010/07/01/oh-yeah-callstream-is-great-to-express-monads.aspx
stateful = (value, state) ->
bind = (operation) ->
stateful(operation.call(bind, value), bind.state)
bind.value = value
bind.state = state
bind
p = stateful(3, "This is the state")((i) -> ++i)((i) -> this.state += "altered"; i * 10)((i) -> i + 2)
console.log("Value: " + p.value + "; state: " + p.state);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment