Skip to content

Instantly share code, notes, and snippets.

@benjaminjackman
Created November 9, 2011 19:59
Show Gist options
  • Save benjaminjackman/1352773 to your computer and use it in GitHub Desktop.
Save benjaminjackman/1352773 to your computer and use it in GitHub Desktop.
define ["jquery", "underscore", "barista"], ($, _, B) ->
outs = B.createModule()
#Define a protocol
IStack = outs.defTypeclass 'IStack', (self) -> {
push: self.Abstract
pop: self.Abstract
pushAll : (elems...) -> _(elems).forEach((elem) -> self.push(elem))
}
#Make an implementation for arrays.
outs.implementTypeclass IStack, (x, ys...) -> $.isArray(x) && ys.length == 0,
{
push :(elem) -> @.push(elem)
pop :() -> [@, @.pop()]
}
outs.export()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment