From fe42a7590778dc022c811dc15b50641cb5011acd Mon Sep 17 00:00:00 2001 From: Giles Bradshaw Date: Wed, 29 Jul 2020 14:53:46 +0100 Subject: [PATCH] initial commit --- compose.libsonnet | 19 +++++++++++++++++++ package.json | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 compose.libsonnet create mode 100644 package.json 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" +}