fnts 1.0.2 → 1.3.0
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/README.md +4 -50
- package/cjs/compose.js +25 -0
- package/cjs/curry.js +37 -0
- package/cjs/either/either-sync.js +21 -0
- package/cjs/either/either.js +18 -0
- package/cjs/either/index.js +11 -0
- package/cjs/either/left.js +22 -0
- package/cjs/either/operators/bifold/bifold.js +15 -0
- package/cjs/either/operators/bifold/bifoldl.js +17 -0
- package/cjs/either/operators/bifold/bifoldr.js +17 -0
- package/cjs/either/operators/bifold/index.js +9 -0
- package/cjs/either/operators/bifold-map.js +20 -0
- package/cjs/either/operators/bimap/bimap.js +20 -0
- package/cjs/either/operators/bimap/first.js +22 -0
- package/cjs/either/operators/bimap/index.js +9 -0
- package/cjs/either/operators/bimap/second.js +22 -0
- package/cjs/either/operators/guards.js +22 -0
- package/cjs/either/operators/index.js +24 -0
- package/cjs/either/right.js +22 -0
- package/cjs/guard.js +37 -0
- package/cjs/identity.js +12 -0
- package/cjs/index.js +21 -0
- package/cjs/inject.js +23 -0
- package/cjs/maybe/index.js +9 -0
- package/cjs/maybe/just.js +22 -0
- package/cjs/maybe/maybe.js +17 -0
- package/cjs/maybe/nothing.js +22 -0
- package/cjs/maybe/operators/bind.js +21 -0
- package/cjs/maybe/operators/fmap.js +22 -0
- package/cjs/maybe/operators/fold-map.js +20 -0
- package/cjs/maybe/operators/fold.js +17 -0
- package/cjs/maybe/operators/guards.js +22 -0
- package/cjs/maybe/operators/index.js +14 -0
- package/cjs/permutation/index.js +7 -0
- package/cjs/permutation/permutation-2.js +18 -0
- package/cjs/permutation/permutation-3.js +18 -0
- package/cjs/pipe.js +25 -0
- package/cjs/rethrow.js +16 -0
- package/cjs/tap.js +15 -0
- package/cjs/ternary.js +16 -0
- package/compose.d.ts +5 -3
- package/curry.d.ts +6 -4
- package/either/either-sync.d.ts +10 -0
- package/either/either.d.ts +8 -40
- package/either/index.d.ts +4 -1
- package/either/left.d.ts +21 -0
- package/either/operators/bifold/bifold.d.ts +15 -0
- package/either/operators/bifold/bifoldl.d.ts +15 -0
- package/either/operators/bifold/bifoldr.d.ts +15 -0
- package/either/operators/bifold/index.d.ts +3 -0
- package/either/operators/bifold-map.d.ts +10 -7
- package/either/operators/bimap/bimap.d.ts +13 -0
- package/either/operators/bimap/first.d.ts +15 -0
- package/either/operators/bimap/index.d.ts +3 -0
- package/either/operators/bimap/second.d.ts +15 -0
- package/either/operators/guards.d.ts +8 -3
- package/either/operators/index.d.ts +3 -3
- package/either/right.d.ts +21 -0
- package/esm/compose.js +18 -0
- package/esm/curry.js +23 -0
- package/esm/either/either-sync.js +18 -0
- package/esm/either/either.js +15 -0
- package/esm/either/index.js +4 -0
- package/esm/either/left.js +17 -0
- package/esm/either/operators/bifold/bifold.js +12 -0
- package/esm/either/operators/bifold/bifoldl.js +14 -0
- package/esm/either/operators/bifold/bifoldr.js +14 -0
- package/esm/either/operators/bifold/index.js +3 -0
- package/esm/either/operators/bifold-map.js +13 -0
- package/esm/either/operators/bimap/bimap.js +13 -0
- package/esm/either/operators/bimap/first.js +15 -0
- package/esm/either/operators/bimap/index.js +3 -0
- package/esm/either/operators/bimap/second.js +15 -0
- package/esm/either/operators/guards.js +17 -0
- package/esm/either/operators/index.js +4 -0
- package/esm/either/right.js +17 -0
- package/esm/guard.js +26 -0
- package/esm/identity.js +9 -0
- package/esm/index.js +9 -0
- package/esm/inject.js +12 -0
- package/esm/maybe/index.js +3 -0
- package/esm/maybe/just.js +17 -0
- package/esm/maybe/maybe.js +14 -0
- package/esm/maybe/nothing.js +17 -0
- package/esm/maybe/operators/bind.js +14 -0
- package/esm/maybe/operators/fmap.js +15 -0
- package/esm/maybe/operators/fold-map.js +13 -0
- package/esm/maybe/operators/fold.js +14 -0
- package/esm/maybe/operators/guards.js +17 -0
- package/esm/maybe/operators/index.js +5 -0
- package/esm/permutation/index.js +2 -0
- package/esm/permutation/permutation-2.js +11 -0
- package/esm/permutation/permutation-3.js +11 -0
- package/esm/pipe.js +18 -0
- package/esm/rethrow.js +13 -0
- package/esm/tap.js +12 -0
- package/esm/ternary.js +13 -0
- package/guard.d.ts +5 -3
- package/identity.d.ts +4 -2
- package/index.d.ts +9 -7
- package/inject.d.ts +14 -0
- package/maybe/index.d.ts +3 -1
- package/maybe/just.d.ts +21 -0
- package/maybe/maybe.d.ts +6 -38
- package/maybe/nothing.d.ts +21 -0
- package/maybe/operators/bind.d.ts +10 -7
- package/maybe/operators/fmap.d.ts +10 -7
- package/maybe/operators/fold-map.d.ts +37 -12
- package/maybe/operators/fold.d.ts +7 -3
- package/maybe/operators/guards.d.ts +8 -3
- package/maybe/operators/index.d.ts +5 -5
- package/package.json +12 -5
- package/permutation/index.d.ts +2 -0
- package/permutation/permutation-2.d.ts +7 -0
- package/permutation/permutation-3.d.ts +7 -0
- package/pipe.d.ts +5 -3
- package/rethrow.d.ts +9 -0
- package/tap.d.ts +11 -0
- package/ternary.d.ts +10 -0
- package/tsconfig.json +1 -1
- package/types/effect.d.ts +9 -0
- package/types/gradual.d.ts +17 -0
- package/{.internal → types}/last.d.ts +7 -0
- package/types/map.d.ts +8 -0
- package/{.internal → types}/slice.d.ts +7 -0
- package/{.internal → types}/tuple.d.ts +6 -0
- package/.internal/gradual.d.ts +0 -5
- package/.internal/map.d.ts +0 -1
- package/.internal/permutation-of-2.d.ts +0 -1
- package/.internal/permutation-of-2.js +0 -1
- package/.internal/permutation-of-3.d.ts +0 -1
- package/.internal/permutation-of-3.js +0 -1
- package/compose.js +0 -1
- package/curry.js +0 -1
- package/either/either.js +0 -1
- package/either/index.js +0 -1
- package/either/operators/bifold-map.js +0 -1
- package/either/operators/bifold.d.ts +0 -31
- package/either/operators/bifold.js +0 -1
- package/either/operators/bimap.d.ts +0 -29
- package/either/operators/bimap.js +0 -1
- package/either/operators/guards.js +0 -1
- package/either/operators/index.js +0 -1
- package/guard.js +0 -1
- package/identity.js +0 -1
- package/index.js +0 -1
- package/maybe/index.js +0 -1
- package/maybe/maybe.js +0 -1
- package/maybe/operators/bind.js +0 -1
- package/maybe/operators/fmap.js +0 -1
- package/maybe/operators/fold-map.js +0 -1
- package/maybe/operators/fold.js +0 -1
- package/maybe/operators/guards.js +0 -1
- package/maybe/operators/index.js +0 -1
- package/pipe.js +0 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Maybe Operators
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var compose_1 = require("../../compose");
|
|
7
|
+
var identity_1 = require("../../identity");
|
|
8
|
+
var maybe_1 = require("../maybe");
|
|
9
|
+
var permutation_2_1 = require("../../permutation/permutation-2");
|
|
10
|
+
var fold_1 = require("./fold");
|
|
11
|
+
var guards_1 = require("./guards");
|
|
12
|
+
var ternary_1 = require("../../ternary");
|
|
13
|
+
function fmap() {
|
|
14
|
+
var args = [];
|
|
15
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
16
|
+
args[_i] = arguments[_i];
|
|
17
|
+
}
|
|
18
|
+
return permutation_2_1.default(function (monad, transition) {
|
|
19
|
+
return ternary_1.default(guards_1.isJust, compose_1.default(maybe_1.default, transition, fold_1.default), identity_1.default)(monad);
|
|
20
|
+
}).apply(void 0, args);
|
|
21
|
+
}
|
|
22
|
+
exports.default = fmap;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Maybe Operators
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var compose_1 = require("../../compose");
|
|
7
|
+
var ternary_1 = require("../../ternary");
|
|
8
|
+
var permutation_2_1 = require("../../permutation/permutation-2");
|
|
9
|
+
var fold_1 = require("./fold");
|
|
10
|
+
var guards_1 = require("./guards");
|
|
11
|
+
function foldMap() {
|
|
12
|
+
var args = [];
|
|
13
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
14
|
+
args[_i] = arguments[_i];
|
|
15
|
+
}
|
|
16
|
+
return permutation_2_1.default(function (monad, transition) {
|
|
17
|
+
return ternary_1.default(guards_1.isJust, compose_1.default(transition, fold_1.default), function () { return null; })(monad);
|
|
18
|
+
}).apply(void 0, args);
|
|
19
|
+
}
|
|
20
|
+
exports.default = foldMap;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Maybe Operators
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var just_1 = require("../just");
|
|
7
|
+
var nothing_1 = require("../nothing");
|
|
8
|
+
var guards_1 = require("./guards");
|
|
9
|
+
/**
|
|
10
|
+
* Returns the value of the provided `monad`.
|
|
11
|
+
*/
|
|
12
|
+
function fold(monad) {
|
|
13
|
+
return guards_1.isJust(monad)
|
|
14
|
+
? monad[just_1.jid]
|
|
15
|
+
: monad[nothing_1.nid];
|
|
16
|
+
}
|
|
17
|
+
exports.default = fold;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Maybe Operators
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isNothing = exports.isJust = void 0;
|
|
7
|
+
var just_1 = require("../just");
|
|
8
|
+
var nothing_1 = require("../nothing");
|
|
9
|
+
/**
|
|
10
|
+
* Type guard function to tell if the provided `monad` is `Just`.
|
|
11
|
+
*/
|
|
12
|
+
function isJust(monad) {
|
|
13
|
+
return Object.prototype.hasOwnProperty.call(monad, just_1.jid);
|
|
14
|
+
}
|
|
15
|
+
exports.isJust = isJust;
|
|
16
|
+
/**
|
|
17
|
+
* Type guard function to tell if the provided `monad` is `Nothing`.
|
|
18
|
+
*/
|
|
19
|
+
function isNothing(monad) {
|
|
20
|
+
return Object.prototype.hasOwnProperty.call(monad, nothing_1.nid);
|
|
21
|
+
}
|
|
22
|
+
exports.isNothing = isNothing;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.foldMap = exports.isNothing = exports.isJust = exports.fold = exports.bind = exports.fmap = void 0;
|
|
4
|
+
var fmap_1 = require("./fmap");
|
|
5
|
+
Object.defineProperty(exports, "fmap", { enumerable: true, get: function () { return fmap_1.default; } });
|
|
6
|
+
var bind_1 = require("./bind");
|
|
7
|
+
Object.defineProperty(exports, "bind", { enumerable: true, get: function () { return bind_1.default; } });
|
|
8
|
+
var fold_1 = require("./fold");
|
|
9
|
+
Object.defineProperty(exports, "fold", { enumerable: true, get: function () { return fold_1.default; } });
|
|
10
|
+
var guards_1 = require("./guards");
|
|
11
|
+
Object.defineProperty(exports, "isJust", { enumerable: true, get: function () { return guards_1.isJust; } });
|
|
12
|
+
Object.defineProperty(exports, "isNothing", { enumerable: true, get: function () { return guards_1.isNothing; } });
|
|
13
|
+
var fold_map_1 = require("./fold-map");
|
|
14
|
+
Object.defineProperty(exports, "foldMap", { enumerable: true, get: function () { return fold_map_1.default; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.permutation3 = exports.permutation2 = void 0;
|
|
4
|
+
var permutation_2_1 = require("./permutation-2");
|
|
5
|
+
Object.defineProperty(exports, "permutation2", { enumerable: true, get: function () { return permutation_2_1.default; } });
|
|
6
|
+
var permutation_3_1 = require("./permutation-3");
|
|
7
|
+
Object.defineProperty(exports, "permutation3", { enumerable: true, get: function () { return permutation_3_1.default; } });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Permutation
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
function permutation2(fn, shouldCurry) {
|
|
7
|
+
return function () {
|
|
8
|
+
var args = [];
|
|
9
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
10
|
+
args[_i] = arguments[_i];
|
|
11
|
+
}
|
|
12
|
+
var a1 = args[0], b = args[1];
|
|
13
|
+
return (shouldCurry === null || shouldCurry === void 0 ? void 0 : shouldCurry(a1, b)) || args.length < fn.length
|
|
14
|
+
? function (a2) { return fn(a2, a1); }
|
|
15
|
+
: fn(a1, b);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
exports.default = permutation2;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Permutation
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
function permutation3(fn, shouldCurry) {
|
|
7
|
+
return function () {
|
|
8
|
+
var args = [];
|
|
9
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
10
|
+
args[_i] = arguments[_i];
|
|
11
|
+
}
|
|
12
|
+
var a1 = args[0], b = args[1], c = args[2];
|
|
13
|
+
return (shouldCurry === null || shouldCurry === void 0 ? void 0 : shouldCurry(a1, b, c)) || args.length < fn.length
|
|
14
|
+
? function (a2) { return fn(a2, a1, b); }
|
|
15
|
+
: fn(a1, b, c);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
exports.default = permutation3;
|
package/cjs/pipe.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Composition
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/**
|
|
7
|
+
* Applies all of the provided `functions` one-by-one in left-to-right order
|
|
8
|
+
* starting from the `argument`.
|
|
9
|
+
*/
|
|
10
|
+
function pipe() {
|
|
11
|
+
var functions = [];
|
|
12
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
13
|
+
functions[_i] = arguments[_i];
|
|
14
|
+
}
|
|
15
|
+
return function (arg) {
|
|
16
|
+
var length = functions.length;
|
|
17
|
+
var pipeline = arg;
|
|
18
|
+
for (var index = 0; index < length; index += 1) {
|
|
19
|
+
var current = functions[index];
|
|
20
|
+
pipeline = current(pipeline);
|
|
21
|
+
}
|
|
22
|
+
return pipeline;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.default = pipe;
|
package/cjs/rethrow.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Side Effects
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var inject_1 = require("./inject");
|
|
7
|
+
/**
|
|
8
|
+
* Rethrows a received error
|
|
9
|
+
* performing an optional side effect.
|
|
10
|
+
*/
|
|
11
|
+
function rethrow(effect) {
|
|
12
|
+
return inject_1.default(function (error) {
|
|
13
|
+
throw error;
|
|
14
|
+
}, effect);
|
|
15
|
+
}
|
|
16
|
+
exports.default = rethrow;
|
package/cjs/tap.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Side Effects
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var inject_1 = require("./inject");
|
|
7
|
+
var identity_1 = require("./identity");
|
|
8
|
+
/**
|
|
9
|
+
* Performs a side effect
|
|
10
|
+
* passing the received argument through itself.
|
|
11
|
+
*/
|
|
12
|
+
function tap(effect) {
|
|
13
|
+
return inject_1.default(identity_1.default, effect);
|
|
14
|
+
}
|
|
15
|
+
exports.default = tap;
|
package/cjs/ternary.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Ternary
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/**
|
|
7
|
+
* Functional alternative to the ternary operator.
|
|
8
|
+
* Enforces the same return type for both branches,
|
|
9
|
+
* the result is evaluated lazily.
|
|
10
|
+
*/
|
|
11
|
+
function ternary(predicate, left, right) {
|
|
12
|
+
return function (value) {
|
|
13
|
+
return predicate(value) ? left(value) : right(value);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
exports.default = ternary;
|
package/compose.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module Composition
|
|
3
|
+
*/
|
|
4
|
+
import type { Last } from './types/last';
|
|
2
5
|
/**
|
|
3
6
|
* Creates a `Composition` type which parses all of the provided functions' types.
|
|
4
7
|
* Any function with either an incorrect argument or a return type will not fit
|
|
@@ -17,5 +20,4 @@ export declare type Composition<Functions extends Array<(...args: any[]) => any>
|
|
|
17
20
|
* Applies all of the provided `functions` one-by-one in right-to-left order
|
|
18
21
|
* starting from the `argument`.
|
|
19
22
|
*/
|
|
20
|
-
export
|
|
21
|
-
export default compose;
|
|
23
|
+
export default function compose<Functions extends Array<(arg: any) => any>>(...functions: Composition<Functions>): (arg: Parameters<Last<Functions>>[0]) => ReturnType<Functions[0]>;
|
package/curry.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module Curry
|
|
3
|
+
*/
|
|
4
|
+
import type { Slice } from './types/slice';
|
|
5
|
+
import type { Gradual } from './types/gradual';
|
|
3
6
|
/**
|
|
4
7
|
* Creates a type for an auto-curried function.
|
|
5
8
|
*/
|
|
@@ -12,5 +15,4 @@ export declare type Currying<Function extends (...args: any[]) => any, Length ex
|
|
|
12
15
|
* of arguments.
|
|
13
16
|
* Any excess arguments will not be applied.
|
|
14
17
|
*/
|
|
15
|
-
export
|
|
16
|
-
export default curry;
|
|
18
|
+
export default function curry<Function extends (...args: any[]) => any, Length extends number = Parameters<Function>['length']>(fn: Function, length?: Length): Currying<Function, Length>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either
|
|
3
|
+
*/
|
|
4
|
+
import type { Either } from './either';
|
|
5
|
+
/**
|
|
6
|
+
* Type constructor for `Either`.
|
|
7
|
+
* Creates either `Right` of the value provided,
|
|
8
|
+
* or `Left` of the thrown error.
|
|
9
|
+
*/
|
|
10
|
+
export default function eitherSync<LeftValue, RightValue>(value: () => RightValue): Either<LeftValue, RightValue>;
|
package/either/either.d.ts
CHANGED
|
@@ -1,49 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @module Either
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Type constructor for `Left`.
|
|
7
|
-
* Describes the special object with one property, represented as unique symbol
|
|
8
|
-
* key, holding the provided value type.
|
|
9
|
-
*/
|
|
10
|
-
export declare type Left<Value> = {
|
|
11
|
-
[lid]: Value;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Constructor function for `Left`.
|
|
15
|
-
* Creates the special object with one property, represented as unique symbol
|
|
16
|
-
* key, holding the provided value.
|
|
17
|
-
*/
|
|
18
|
-
export declare const left: <Value>(value: Value) => Left<Value>;
|
|
19
|
-
/**
|
|
20
|
-
* Internal unique identifier for `Right`.
|
|
21
|
-
*/
|
|
22
|
-
export declare const rid: unique symbol;
|
|
23
|
-
/**
|
|
24
|
-
* Type constructor for `Right`.
|
|
25
|
-
* Describes the special object with one property, represented as unique symbol
|
|
26
|
-
* key, holding the provided value type.
|
|
27
|
-
*/
|
|
28
|
-
export declare type Right<Value> = {
|
|
29
|
-
[rid]: Value;
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Constructor function for `Right`.
|
|
33
|
-
* Creates the special object with one property, represented as unique symbol
|
|
34
|
-
* key, holding the provided value.
|
|
35
|
-
*/
|
|
36
|
-
export declare const right: <Value>(value: Value) => Right<Value>;
|
|
4
|
+
import { Left } from './left';
|
|
5
|
+
import { Right } from './right';
|
|
37
6
|
/**
|
|
38
7
|
* Type constructor for `Either`.
|
|
39
|
-
*
|
|
40
|
-
* or `Left` of the
|
|
8
|
+
* Can be either `Right` of the value provided,
|
|
9
|
+
* or `Left` of the error thrown.
|
|
41
10
|
*/
|
|
42
11
|
export declare type Either<LeftValue, RightValue> = Left<LeftValue> | Right<RightValue>;
|
|
43
12
|
/**
|
|
44
13
|
* Type constructor for `Either`.
|
|
45
|
-
*
|
|
46
|
-
* or `Left` of the
|
|
14
|
+
* Creates either `Right` of the value provided,
|
|
15
|
+
* or `Left` of the error thrown.
|
|
47
16
|
*/
|
|
48
|
-
export
|
|
49
|
-
export default either;
|
|
17
|
+
export default function either<LeftValue, RightValue>(value: () => Promise<RightValue>): Promise<Either<LeftValue, RightValue>>;
|
package/either/index.d.ts
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
export { default,
|
|
1
|
+
export { default, Either } from './either';
|
|
2
|
+
export { default as left, Left } from './left';
|
|
3
|
+
export { default as right, Right } from './right';
|
|
4
|
+
export { default as eitherSync } from './either-sync';
|
package/either/left.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Internal unique identifier for `Left`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const lid: unique symbol;
|
|
8
|
+
/**
|
|
9
|
+
* Type constructor for `Left`.
|
|
10
|
+
* Describes the special object with one property, represented as unique symbol
|
|
11
|
+
* key, holding the provided value type.
|
|
12
|
+
*/
|
|
13
|
+
export declare type Left<Value> = {
|
|
14
|
+
[lid]: Value;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Constructor function for `Left`.
|
|
18
|
+
* Creates the special object with one property, represented as unique symbol
|
|
19
|
+
* key, holding the provided value.
|
|
20
|
+
*/
|
|
21
|
+
export default function left<Value>(value: Value): Left<Value>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
4
|
+
import type { Left } from '../../left';
|
|
5
|
+
import type { Right } from '../../right';
|
|
6
|
+
import type { Either } from '../../either';
|
|
7
|
+
/**
|
|
8
|
+
* A type to unwrap either the left or the right value type
|
|
9
|
+
* of the provided `Monad`.
|
|
10
|
+
*/
|
|
11
|
+
export declare type Bifold<Monad extends Either<any, any>> = Monad extends Left<infer LeftValue> ? LeftValue : Monad extends Right<infer RightValue> ? RightValue : never;
|
|
12
|
+
/**
|
|
13
|
+
* Unwraps either the left or the right value of the provided `monad`.
|
|
14
|
+
*/
|
|
15
|
+
export default function bifold<Monad extends Either<any, any>>(monad: Monad): Bifold<Monad>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
4
|
+
import { Left } from '../../left';
|
|
5
|
+
import type { Either } from '../../either';
|
|
6
|
+
/**
|
|
7
|
+
* A type to unwrap the left value type of the provided `Monad`.
|
|
8
|
+
* If the `Monad` is `Right`, returns `undefined`.
|
|
9
|
+
*/
|
|
10
|
+
export declare type Bifoldl<Monad extends Either<any, any>> = Monad extends Left<infer LeftValue> ? LeftValue : undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the left value of the provided `monad`.
|
|
13
|
+
* If the `monad` is `Right`, returns `undefined`.
|
|
14
|
+
*/
|
|
15
|
+
export default function bifoldl<Monad extends Either<any, any>>(monad: Monad): Bifoldl<Monad>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
4
|
+
import { Right } from '../../right';
|
|
5
|
+
import type { Either } from '../../either';
|
|
6
|
+
/**
|
|
7
|
+
* A type to unwrap the right value type of the provided `Monad`.
|
|
8
|
+
* If the `Monad` is `Left`, returns `undefined`.
|
|
9
|
+
*/
|
|
10
|
+
export declare type Bifoldr<Monad extends Either<any, any>> = Monad extends Right<infer RightValue> ? RightValue : undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the right value of the provided `monad`.
|
|
13
|
+
* If the `monad` is `Left`, returns `undefined`.
|
|
14
|
+
*/
|
|
15
|
+
export default function bifoldr<Monad extends Either<any, any>>(monad: Monad): Bifoldr<Monad>;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
1
4
|
import type { Either } from '../either';
|
|
2
|
-
import type { Map } from '
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import type { Map } from '../../types/map';
|
|
6
|
+
/**
|
|
7
|
+
* Maps left and right values of the provided `monad` to a value,
|
|
8
|
+
* then returns it.
|
|
9
|
+
*/
|
|
10
|
+
export default function bifoldMap<LeftValue, RightValue, MappedValue>(mapLeft: Map<LeftValue, MappedValue>, mapRight: Map<RightValue, MappedValue>): (monad: Either<LeftValue, RightValue>) => MappedValue;
|
|
7
11
|
/**
|
|
8
12
|
* Maps left and right values of the provided `monad` to a value,
|
|
9
13
|
* then returns it.
|
|
10
14
|
*/
|
|
11
|
-
export
|
|
12
|
-
export default bifoldMap;
|
|
15
|
+
export default function bifoldMap<LeftValue, RightValue, MappedValue>(monad: Either<LeftValue, RightValue>, mapLeft: Map<LeftValue, MappedValue>, mapRight: Map<RightValue, MappedValue>): MappedValue;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
4
|
+
import type { Either } from '../../either';
|
|
5
|
+
import type { Map } from '../../../types/map';
|
|
6
|
+
/**
|
|
7
|
+
* Maps left and right values of the provided `monad` to a new `Either` monad.
|
|
8
|
+
*/
|
|
9
|
+
export default function bimap<LeftValue, RightValue, NextLeftValue, NextRightValue>(mapLeft: Map<LeftValue, NextLeftValue>, mapRight: Map<RightValue, NextRightValue>): (monad: Either<LeftValue, RightValue>) => Either<NextLeftValue, NextRightValue>;
|
|
10
|
+
/**
|
|
11
|
+
* Maps left and right values of the provided `monad` to a new `Either` monad.
|
|
12
|
+
*/
|
|
13
|
+
export default function bimap<LeftValue, RightValue, NextLeftValue, NextRightValue>(monad: Either<LeftValue, RightValue>, mapLeft: Map<LeftValue, NextLeftValue>, mapRight: Map<RightValue, NextRightValue>): Either<NextLeftValue, NextRightValue>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
4
|
+
import type { Either } from '../../either';
|
|
5
|
+
import type { Map } from '../../../types/map';
|
|
6
|
+
/**
|
|
7
|
+
* Maps the left value of the provided `monad` to a new `Either` monad
|
|
8
|
+
* with the same right value.
|
|
9
|
+
*/
|
|
10
|
+
export default function first<LeftValue, RightValue, NextLeftValue>(mapLeft: Map<LeftValue, NextLeftValue>): (monad: Either<LeftValue, RightValue>) => Either<NextLeftValue, RightValue>;
|
|
11
|
+
/**
|
|
12
|
+
* Maps the left value of the provided `monad` to a new `Either` monad
|
|
13
|
+
* with the same right value.
|
|
14
|
+
*/
|
|
15
|
+
export default function first<LeftValue, RightValue, NextLeftValue>(monad: Either<LeftValue, RightValue>, mapLeft: Map<LeftValue, NextLeftValue>): Either<NextLeftValue, RightValue>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
4
|
+
import type { Either } from '../../either';
|
|
5
|
+
import type { Map } from '../../../types/map';
|
|
6
|
+
/**
|
|
7
|
+
* Maps the right value of the provided `monad` to a new `Either` monad
|
|
8
|
+
* with the same left value.
|
|
9
|
+
*/
|
|
10
|
+
export default function second<LeftValue, RightValue, NextRightValue>(mapRight: Map<RightValue, NextRightValue>): (monad: Either<LeftValue, RightValue>) => Either<LeftValue, NextRightValue>;
|
|
11
|
+
/**
|
|
12
|
+
* Maps the right value of the provided `monad` to a new `Either` monad
|
|
13
|
+
* with the same left value.
|
|
14
|
+
*/
|
|
15
|
+
export default function second<LeftValue, RightValue, NextRightValue>(monad: Either<LeftValue, RightValue>, mapRight: Map<RightValue, NextRightValue>): Either<LeftValue, NextRightValue>;
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
4
|
+
import { Left } from '../left';
|
|
5
|
+
import { Right } from '../right';
|
|
6
|
+
import type { Either } from '../either';
|
|
2
7
|
/**
|
|
3
8
|
* Type guard function to tell if the provided `monad` is `Left`.
|
|
4
9
|
*/
|
|
5
|
-
export declare
|
|
10
|
+
export declare function isLeft<LeftValue>(monad: Either<LeftValue, any>): monad is Left<LeftValue>;
|
|
6
11
|
/**
|
|
7
12
|
* Type guard function to tell if the provided `monad` is `Right`.
|
|
8
13
|
*/
|
|
9
|
-
export declare
|
|
14
|
+
export declare function isRight<RightValue>(monad: Either<any, RightValue>): monad is Right<RightValue>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from './bifold';
|
|
1
|
+
export { bifoldl, Bifoldl, bifoldr, Bifoldr, default as bifold, Bifold, } from './bifold';
|
|
3
2
|
export * from './guards';
|
|
4
|
-
export
|
|
3
|
+
export { default as bifoldMap } from './bifold-map';
|
|
4
|
+
export { default as bimap, first, second } from './bimap';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Internal unique identifier for `Right`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const rid: unique symbol;
|
|
8
|
+
/**
|
|
9
|
+
* Type constructor for `Right`.
|
|
10
|
+
* Describes the special object with one property, represented as unique symbol
|
|
11
|
+
* key, holding the provided value type.
|
|
12
|
+
*/
|
|
13
|
+
export declare type Right<Value> = {
|
|
14
|
+
[rid]: Value;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Constructor function for `Right`.
|
|
18
|
+
* Creates the special object with one property, represented as unique symbol
|
|
19
|
+
* key, holding the provided value.
|
|
20
|
+
*/
|
|
21
|
+
export default function right<Value>(value: Value): Right<Value>;
|
package/esm/compose.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Composition
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Applies all of the provided `functions` one-by-one in right-to-left order
|
|
6
|
+
* starting from the `argument`.
|
|
7
|
+
*/
|
|
8
|
+
export default function compose(...functions) {
|
|
9
|
+
return (arg) => {
|
|
10
|
+
const length = functions.length;
|
|
11
|
+
let composition = arg;
|
|
12
|
+
for (let index = length - 1; index >= 0; index -= 1) {
|
|
13
|
+
const current = functions[index];
|
|
14
|
+
composition = current(composition);
|
|
15
|
+
}
|
|
16
|
+
return composition;
|
|
17
|
+
};
|
|
18
|
+
}
|
package/esm/curry.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Curry
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Creates an auto-curried function from the one provided.
|
|
6
|
+
* Until the curried function receives an expected number of arguments,
|
|
7
|
+
* defined by either its `length` property or the `length` argument of `curry`,
|
|
8
|
+
* it will return new function which receives from one to the remaining amount
|
|
9
|
+
* of arguments.
|
|
10
|
+
* Any excess arguments will not be applied.
|
|
11
|
+
*/
|
|
12
|
+
export default function curry(fn, length = fn.length) {
|
|
13
|
+
return (...args) => {
|
|
14
|
+
const argsLength = args.length;
|
|
15
|
+
if (argsLength === length) {
|
|
16
|
+
return fn(...args);
|
|
17
|
+
}
|
|
18
|
+
if (argsLength > length) {
|
|
19
|
+
return fn(...args.slice(0, length));
|
|
20
|
+
}
|
|
21
|
+
return curry((...nextArgs) => fn(...args.concat(nextArgs)), length - argsLength);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either
|
|
3
|
+
*/
|
|
4
|
+
import left from './left';
|
|
5
|
+
import right from './right';
|
|
6
|
+
/**
|
|
7
|
+
* Type constructor for `Either`.
|
|
8
|
+
* Creates either `Right` of the value provided,
|
|
9
|
+
* or `Left` of the thrown error.
|
|
10
|
+
*/
|
|
11
|
+
export default function eitherSync(value) {
|
|
12
|
+
try {
|
|
13
|
+
return right(value());
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
return left(error);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either
|
|
3
|
+
*/
|
|
4
|
+
import left from './left';
|
|
5
|
+
import right from './right';
|
|
6
|
+
/**
|
|
7
|
+
* Type constructor for `Either`.
|
|
8
|
+
* Creates either `Right` of the value provided,
|
|
9
|
+
* or `Left` of the error thrown.
|
|
10
|
+
*/
|
|
11
|
+
export default function either(value) {
|
|
12
|
+
return value()
|
|
13
|
+
.then(right)
|
|
14
|
+
.catch(left);
|
|
15
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Internal unique identifier for `Left`.
|
|
6
|
+
*/
|
|
7
|
+
export const lid = Symbol.for('@@functional/left');
|
|
8
|
+
/**
|
|
9
|
+
* Constructor function for `Left`.
|
|
10
|
+
* Creates the special object with one property, represented as unique symbol
|
|
11
|
+
* key, holding the provided value.
|
|
12
|
+
*/
|
|
13
|
+
export default function left(value) {
|
|
14
|
+
return {
|
|
15
|
+
[lid]: value
|
|
16
|
+
};
|
|
17
|
+
}
|