Skip to content

Instantly share code, notes, and snippets.

@munro
munro / asyncMap.js
Created July 15, 2011 17:57
Array.prototype.asyncMap
Array.prototype.asyncMap = function (fn, callback) {
var that = this, i, count = 0, errors = [], map = [];
for (i = 0; i < this.length; i += 1) {
(function iter(i) {
fn(that[i], function (err, value) {
err && errors.push(err);
map[i] = value;
count += 1;
if (count === that.length) {
callback(errors.length ? errors : false, map);
@gip
gip / freedsl.hs
Last active August 29, 2015 14:07
Haskell / Free Monad / How can I do something like this?
data A = A Text
data B = B Text A
data ActionC t next = InsertC t (t -> next)
instance Functor (ActionC t) where
fmap f (InsertC a b)= InsertC a (f . b)
insertC a = liftF (InsertC a id)
proC txt1 txt2 = do
-- Explicitly stating the order of computation `a (b c)` makes this not compile
-- While, if we used a C style, order of computation would be explicit by default `a(b(c))` vs `a(b, c)`
example1 = a b c
where
a first second = first ++ second
b = "hey"
c = " world"
-- Explicitly stating `a (b c)` makes this compile
example2 = a b c