just-curry-it
Advanced tools
Comparing version 2.0.1 to 3.0.0
26
index.js
module.exports = curry; | ||
/* | ||
function add(a, b, c) { | ||
return a + b + c; | ||
} | ||
curry(add)(1)(2)(3); // 6 | ||
curry(add)(1)(2)(2); // 5 | ||
curry(add)(2)(4, 3); // 9 | ||
function add(...args) { | ||
return args.reduce((sum, n) => sum + n, 0) | ||
} | ||
var curryAdd4 = curry(add, 4) | ||
curryAdd4(1)(2, 3)(4); // 10 | ||
function converter(ratio, input) { | ||
return (input*ratio).toFixed(1); | ||
} | ||
var curriedConverter = curry(converter) | ||
var milesToKm = curriedConverter(1.62); | ||
const curriedConverter = curry(converter) | ||
const milesToKm = curriedConverter(1.62); | ||
milesToKm(35); // 56.7 | ||
@@ -13,9 +26,12 @@ milesToKm(10); // 16.2 | ||
function curry(fn) { | ||
function curry(fn, arity) { | ||
return function curried() { | ||
if (arity == null) { | ||
arity = fn.length; | ||
} | ||
var args = [].slice.call(arguments); | ||
if (args.length >= fn.length) { | ||
if (args.length >= arity) { | ||
return fn.apply(this, args); | ||
} else { | ||
return function () { | ||
return function() { | ||
return curried.apply(this, args.concat([].slice.call(arguments))); | ||
@@ -22,0 +38,0 @@ }; |
{ | ||
"name": "just-curry-it", | ||
"version": "2.0.1", | ||
"version": "3.0.0", | ||
"description": "return a curried function", | ||
@@ -10,8 +10,3 @@ "main": "index.js", | ||
"repository": "https://github.com/angus-c/just", | ||
"keywords": [ | ||
"function", | ||
"curry", | ||
"no-dependencies", | ||
"just" | ||
], | ||
"keywords": ["function", "curry", "no-dependencies", "just"], | ||
"author": "Angus Croll", | ||
@@ -18,0 +13,0 @@ "license": "MIT", |
@@ -11,8 +11,22 @@ ## just-curry-it | ||
function add(a, b, c) { | ||
return a + b + c; | ||
} | ||
curry(add)(1)(2)(3); // 6 | ||
curry(add)(1)(2)(2); // 5 | ||
curry(add)(2)(4, 3); // 9 | ||
function add(...args) { | ||
return args.reduce((sum, n) => sum + n, 0) | ||
} | ||
var curryAdd4 = curry(add, 4) | ||
curryAdd4(1)(2, 3)(4); // 10 | ||
function converter(ratio, input) { | ||
return (input*ratio).toFixed(1); | ||
} | ||
const milesToKm = curry(converter)(1.62); | ||
const curriedConverter = curry(converter) | ||
const milesToKm = curriedConverter(1.62); | ||
milesToKm(35); // 56.7 | ||
milesToKm(10); // 16.2 | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2027
36
32