diff --git a/src/api/validate-arguments/index.js b/src/api/validate-arguments/index.js index 3c1f569..6ce74ed 100644 --- a/src/api/validate-arguments/index.js +++ b/src/api/validate-arguments/index.js @@ -3,6 +3,7 @@ const isArguments = require("is-arguments"); const flatten = require("flatten"); const asExpression = require("as-expression"); +const syncpipe = require("syncpipe"); const ValidationError = require("@validatem/error"); const annotateErrors = require("@validatem/annotate-errors"); @@ -63,15 +64,12 @@ function applyDefinitions(args, definitions, remainingArgumentsIndex) { }; }); - // FIXME: Investigate syncpipe usage here - let combinedErrors = results.map((result) => result.errors); - let flattenedErrors = flatten(combinedErrors); // TODO: Switch to `Array#flat` once Node 10.x goes EOL (April 2021) - - let newValues = results.map((result) => result.newValue); - return { - errors: flattenedErrors, - newValue: newValues + errors: syncpipe(results, [ + (_) => _.map((result) => result.errors), + (_) => flatten(_) // TODO: Switch to `Array#flat` once Node 10.x goes EOL (April 2021) + ]), + newValue: results.map((result) => result.newValue) }; }