Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View 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));

View file

@ -0,0 +1 @@
[7, 14, 21, 28, 35, 42, 49, 56, 63, 70]

View 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]
})();

View file

@ -0,0 +1 @@
[14, 28, 42, 56, 70, 84, 98, 112, 126, 140]

View 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]
})();

View file

@ -0,0 +1 @@
[7, 14, 21, 28, 35, 42, 49, 56, 63, 70]

View 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]
})();

View file

@ -0,0 +1 @@
[14, 28, 42, 56, 70, 84, 98, 112, 126, 140]

View file

@ -0,0 +1 @@
(a,b) => expr_using_a_and_b

View file

@ -0,0 +1 @@
a => b => expr_using_a_and_b

View 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

View 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]
})();