pepka 1.6.16 → 1.6.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.cjs +7 -6
- package/dist/bundle.mjs +7 -6
- package/package.json +1 -1
- package/src/curry.ts +33 -7
package/dist/bundle.cjs
CHANGED
|
@@ -46,16 +46,17 @@ const endlessph = (fn) => {
|
|
|
46
46
|
}
|
|
47
47
|
return _endlessph;
|
|
48
48
|
};
|
|
49
|
+
const zero = 0;
|
|
49
50
|
function curry2(fn) {
|
|
50
|
-
function curried2(a,
|
|
51
|
+
function curried2(a, ...args) {
|
|
51
52
|
const withPlaceholder1 = a === __;
|
|
52
|
-
const aln =
|
|
53
|
-
if (aln
|
|
53
|
+
const aln = Boolean(args.length);
|
|
54
|
+
if (aln && withPlaceholder1)
|
|
54
55
|
throw new Error('Senseless placeholder usage.');
|
|
55
|
-
return aln
|
|
56
|
+
return aln
|
|
56
57
|
? withPlaceholder1
|
|
57
|
-
? endlessph((a) => fn(a,
|
|
58
|
-
: fn(a,
|
|
58
|
+
? endlessph((a) => fn(a, args[zero]))
|
|
59
|
+
: fn(a, args[zero])
|
|
59
60
|
: (b) => fn(a, b);
|
|
60
61
|
}
|
|
61
62
|
return curried2;
|
package/dist/bundle.mjs
CHANGED
|
@@ -44,16 +44,17 @@ const endlessph = (fn) => {
|
|
|
44
44
|
}
|
|
45
45
|
return _endlessph;
|
|
46
46
|
};
|
|
47
|
+
const zero = 0;
|
|
47
48
|
function curry2(fn) {
|
|
48
|
-
function curried2(a,
|
|
49
|
+
function curried2(a, ...args) {
|
|
49
50
|
const withPlaceholder1 = a === __;
|
|
50
|
-
const aln =
|
|
51
|
-
if (aln
|
|
51
|
+
const aln = Boolean(args.length);
|
|
52
|
+
if (aln && withPlaceholder1)
|
|
52
53
|
throw new Error('Senseless placeholder usage.');
|
|
53
|
-
return aln
|
|
54
|
+
return aln
|
|
54
55
|
? withPlaceholder1
|
|
55
|
-
? endlessph((a) => fn(a,
|
|
56
|
-
: fn(a,
|
|
56
|
+
? endlessph((a) => fn(a, args[zero]))
|
|
57
|
+
: fn(a, args[zero])
|
|
57
58
|
: (b) => fn(a, b);
|
|
58
59
|
}
|
|
59
60
|
return curried2;
|
package/package.json
CHANGED
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
|
|
42
42
|
"all": "npm run dev && npm run prod"
|
|
43
43
|
},
|
|
44
|
-
"version": "1.6.
|
|
44
|
+
"version": "1.6.17",
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
47
47
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
package/src/curry.ts
CHANGED
|
@@ -60,7 +60,33 @@ const endlessph = <Func extends AnyFunc>(fn: Func) => {
|
|
|
60
60
|
return _endlessph
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
type Curried2<p0, p1, ReturnT> = {
|
|
64
|
+
(a: Placeholder, b: p1): (a: p0) => ReturnT
|
|
65
|
+
(a: p0, b: Placeholder): (b: p1) => ReturnT
|
|
66
|
+
(a: p0): (b: p1) => ReturnT
|
|
67
|
+
(a: p0, b: p1): ReturnT
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const curried2 =
|
|
71
|
+
<p0, p1, ReturnT>(fn: (a: p0, b: p1) => ReturnT) => {
|
|
72
|
+
|
|
73
|
+
const impl = (
|
|
74
|
+
a: p0 | Placeholder,
|
|
75
|
+
...args: [b?: p1]
|
|
76
|
+
): ReturnT | ((b: p1) => ReturnT) => {
|
|
77
|
+
if (args.length === 0) {
|
|
78
|
+
return (b: p1) => fn(a as p0, b)
|
|
79
|
+
}
|
|
80
|
+
const b = args[0]
|
|
81
|
+
return fn(a as p0, b as p1)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return impl as Curried2<p0, p1, ReturnT>
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
63
88
|
type Func2 = (a: any, b: any) => any
|
|
89
|
+
const zero = 0
|
|
64
90
|
export function curry2<Func extends Func2>(fn: Func) {
|
|
65
91
|
type p0 = Parameters<Func>[0]
|
|
66
92
|
type p1 = Parameters<Func>[1]
|
|
@@ -69,16 +95,16 @@ export function curry2<Func extends Func2>(fn: Func) {
|
|
|
69
95
|
function curried2(a: p0, b: Placeholder): (b: p1) => ReturnT
|
|
70
96
|
function curried2(a: p0 ): (b: p1) => ReturnT
|
|
71
97
|
function curried2(a: p0, b: p1): ReturnT
|
|
72
|
-
function curried2(a: p0 | Placeholder, b?: p1) {
|
|
98
|
+
function curried2(a: p0 | Placeholder, ...args: [b?: p1]) {
|
|
73
99
|
const withPlaceholder1 = a===__
|
|
74
|
-
const aln =
|
|
75
|
-
if(aln
|
|
100
|
+
const aln = Boolean(args.length)
|
|
101
|
+
if(aln && withPlaceholder1)
|
|
76
102
|
throw new Error('Senseless placeholder usage.')
|
|
77
|
-
return aln
|
|
103
|
+
return aln
|
|
78
104
|
? withPlaceholder1
|
|
79
|
-
? endlessph((a: p0) => fn(a,
|
|
80
|
-
: fn(a,
|
|
81
|
-
: (b: p1) => fn(a, b) as
|
|
105
|
+
? endlessph((a: p0) => fn(a, args[zero]) as ReturnType<Func>)
|
|
106
|
+
: fn(a, args[zero]) as ReturnType<Func>
|
|
107
|
+
: (b: p1) => fn(a, b) as Curried2<p0, p1, ReturnT>
|
|
82
108
|
}
|
|
83
109
|
return curried2
|
|
84
110
|
}
|