Skip to content

Commit

Permalink
Add feature to send single value to lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
smizell committed Sep 9, 2020
1 parent a01c767 commit 85dd857
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ const regex = {
test: (re, str) => re.test(str),
};

const jsonpath = require("jsonpath");

const defaultLibraries = [
R,
RA,
// These are libraries we want to name space
{
jq: require("jsonpath"),
jp: jsonpath.query.bind(jsonpath),
saunter: require("saunter"),
regex,
},
Expand Down Expand Up @@ -170,7 +172,11 @@ const defaultForms = {
}),

lambda: formWrapper((parentRuntime, lambdaArgs) => {
const argNames = lambdaArgs[0];
// Allow for a single value to be passed to lambdas
const argNames = RA.isArray(lambdaArgs[0])
? lambdaArgs[0]
: [lambdaArgs[0]];

// We create a copy of the scope when the lambda is created
// We don't want this scope to change
const frozenScope = parentRuntime.scope.copy();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "geneva",
"version": "1.4.0",
"version": "1.5.0",
"description": "Make your YAML and JSON dynamic",
"main": "index.js",
"scripts": {
Expand Down
25 changes: 25 additions & 0 deletions test/test_lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@ describe("Lambda", () => {
]);
expect(result).to.equal(5);
});

it.only("handles single value arguments", function () {
const geneva = new Geneva();
const result = geneva.run({
"fn:do": [
{
"fn:def": [
"foo",
{
"fn:lambda": [
"foo",
{
"fn:add": [4, "ref:foo"],
},
],
},
],
},
{
"fn:foo": [5],
},
],
});
expect(result).to.equal(9);
});
});

context("when defining a multi-line function", function () {
Expand Down

0 comments on commit 85dd857

Please sign in to comment.