diff --git a/compose.libsonnet b/compose.libsonnet new file mode 100644 index 0000000..163f535 --- /dev/null +++ b/compose.libsonnet @@ -0,0 +1,19 @@ + // the tail of an array +local tail(array) = std.makeArray( + std.length(array) -1, + function(x) array[x + 1], +); +local compose(functions) = + if std.length(functions) == 0 + then + function(object) object + else + function(object) compose( + tail( + functions, + ) + )( + functions[0](object) + ); +// compose an array of functions +compose diff --git a/package.json b/package.json new file mode 100644 index 0000000..81bfdbb --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "jsonnet-compose", + "version": "0.0.1", + "description": "function compose", + "main": "compose.libsonnet", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://sigyl.com/git/jsonnet/compose.git" + }, + "keywords": [ + "jsonnet", + "functional", + "compose" + ], + "author": "giles bradshaw", + "license": "MIT" +}