@effect/data
Advanced tools
Comparing version 0.15.1 to 0.16.0
@@ -66,11 +66,72 @@ "use strict"; | ||
exports.isFunction = isFunction; | ||
const dual = (arity, body) => { | ||
const isDataFirst = typeof arity === "number" ? args => args.length >= arity : arity; | ||
return function () { | ||
if (isDataFirst(arguments)) { | ||
// @ts-expect-error | ||
return body.apply(this, arguments); | ||
} | ||
return self => body(self, ...arguments); | ||
}; | ||
const dual = function (arity, body) { | ||
if (typeof arity === "function") { | ||
return function () { | ||
if (arity(arguments)) { | ||
// @ts-expect-error | ||
return body.apply(this, arguments); | ||
} | ||
return self => body(self, ...arguments); | ||
}; | ||
} | ||
switch (arity) { | ||
case 0: | ||
return body; | ||
case 1: | ||
return function (a) { | ||
if (arguments.length >= 1) { | ||
return body(a); | ||
} | ||
return function () { | ||
return body(a); | ||
}; | ||
}; | ||
case 2: | ||
return function (a, b) { | ||
if (arguments.length >= 2) { | ||
return body(a, b); | ||
} | ||
return function (self) { | ||
return body(self, a); | ||
}; | ||
}; | ||
case 3: | ||
return function (a, b, c) { | ||
if (arguments.length >= 3) { | ||
return body(a, b, c); | ||
} | ||
return function (self) { | ||
return body(self, a, b); | ||
}; | ||
}; | ||
case 4: | ||
return function (a, b, c, d) { | ||
if (arguments.length >= 4) { | ||
return body(a, b, c, d); | ||
} | ||
return function (self) { | ||
return body(self, a, b, c); | ||
}; | ||
}; | ||
case 5: | ||
return function (a, b, c, d, e) { | ||
if (arguments.length >= 5) { | ||
return body(a, b, c, d, e); | ||
} | ||
return function (self) { | ||
return body(self, a, b, c, d); | ||
}; | ||
}; | ||
default: | ||
return function () { | ||
if (arguments.length >= arity) { | ||
// @ts-expect-error | ||
return body.apply(this, arguments); | ||
} | ||
const args = arguments; | ||
return function (self) { | ||
return body(self, ...args); | ||
}; | ||
}; | ||
} | ||
}; | ||
@@ -77,0 +138,0 @@ /** |
@@ -640,3 +640,2 @@ /** | ||
* assert.deepStrictEqual(O.all({ a: O.some(1), b: O.none() }), O.none()) | ||
* assert.deepStrictEqual(O.all(O.some(1), O.some("hello")), O.some([1, "hello"])) | ||
* assert.deepStrictEqual(O.all([O.some(1), O.some(2)]), O.some([1, 2])) | ||
@@ -647,14 +646,7 @@ * | ||
*/ | ||
export declare const all: { | ||
<A extends ReadonlyArray<Option<any>>>(elements: A): Option<{ | ||
-readonly [I in keyof A]: [A[I]] extends [Option<infer _A>] ? _A : never; | ||
}>; | ||
<A>(elements: Iterable<Option<A>>): Option<Array<A>>; | ||
<A extends ReadonlyArray<Option<any>>>(...elements: A): Option<{ | ||
-readonly [I in keyof A]: [A[I]] extends [Option<infer A>] ? A : never; | ||
}>; | ||
<A extends Record<string, Option<any>>>(fields: A): Option<{ | ||
-readonly [K in keyof A]: [A[K]] extends [Option<infer A>] ? A : never; | ||
}>; | ||
}; | ||
export declare const all: <const I extends Iterable<Option<any>> | Record<string, Option<any>>>(input: I) => [I] extends [ReadonlyArray<Option<any>>] ? Option<{ | ||
-readonly [K in keyof I]: [I[K]] extends [Option<infer A>] ? A : never; | ||
}> : [I] extends [Iterable<Option<infer A>>] ? Option<Array<A>> : Option<{ | ||
-readonly [K in keyof I]: [I[K]] extends [Option<infer A>] ? A : never; | ||
}>; | ||
/** | ||
@@ -661,0 +653,0 @@ * Zips two `Option` values together using a provided function, returning a new `Option` of the result. |
@@ -612,3 +612,2 @@ "use strict"; | ||
* assert.deepStrictEqual(O.all({ a: O.some(1), b: O.none() }), O.none()) | ||
* assert.deepStrictEqual(O.all(O.some(1), O.some("hello")), O.some([1, "hello"])) | ||
* assert.deepStrictEqual(O.all([O.some(1), O.some(2)]), O.some([1, 2])) | ||
@@ -619,8 +618,8 @@ * | ||
*/ | ||
// @ts-expect-error | ||
exports.productMany = productMany; | ||
const all = function () { | ||
const collection = arguments.length === 1 && isOption(arguments[0]) ? [arguments[0]] : arguments.length !== 1 ? arguments : arguments[0]; | ||
if (Symbol.iterator in collection) { | ||
const all = input => { | ||
if (Symbol.iterator in input) { | ||
const out = []; | ||
for (const o of collection) { | ||
for (const o of input) { | ||
if (isNone(o)) { | ||
@@ -634,4 +633,4 @@ return none(); | ||
const out = {}; | ||
for (const key of Object.keys(collection)) { | ||
const o = collection[key]; | ||
for (const key of Object.keys(input)) { | ||
const o = input[key]; | ||
if (isNone(o)) { | ||
@@ -638,0 +637,0 @@ return none(); |
{ | ||
"name": "@effect/data", | ||
"version": "0.15.1", | ||
"version": "0.16.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -13,3 +13,3 @@ # Installation | ||
- TypeScript 4.9 or newer | ||
- TypeScript 5.0 or newer | ||
- The `strict` flag enabled in your `tsconfig.json` file | ||
@@ -16,0 +16,0 @@ |
@@ -80,13 +80,79 @@ /** | ||
): DataLast & DataFirst | ||
} = (arity, body) => { | ||
const isDataFirst: (args: IArguments) => boolean = typeof arity === "number" ? | ||
((args) => args.length >= arity) : | ||
arity | ||
return function() { | ||
if (isDataFirst(arguments)) { | ||
// @ts-expect-error | ||
return body.apply(this, arguments) | ||
} = function(arity, body) { | ||
if (typeof arity === "function") { | ||
return function() { | ||
if (arity(arguments)) { | ||
// @ts-expect-error | ||
return body.apply(this, arguments) | ||
} | ||
return ((self: any) => body(self, ...arguments)) as any | ||
} | ||
return ((self: any) => body(self, ...arguments)) as any | ||
} | ||
switch (arity) { | ||
case 0: | ||
return body | ||
case 1: | ||
return function(a) { | ||
if (arguments.length >= 1) { | ||
return body(a) | ||
} | ||
return function() { | ||
return body(a) | ||
} | ||
} | ||
case 2: | ||
return function(a, b) { | ||
if (arguments.length >= 2) { | ||
return body(a, b) | ||
} | ||
return function(self: any) { | ||
return body(self, a) | ||
} | ||
} | ||
case 3: | ||
return function(a, b, c) { | ||
if (arguments.length >= 3) { | ||
return body(a, b, c) | ||
} | ||
return function(self: any) { | ||
return body(self, a, b) | ||
} | ||
} | ||
case 4: | ||
return function(a, b, c, d) { | ||
if (arguments.length >= 4) { | ||
return body(a, b, c, d) | ||
} | ||
return function(self: any) { | ||
return body(self, a, b, c) | ||
} | ||
} | ||
case 5: | ||
return function(a, b, c, d, e) { | ||
if (arguments.length >= 5) { | ||
return body(a, b, c, d, e) | ||
} | ||
return function(self: any) { | ||
return body(self, a, b, c, d) | ||
} | ||
} | ||
default: | ||
return function() { | ||
if (arguments.length >= arity) { | ||
// @ts-expect-error | ||
return body.apply(this, arguments) | ||
} | ||
const args = arguments | ||
return function(self: any) { | ||
return body(self, ...args) | ||
} | ||
} | ||
} | ||
} | ||
@@ -93,0 +159,0 @@ /** |
@@ -763,3 +763,2 @@ /** | ||
* assert.deepStrictEqual(O.all({ a: O.some(1), b: O.none() }), O.none()) | ||
* assert.deepStrictEqual(O.all(O.some(1), O.some("hello")), O.some([1, "hello"])) | ||
* assert.deepStrictEqual(O.all([O.some(1), O.some(2)]), O.some([1, 2])) | ||
@@ -770,31 +769,30 @@ * | ||
*/ | ||
export const all: { | ||
<A extends ReadonlyArray<Option<any>>>( | ||
elements: A | ||
): Option<{ -readonly [I in keyof A]: [A[I]] extends [Option<infer _A>] ? _A : never }> | ||
// @ts-expect-error | ||
export const all: <const I extends Iterable<Option<any>> | Record<string, Option<any>>>( | ||
input: I | ||
) => [I] extends [ReadonlyArray<Option<any>>] ? Option< | ||
{ -readonly [K in keyof I]: [I[K]] extends [Option<infer A>] ? A : never } | ||
> | ||
: [I] extends [Iterable<Option<infer A>>] ? Option<Array<A>> | ||
: Option<{ -readonly [K in keyof I]: [I[K]] extends [Option<infer A>] ? A : never }> = ( | ||
input: Iterable<Option<any>> | Record<string, Option<any>> | ||
): Option<any> => { | ||
if (Symbol.iterator in input) { | ||
const out: Array<Option<any>> = [] | ||
for (const o of (input as Iterable<Option<any>>)) { | ||
if (isNone(o)) { | ||
return none() | ||
} | ||
out.push(o.value) | ||
} | ||
return some(out) | ||
} | ||
<A>(elements: Iterable<Option<A>>): Option<Array<A>> | ||
<A extends ReadonlyArray<Option<any>>>( | ||
...elements: A | ||
): Option<{ -readonly [I in keyof A]: [A[I]] extends [Option<infer A>] ? A : never }> | ||
<A extends Record<string, Option<any>>>( | ||
fields: A | ||
): Option<{ -readonly [K in keyof A]: [A[K]] extends [Option<infer A>] ? A : never }> | ||
} = function() { | ||
const collection: Record<string, Option<any>> | Iterable<Option<any>> = | ||
arguments.length === 1 && isOption(arguments[0]) ? | ||
[arguments[0]] : | ||
arguments.length !== 1 ? | ||
arguments : | ||
arguments[0] | ||
if (Symbol.iterator in collection) { | ||
const out: Array<Option<any>> = [] | ||
for (const o of collection) { | ||
const out: Record<string, any> = {} | ||
for (const key of Object.keys(input)) { | ||
const o = input[key] | ||
if (isNone(o)) { | ||
return none() | ||
} | ||
out.push(o.value) | ||
out[key] = o.value | ||
} | ||
@@ -804,13 +802,2 @@ return some(out) | ||
const out: any = {} | ||
for (const key of Object.keys(collection)) { | ||
const o = collection[key] | ||
if (isNone(o)) { | ||
return none() | ||
} | ||
out[key] = o.value | ||
} | ||
return some(out) | ||
} | ||
/** | ||
@@ -817,0 +804,0 @@ * Zips two `Option` values together using a provided function, returning a new `Option` of the result. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
2921262
61664