Dataflow programming


Dataflow programming

dflow is a minimal Dataflow programming engine.

With npm do

$ npm install dflow

With bower do

$ bower install dflow

Say Hello World with dflow.

var dflow = require('dflow')
// A JSON that represents the execution graph. 
// arguments[0] ==> console.log 
var graph = {
  "task": {
    "1": "arguments[0]",
    "2": "console.log"
  "pipe": {
    "3": [ "1", "2" ]
// Create a dflow function. 
var f = dflow.fun(graph)
f('Hello World') // prints "Hello World" 

dflow exports a fun function ☺

Function fun as the following signature

  • param: {Object} graph to be executed.
  • param: {Object} additionalFunctions is an optional collection of functions.
  • returns: {Function} dflowFun that executes the given graph.

A graph is a collection of tasks and pipes that can be stored in JSON format.

Every task refers to a function which output can be piped as an argument to another other task.

A graph has the following properties

  • task: collection of function names.
  • pipe: connections from the output of a task to an input of another task.
  • data: (optional) persistence.
  • func: (optional) collection of subgraphs.

dflow provides few builtin functions and injects the following ones

  • return: a task that accepts one argument and behaves like a Return statement.
  • arguments: task that returns the arguments of dflowFun.
  • arguments[0] ... arguments[N]: tasks that return the arguments[i] of dflowFun.
  • .foo: accessor to graph.data.foo.
  • &bar: returns bar function.

See test/page.html for a working example of dflow in a browser context.

Node.js Stream Playground first example is

var fs = require("fs");
// Read File 
    // Write File 

It is ported to script stream.js which evaluates graph stream.json using few custom functions.

Every example has a graph and a set of expected results that are required by test/examples.js.

graph results

Just an empty graph, {} for instance. It is expected that dflow has nothing to do.

graph results

Takes two operands as arguments and returns its sum.

graph results

Implements the apply operator.

graph results

Like the . opretor, takes an object and a prop as arguments and returns object[prop] value.