/*jshint asi: true */
module.exports = forge

var fu = require('fu')
var fs = require('fs')

function isFile(file) {
  return fs.existsSync(file)
}

function requireTransform(name) {
  try {
    return require(name)
  } catch (ex) {
    return null
  }
}

function forge(args) {
  var x = fu.foldl(function (obj, arg) {
    var item
    if (isFile(arg)) {
      obj.files.push(arg)
    } else if (item = requireTransform(arg)) {
      obj.transforms.push(item)
    }
    return obj
  }, args, { transforms: [], files: [] })

  return fu.map(function (file) {
    var stream = fs.createReadStream(file)
    return fu.foldl(function (stream, transform) {
      return stream.pipe(transform(file))
    }, x.transforms, stream).pipe(process.stdout)
  }, x.files)
}

@@ -262,237 +262,293 @@
 ion 
-forge(args) %7B%0A  var x = fu.foldl(function (obj, arg) %7B%0A    var item%0A    if (isFile(arg)) %7B%0A      obj.files.push(arg)%0A    %7D else if (item = requireTransform(arg)) %7B%0A      obj.transforms.push(item)%0A    %7D%0A    return obj%0A  %7D, args, %7B
+transformFiles(transforms) %7B%0A  return function (file) %7B%0A    return addTransforms(fs.createReadStream(file), transforms, file)%0A  %7D%0A%7D%0A%0Afunction transformStdin(transforms) %7B%0A  process.stdin.resume()%0A  return addTransforms(process.stdin, transforms, null)%0A%7D%0A%0Afunction addTransforms(stream,
  tra
@@ -558,27 +558,21 @@
 orms
-: %5B%5D
 , file
-s: %5B%5D %7D)%0A
+Name) %7B
 %0A  r
@@ -584,11 +584,13 @@
  fu.
-map
+foldl
 (fun
@@ -596,28 +596,41 @@
 nction (
-file
+stream, transform
 ) %7B%0A    
 var stre
@@ -625,201 +625,543 @@
     
-var
+return
  stream
- = fs.createReadStream(file)%0A    return fu.foldl(function (stream, transform) %7B%0A      return stream.pipe(transform(file))%0A    %7D, x.transforms, stream).pipe(process.stdout)%0A  %7D, x.file
+.pipe(transform(fileName))%0A  %7D, transforms, stream).pipe(process.stdout)%0A%7D%0A%0Afunction append(obj, prop, x) %7B%0A  obj%5Bprop%5D.push(x)%0A  return obj%0A%7D%0A%0Afunction forge(args) %7B%0A  var x = fu.foldl(function (obj, arg) %7B%0A    try %7B%0A      return isFile(arg)%0A        ? append(obj, 'files', arg)%0A        : append(obj, 'transforms', require(arg))%0A    %7D catch (ex) %7B%0A      return obj%0A    %7D%0A  %7D, args, %7B transforms: %5B%5D, files: %5B%5D %7D)%0A%0A  return x.files.length%0A    ? fu.map(transformFiles(x.transforms), x.files)%0A    : transformStdin(x.transform
 s)%0A%7D

Allow input from stdin