Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
10
Task/Currying/JavaScript/currying-1.js
Normal file
10
Task/Currying/JavaScript/currying-1.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
function addN(n) {
|
||||
var curry = function(x) {
|
||||
return x + n;
|
||||
};
|
||||
return curry;
|
||||
}
|
||||
|
||||
add2 = addN(2);
|
||||
alert(add2);
|
||||
alert(add2(7));
|
||||
1
Task/Currying/JavaScript/currying-10.js
Normal file
1
Task/Currying/JavaScript/currying-10.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
[7, 14, 21, 28, 35, 42, 49, 56, 63, 70]
|
||||
29
Task/Currying/JavaScript/currying-11.js
Normal file
29
Task/Currying/JavaScript/currying-11.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
(() => {
|
||||
|
||||
// (arbitrary arity to fully curried)
|
||||
// extraCurry :: Function -> Function
|
||||
let extraCurry = (f, ...args) => {
|
||||
let intArgs = f.length;
|
||||
|
||||
// Recursive currying
|
||||
let _curry = (xs, ...arguments) =>
|
||||
xs.length >= intArgs ? (
|
||||
f.apply(null, xs)
|
||||
) : function () {
|
||||
return _curry(xs.concat([].slice.apply(arguments)));
|
||||
};
|
||||
|
||||
return _curry([].slice.call(args, 1));
|
||||
};
|
||||
|
||||
// TEST
|
||||
|
||||
// product3:: Num -> Num -> Num -> Num
|
||||
let product3 = (a, b, c) => a * b * c;
|
||||
|
||||
return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
.map(extraCurry(product3)(7)(2))
|
||||
|
||||
// [14, 28, 42, 56, 70, 84, 98, 112, 126, 140]
|
||||
|
||||
})();
|
||||
1
Task/Currying/JavaScript/currying-12.js
Normal file
1
Task/Currying/JavaScript/currying-12.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
[14, 28, 42, 56, 70, 84, 98, 112, 126, 140]
|
||||
34
Task/Currying/JavaScript/currying-2.js
Normal file
34
Task/Currying/JavaScript/currying-2.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
(function () {
|
||||
|
||||
// curry :: ((a, b) -> c) -> a -> b -> c
|
||||
function curry(f) {
|
||||
return function (a) {
|
||||
return function (b) {
|
||||
return f(a, b);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// TESTS
|
||||
|
||||
// product :: Num -> Num -> Num
|
||||
function product(a, b) {
|
||||
return a * b;
|
||||
}
|
||||
|
||||
// return typeof curry(product);
|
||||
// --> function
|
||||
|
||||
// return typeof curry(product)(7)
|
||||
// --> function
|
||||
|
||||
//return typeof curry(product)(7)(9)
|
||||
// --> number
|
||||
|
||||
return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
.map(curry(product)(7))
|
||||
|
||||
// [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]
|
||||
|
||||
})();
|
||||
1
Task/Currying/JavaScript/currying-3.js
Normal file
1
Task/Currying/JavaScript/currying-3.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
[7, 14, 21, 28, 35, 42, 49, 56, 63, 70]
|
||||
34
Task/Currying/JavaScript/currying-4.js
Normal file
34
Task/Currying/JavaScript/currying-4.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
(function () {
|
||||
|
||||
// (arbitrary arity to fully curried)
|
||||
// extraCurry :: Function -> Function
|
||||
function extraCurry(f) {
|
||||
|
||||
// Recursive currying
|
||||
function _curry(xs) {
|
||||
return xs.length >= intArgs ? (
|
||||
f.apply(null, xs)
|
||||
) : function () {
|
||||
return _curry(xs.concat([].slice.apply(arguments)));
|
||||
};
|
||||
}
|
||||
|
||||
var intArgs = f.length;
|
||||
|
||||
return _curry([].slice.call(arguments, 1));
|
||||
}
|
||||
|
||||
|
||||
// TEST
|
||||
|
||||
// product3:: Num -> Num -> Num -> Num
|
||||
function product3(a, b, c) {
|
||||
return a * b * c;
|
||||
}
|
||||
|
||||
return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
.map(extraCurry(product3)(7)(2))
|
||||
|
||||
// [14, 28, 42, 56, 70, 84, 98, 112, 126, 140]
|
||||
|
||||
})();
|
||||
1
Task/Currying/JavaScript/currying-5.js
Normal file
1
Task/Currying/JavaScript/currying-5.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
[14, 28, 42, 56, 70, 84, 98, 112, 126, 140]
|
||||
1
Task/Currying/JavaScript/currying-6.js
Normal file
1
Task/Currying/JavaScript/currying-6.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
(a,b) => expr_using_a_and_b
|
||||
1
Task/Currying/JavaScript/currying-7.js
Normal file
1
Task/Currying/JavaScript/currying-7.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
a => b => expr_using_a_and_b
|
||||
23
Task/Currying/JavaScript/currying-8.js
Normal file
23
Task/Currying/JavaScript/currying-8.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
let
|
||||
fix = // This is a variant of the Applicative order Y combinator
|
||||
f => (f => f(f))(g => f((...a) => g(g)(...a))),
|
||||
curry =
|
||||
f => (
|
||||
fix(
|
||||
z => (n,...a) => (
|
||||
n>0
|
||||
?b => z(n-1,...a,b)
|
||||
:f(...a)))
|
||||
(f.length)),
|
||||
curryrest =
|
||||
f => (
|
||||
fix(
|
||||
z => (n,...a) => (
|
||||
n>0
|
||||
?b => z(n-1,...a,b)
|
||||
:(...b) => f(...a,...b)))
|
||||
(f.length)),
|
||||
curriedmax=curry(Math.max),
|
||||
curryrestedmax=curryrest(Math.max);
|
||||
print(curriedmax(8)(4),curryrestedmax(8)(4)(),curryrestedmax(8)(4)(9,7,2));
|
||||
// 8,8,9
|
||||
27
Task/Currying/JavaScript/currying-9.js
Normal file
27
Task/Currying/JavaScript/currying-9.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
(() => {
|
||||
|
||||
// curry :: ((a, b) -> c) -> a -> b -> c
|
||||
let curry = f => a => b => f(a, b);
|
||||
|
||||
|
||||
// TEST
|
||||
|
||||
// product :: Num -> Num -> Num
|
||||
let product = (a, b) => a * b,
|
||||
|
||||
// Int -> Int -> Maybe Int -> [Int]
|
||||
range = (m, n, step) => {
|
||||
let d = (step || 1) * (n >= m ? 1 : -1);
|
||||
|
||||
return Array.from({
|
||||
length: Math.floor((n - m) / d) + 1
|
||||
}, (_, i) => m + (i * d));
|
||||
}
|
||||
|
||||
|
||||
return range(1, 10)
|
||||
.map(curry(product)(7))
|
||||
|
||||
// [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]
|
||||
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue