Skip to content

Instantly share code, notes, and snippets.

@ririw
Forked from co1rowjp/gist:3845888
Created September 1, 2014 10:50
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 ririw/38c58f62ce345c251046 to your computer and use it in GitHub Desktop.
Save ririw/38c58f62ce345c251046 to your computer and use it in GitHub Desktop.
interface Functor {
fmap: (any) => any;
}
interface Monad extends Functor {
bind: (any) => Monad;
}
interface Maybe extends Monad {
}
class Just implements Maybe {
private value: any;
constructor(a: any) {
this.value = a
}
fmap (f: (any) => any): Just {
return new Just(f(this.value))
}
bind (f: (any) => Maybe): Maybe {
return f(this.value)
}
}
class Nothing implements Maybe {
fmap (f: (any) => any): Nothing {
return this
}
bind (f: (any) => Maybe): Maybe {
return this
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment