Skip to content

Instantly share code, notes, and snippets.

View micmarsh's full-sized avatar

Michael Marsh micmarsh

View GitHub Profile
@micmarsh
micmarsh / compose.coffee
Last active December 31, 2015 01:49
Compose Promises and Synchronous Functions
# 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
@micmarsh
micmarsh / queue.clj
Last active December 30, 2015 22:39
Persistent Queue In Clojure
; 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)))