From 16829b2cba4704ab305d1a5de21f6638f4848f38 Mon Sep 17 00:00:00 2001 From: chee Date: Wed, 5 Apr 2017 19:39:32 +0100 Subject: [PATCH] introduce mcflurry --- README.md | 23 +++++++++++++++++++++++ index.js | 9 +++++++++ package.json | 9 +++++++++ 3 files changed, 41 insertions(+) create mode 100644 README.md create mode 100644 index.js create mode 100644 package.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..39b3171 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# mcflurry + +destructuring an object in function arguments is fun and v flexible, but it +means you can't build up the arguments over time using `curry()` and v sad. + +so mcflurry lets you do this + +```js +const mcflurry = require('mcflurry') +const objectLog = mcflurry(console.log) +objectLog({a: 22})({b: 47})({c: 'dog', a: 1})() //=> {a:22, b:47, c:'dog'} +``` + +yes unfortunately it can't magically know when the function is fully satisfied, +the only way to do that would be to supply a list of the keys that needed to be +present separately as strings. that seemed more gross. + +ruby has `method(:lol).parameters` which would allow you to do it there, but not +in js in any way i could think of + +so i've opted for calling it with no arguments when you're done + +anyway thanks everybody bye diff --git a/index.js b/index.js new file mode 100644 index 0000000..8abb1ec --- /dev/null +++ b/index.js @@ -0,0 +1,9 @@ +module.exports = mcflurry +mcflurry.default = mcflurry + +function mcflurry(fn, object = {}) { + return function(next) { + const current = Object.assign({}, object, next) + return next ? mcflurry(fn, current) : fn(current) + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..1ec0bfe --- /dev/null +++ b/package.json @@ -0,0 +1,9 @@ +{ + "name": "mcflurry", + "version": "0.0.74", + "description": "build composeable functions using objects for keyword arguments", + "main": "index.js", + "repository": "git@gitlab.com:chee/mcflurry", + "author": "chee ", + "license": "MIT" +}