Skip to content

Commit

Permalink
[minor] minor fixes to code
Browse files Browse the repository at this point in the history
  • Loading branch information
dscape committed Feb 18, 2012
1 parent bac5d61 commit 26ac1c9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
11 changes: 5 additions & 6 deletions pattern.js
Expand Up @@ -24,18 +24,17 @@
ok = true; // set our flag to matching
log(' ✔ ', s[i], '===', arguments[i]);
j=0;
log('aa',arguments.length, (i+1))
if(arguments.length !== i+1) { continue ol; } }
if(arguments.length !== i+1) { log(' ⥁'); continue ol; } }
else { // if it doesnt match try next pattern in stack
log(' ✗ ', s[i], '===', arguments[i]);
// dont break and set ok to false if this is the last element
if(stack.length !== j+1) { ok = false; continue; } } }
if(stack.length === j+1 || arguments.length === i+1) {
if(stack.length!==j+1) { log(' ⥁'); ok = false; continue; } } }
//if(stack.length === j+1) {
// decide on the function base ok if its a match or not
var f = ok ? arguments[arguments.length-1] : s[s.length-1];
log(' ' + (ok ? 'λ' : 'ƒ'), f);
log(' ' + (ok ? 'λ' : 'ƒ'), f.name || f);
// execute whatever is the last argument on last pattern of stack
return f.apply(this, [].slice.call(arguments,0)); } } }
return f.apply(this, [].slice.call(arguments,0)); } } //}
} else {
stack.push([].slice.call(arguments,0)); // initializing add pattern
log('‣ ', [].slice.call(arguments,0));
Expand Down
6 changes: 3 additions & 3 deletions samples/map.js
Expand Up @@ -2,10 +2,10 @@ var map = require('../pattern')
, _
;

map(_, [], _, function(cb,ac) { return cb(ac); });
map(function(f, l, ac) {
map(_, [], _, function stop(cb,ac) { return cb(ac); });
map(function all(f, l, ac) {
ac.push(f(l.shift())); // head
map(f, l, ac); // l is now tail
});

map(function(x) { return x*2; }, [1,2,3], []);
map(function duplicate(x) { console.log(x); return x*2; }, [1,2,3], []);
8 changes: 4 additions & 4 deletions samples/nodetuts.js
Expand Up @@ -8,16 +8,16 @@ function insert_element(data, callback) {
Math.ceil(Math.random() * 1000));
}

insert_all([], _, function (cb) { cb(); });
insert_all(function (l,cb) {
insert_all([], _, function finish(cb) { cb(); });
insert_all(function catchall(l,cb) {
var elem = l.shift(); // head
insert_element(elem, function(err, elem) {
insert_element(elem, function elem_cb(err, elem) {
if(err) { return cb(err); }
console.log(elem + ' inserted');
insert_all(l, cb);
});
});

insert_all([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function () {
insert_all([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function done() {
console.log('done');
});

0 comments on commit 26ac1c9

Please sign in to comment.