Skip to content

Commit

Permalink
[minor] added readme sample
Browse files Browse the repository at this point in the history
  • Loading branch information
dscape committed Feb 18, 2012
1 parent d551a33 commit 44eead3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion samples/map.js
Expand Up @@ -2,7 +2,7 @@ var map = require('../pattern')
, _, f, ac , _, f, ac
; ;


map(f, [], ac, function done(_,_,ac) { return console.log(ac); }); map(f, [], ac, function done(_, _, ac) { return console.log(ac); });
map(f, _, ac, function all(f, l, ac) { map(f, _, ac, function all(f, l, ac) {
ac.push(f(l.shift())); // head ac.push(f(l.shift())); // head
map(f, l, ac); // l is now tail map(f, l, ac); // l is now tail
Expand Down
11 changes: 0 additions & 11 deletions samples/map_async.js
@@ -1,11 +0,0 @@
var map = require('../pattern')
, _, f, ac
;

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

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


insert_all([], function done() { console.log('done'); }); insert_all([], _, function stop(l,cb) { cb(); });
insert_all(_, function catchall(l) { insert_all(_, _, function catchall(l, cb) {
insert_element(l.shift(), function elem_cb(elem) { insert_element(l.shift(), function elem_cb(elem) {
console.log(elem + ' inserted'); console.log(elem + ' inserted');
insert_all(l); insert_all(l, cb);
}); });
}); });


insert_all([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); insert_all([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
function done() { console.log('done'); });
15 changes: 15 additions & 0 deletions samples/readme.js
@@ -0,0 +1,15 @@
var insert_all = require('../pattern'), _;

function insert_element(data, callback) {
setTimeout(function() { callback(data); }, Math.ceil(Math.random() * 1000));
}

insert_all([], function () { console.log('done'); });
insert_all(_, function (l) {
insert_element(l.shift(), function (elem) {
console.log('‣ ', elem);
insert_all(l);
});
});

insert_all([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
2 changes: 1 addition & 1 deletion samples/two_patterns.js
Expand Up @@ -9,7 +9,7 @@ function insert_element(data, callback) {
Math.ceil(Math.random() * 1000)); Math.ceil(Math.random() * 1000));
} }


function done() { console.log('done'); } function done(l) { console.log('done'); }


function any_generator (name,context) { function any_generator (name,context) {
return function (l) { return function (l) {
Expand Down

0 comments on commit 44eead3

Please sign in to comment.