This file contains hidden or 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
| # While coffee script offers a "class" keyword, methods still aren't that closely | |
| # associated with class instances. Include fixScoping(this) at the beginning | |
| # of all of your constructors to make that class' methods well behaved by javascript standards | |
| fixScoping = (instance) -> | |
| for property, value of instance | |
| do (property, value) -> #b/c javascript | |
| if typeof value is "function" | |
| instance[property] = (args...) -> value.apply(instance, args) |
This file contains hidden or 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
| # use lodash/underscore, this could probably actually be a mixin for those | |
| compose = (fns) -> | |
| _.reduceRight fns, (composed, currentFn) -> | |
| _.compose (valueOrPromise) -> | |
| vop = valueOrPromise | |
| if Boolean vop and vop.then | |
| vop.then (value) -> | |
| currentFn value | |
| else | |
| currentFn vop |
This file contains hidden or 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
| ; Clojure actually has a queue type, but it's not easily accesible. Here's a function to help with that | |
| (defn queue | |
| ([] clojure.lang.PersistentQueue/EMPTY) | |
| ([& elements] | |
| (into (queue) elements))) |
NewerOlder