Skip to content

Instantly share code, notes, and snippets.

@bga
Forked from heapwolf/z.js
Created February 27, 2012 12:31
Show Gist options
  • Save bga/1923417 to your computer and use it in GitHub Desktop.
Save bga/1923417 to your computer and use it in GitHub Desktop.
z
var match = []
var _finalizeExpr = function(match) {
var vs = match[0]
var _iter = match[1]
var _done = match[2]
var i = 0
var _iterWrappper = function() {
if(i === vs.length) {
_done()
}
else {
_iter(vs[i], _iterWrappper)
i++
}
}
_iterWrappper()
};
([Array, Fn]
.map(function(v) {
return v.prototype
})
.forEach(function(v) {
v.valueOf = function() { var that = this;
_log(typeof(that))
if(
that instanceof Array && match.length === 0
|| that instanceof Fn && match.length === 1
|| that instanceof Fn && match.length === 2
) {
match.push(that)
if(match.length === 3) {
_finalizeExpr(match.concat())
match = []
}
}
else {
_log('break')
match = []
}
}
})
);
([1, 2, 3]
| function(v, _next) {
setTimeout(function() {
_log(v)
_next()
}, 1000)
}
| function() {
_log('end')
}
)
@kriskowal
Copy link

Cute hack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment