Permalink
Browse files

examples with coffee script and a fix for par_

  • Loading branch information...
1 parent c346e8a commit 27e640217c19eed4816c07c50f1e8e7c82c73a9e @substack committed Feb 27, 2011
Showing with 42 additions and 6 deletions.
  1. +12 −0 examples/parseq.coffee
  2. +1 −1 examples/parseq.js
  3. +16 −0 examples/stat_all.coffee
  4. +13 −5 index.js
View
@@ -0,0 +1,12 @@
+fs = require 'fs'
+exec = require('child_process').exec
+Seq = require 'seq'
+
+Seq()
+ .seq_((next) -> exec 'whoami', next)
+ .par_((next, who) -> exec('groups ' + who, next))
+ .par_((next, who) -> fs.readFile(__filename, 'utf8', next))
+ .seq_((next, groups, src) ->
+ console.log('Groups: ' + groups.trim())
+ console.log('This file has ' + src.length + ' bytes')
+ )
View
@@ -10,7 +10,7 @@ Seq()
exec('groups ' + who, this);
})
.par(function (who) {
- fs.readFile(__filename, 'ascii', this);
+ fs.readFile(__filename, 'utf8', this);
})
.seq(function (groups, src) {
console.log('Groups: ' + groups.trim());
View
@@ -0,0 +1,16 @@
+fs = require 'fs'
+Hash = require 'hashish'
+Seq = require 'seq'
+
+Seq()
+ .seq_((next) ->
+ fs.readdir(__dirname, next)
+ )
+ .flatten()
+ .parEach_((next, file) ->
+ fs.stat(__dirname + '/' + file, next.into(file))
+ )
+ .seq_((next) ->
+ sizes = Hash.map(next.vars, (s) -> s.size)
+ console.dir sizes
+ )
View
@@ -164,15 +164,23 @@ function builder (saw, xs) {
this.par_ = function (key) {
var args = [].slice.call(arguments);
- if (typeof key === 'function') {
- args.unshift(undefined);
- }
- var cb = args[1];
- args[1] = function () {
+
+ var cb = typeof key === 'function'
+ ? args[0] : args[1];
+
+ var fn = function () {
var argv = [].slice.call(arguments);
argv.unshift(this);
cb.apply(this, argv);
};
+
+ if (typeof key === 'function') {
+ args[0] = fn;
+ }
+ else {
+ args[1] = fn;
+ }
+
this.par.apply(this, args);
};

0 comments on commit 27e6402

Please sign in to comment.