Permalink
Browse files

[minor] added readme sample

  • Loading branch information...
1 parent d551a33 commit 44eead3a3c621d76648dd93c7edf92a8a10699eb @dscape committed Feb 18, 2012
Showing with 22 additions and 17 deletions.
  1. +1 −1 samples/map.js
  2. +0 −11 samples/map_async.js
  3. +5 −4 samples/nodetuts.js
  4. +15 −0 samples/readme.js
  5. +1 −1 samples/two_patterns.js
View
@@ -2,7 +2,7 @@ var map = require('../pattern')
, _, 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) {
ac.push(f(l.shift())); // head
map(f, l, ac); // l is now tail
View
@@ -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], []);
View
@@ -6,12 +6,13 @@ function insert_element(data, callback) {
Math.ceil(Math.random() * 1000));
}
-insert_all([], function done() { console.log('done'); });
-insert_all(_, function catchall(l) {
+insert_all([], _, function stop(l,cb) { cb(); });
+insert_all(_, _, function catchall(l, cb) {
insert_element(l.shift(), function elem_cb(elem) {
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'); });
View
@@ -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]);
View
@@ -9,7 +9,7 @@ function insert_element(data, callback) {
Math.ceil(Math.random() * 1000));
}
-function done() { console.log('done'); }
+function done(l) { console.log('done'); }
function any_generator (name,context) {
return function (l) {

0 comments on commit 44eead3

Please sign in to comment.