Created
November 9, 2011 19:59
-
-
Save benjaminjackman/1352773 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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