Skip to content

Instantly share code, notes, and snippets.

@aardvarrk
Created December 6, 2012 19:18
Show Gist options
  • Select an option

  • Save aardvarrk/4227408 to your computer and use it in GitHub Desktop.

Select an option

Save aardvarrk/4227408 to your computer and use it in GitHub Desktop.
class Maybe
bind: (f) ->
if @_value is undefined then Nothing else f(@_value)
ret: (x) -> Just(x)
fmap: (f) ->
if @_value is undefined then Nothing else Just(f(@_value))
Just = (x) ->
m = new Maybe()
m._value = x
m
Nothing = Just(undefined)
bind = (m, f) -> m.bind(f)
ret = (m, x) -> m.ret(x)
fmap = (f, f_) -> f.fmap(f_)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment