fnts 1.8.0 → 2.0.0-rc.1
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/compose.d.ts +4 -13
- package/compose.js +3 -14
- package/either/left.d.ts +1 -1
- package/either/operators/bifold/bifold.d.ts +4 -4
- package/either/operators/bifold/bifold.js +6 -4
- package/either/operators/bifold/bifoldl.d.ts +2 -2
- package/either/operators/bifold/bifoldl.js +2 -2
- package/either/operators/bifold/bifoldr.d.ts +2 -2
- package/either/operators/bifold/bifoldr.js +2 -2
- package/either/operators/{bifold-map.d.ts → bifold-map/bifold-map.d.ts} +2 -2
- package/either/operators/{bifold-map.js → bifold-map/bifold-map.js} +8 -6
- package/either/operators/bifold-map/bifoldl-map.d.ts +15 -0
- package/either/operators/bifold-map/bifoldl-map.js +20 -0
- package/either/operators/bifold-map/bifoldr-map.d.ts +15 -0
- package/either/operators/bifold-map/bifoldr-map.js +20 -0
- package/either/operators/bifold-map/index.d.ts +3 -0
- package/either/operators/bifold-map/index.js +9 -0
- package/either/operators/bimap/first.js +2 -2
- package/either/operators/bimap/second.js +2 -2
- package/either/operators/guards.d.ts +4 -4
- package/either/operators/guards.js +6 -6
- package/either/right.d.ts +1 -1
- package/guard.d.ts +1 -1
- package/guard.js +2 -2
- package/maybe/just.d.ts +2 -2
- package/maybe/maybe.d.ts +1 -6
- package/maybe/nothing.d.ts +1 -1
- package/maybe/nothing.js +1 -1
- package/maybe/operators/bind.d.ts +2 -2
- package/maybe/operators/fmap.d.ts +2 -2
- package/maybe/operators/fmap.js +2 -2
- package/maybe/operators/fold-map.d.ts +3 -3
- package/maybe/operators/fold-map.js +1 -1
- package/maybe/operators/fold.d.ts +2 -2
- package/maybe/operators/guards.d.ts +4 -4
- package/maybe/operators/guards.js +6 -6
- package/package.json +1 -1
- package/pipe.d.ts +4 -13
- package/pipe.js +3 -14
package/compose.d.ts
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Composition
|
|
3
3
|
*/
|
|
4
|
-
import type { Last } from './types/last';
|
|
5
|
-
import type { UnaryFunction, VariadicFunction } from './types/function';
|
|
6
4
|
/**
|
|
7
|
-
*
|
|
8
|
-
* Any function with either an incorrect argument or a return type will not fit
|
|
9
|
-
* into the composition and should be typed according to it, so that its argument's
|
|
10
|
-
* type matches the return type of the next function and its return type
|
|
11
|
-
* matches the type of the previous function's argument.
|
|
5
|
+
* Applies first onto second onto args.
|
|
12
6
|
*/
|
|
13
|
-
export
|
|
14
|
-
...Composition<Rest extends UnaryFunction[] ? Last extends UnaryFunction ? Penultimate extends UnaryFunction ? [...Rest, (arg: ReturnType<Last>) => ReturnType<Penultimate>] : never : Last extends VariadicFunction ? Penultimate extends UnaryFunction ? [...Rest, (arg: ReturnType<Last>) => ReturnType<Penultimate>] : never : never : never>,
|
|
15
|
-
Last
|
|
16
|
-
] : Functions;
|
|
7
|
+
export default function compose<First, Argument, Return>(first: (arg: First) => Return, second: (arg: Argument) => First): (arg: Argument) => Return;
|
|
17
8
|
/**
|
|
18
|
-
* Applies
|
|
9
|
+
* Applies first onto second onto args.
|
|
19
10
|
*/
|
|
20
|
-
export default function compose<
|
|
11
|
+
export default function compose<First, Arguments extends any[], Return>(first: (arg: First) => Return, second: (...args: Arguments) => First): (...args: Arguments) => Return;
|
package/compose.js
CHANGED
|
@@ -4,26 +4,15 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
/**
|
|
7
|
-
* Applies
|
|
7
|
+
* Applies first onto second onto args.
|
|
8
8
|
*/
|
|
9
|
-
function compose() {
|
|
10
|
-
var functions = [];
|
|
11
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
12
|
-
functions[_i] = arguments[_i];
|
|
13
|
-
}
|
|
9
|
+
function compose(first, second) {
|
|
14
10
|
return function () {
|
|
15
11
|
var args = [];
|
|
16
12
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
17
13
|
args[_i] = arguments[_i];
|
|
18
14
|
}
|
|
19
|
-
|
|
20
|
-
var composition = functions[length - 1].apply(functions, args);
|
|
21
|
-
if (length > 1) {
|
|
22
|
-
for (var index = length - 2; index >= 0; index -= 1) {
|
|
23
|
-
composition = functions[index](composition);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return composition;
|
|
15
|
+
return first(second.apply(void 0, args));
|
|
27
16
|
};
|
|
28
17
|
}
|
|
29
18
|
exports.default = compose;
|
package/either/left.d.ts
CHANGED
|
@@ -18,4 +18,4 @@ export declare type Left<Value> = {
|
|
|
18
18
|
* Creates the special object with one property, represented as unique symbol
|
|
19
19
|
* key, holding the provided value.
|
|
20
20
|
*/
|
|
21
|
-
export default function left<Value>(value
|
|
21
|
+
export default function left<Value = undefined>(value?: Value): Left<Value>;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Either Operators
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import { Left } from '../../left';
|
|
5
|
+
import { Right } from '../../right';
|
|
6
6
|
import type { Either } from '../../either';
|
|
7
7
|
/**
|
|
8
8
|
* A type to unwrap either the left or the right value type
|
|
9
9
|
* of the provided `Monad`.
|
|
10
10
|
*/
|
|
11
|
-
export declare type Bifold<Monad extends Either<any, any>> = Monad extends Left<infer LeftValue> ? LeftValue : Monad extends Right<infer RightValue> ? RightValue : never;
|
|
11
|
+
export declare type Bifold<Monad extends Either<any, any>> = Monad extends Left<infer LeftValue> ? LeftValue : Monad extends Right<infer RightValue> ? RightValue : Monad extends Either<infer LeftValue, infer RightValue> ? LeftValue | RightValue : never;
|
|
12
12
|
/**
|
|
13
13
|
* Unwraps either the left or the right value of the provided `monad`.
|
|
14
14
|
*/
|
|
15
|
-
export default function bifold<
|
|
15
|
+
export default function bifold<LeftValue, RightValue>(monad: Either<LeftValue, RightValue>): LeftValue | RightValue;
|
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
* @module Either Operators
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var
|
|
7
|
-
var
|
|
6
|
+
var guards_1 = require("../guards");
|
|
7
|
+
var left_1 = require("../../left");
|
|
8
|
+
var right_1 = require("../../right");
|
|
8
9
|
/**
|
|
9
10
|
* Unwraps either the left or the right value of the provided `monad`.
|
|
10
11
|
*/
|
|
11
12
|
function bifold(monad) {
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
return (0, guards_1.isLeft)(monad)
|
|
14
|
+
? monad[left_1.lid]
|
|
15
|
+
: monad[right_1.rid];
|
|
14
16
|
}
|
|
15
17
|
exports.default = bifold;
|
|
@@ -7,9 +7,9 @@ import type { Either } from '../../either';
|
|
|
7
7
|
* A type to unwrap the left value type of the provided `Monad`.
|
|
8
8
|
* If the `Monad` is `Right`, returns `undefined`.
|
|
9
9
|
*/
|
|
10
|
-
export declare type Bifoldl<Monad extends Either<any, any>> = Monad extends Left<infer LeftValue> ? LeftValue : undefined;
|
|
10
|
+
export declare type Bifoldl<Monad extends Either<any, any>> = Monad extends Left<infer LeftValue> ? LeftValue : Monad extends Either<infer LeftValue, any> ? LeftValue | undefined : never;
|
|
11
11
|
/**
|
|
12
12
|
* Returns the left value of the provided `monad`.
|
|
13
13
|
* If the `monad` is `Right`, returns `undefined`.
|
|
14
14
|
*/
|
|
15
|
-
export default function bifoldl<
|
|
15
|
+
export default function bifoldl<LeftValue>(monad: Either<LeftValue, any>): LeftValue | undefined;
|
|
@@ -10,8 +10,8 @@ var left_1 = require("../../left");
|
|
|
10
10
|
* If the `monad` is `Right`, returns `undefined`.
|
|
11
11
|
*/
|
|
12
12
|
function bifoldl(monad) {
|
|
13
|
-
return (
|
|
13
|
+
return (0, guards_1.isLeft)(monad)
|
|
14
14
|
? monad[left_1.lid]
|
|
15
|
-
: undefined
|
|
15
|
+
: undefined;
|
|
16
16
|
}
|
|
17
17
|
exports.default = bifoldl;
|
|
@@ -7,9 +7,9 @@ import type { Either } from '../../either';
|
|
|
7
7
|
* A type to unwrap the right value type of the provided `Monad`.
|
|
8
8
|
* If the `Monad` is `Left`, returns `undefined`.
|
|
9
9
|
*/
|
|
10
|
-
export declare type Bifoldr<Monad extends Either<any, any>> = Monad extends Right<infer RightValue> ? RightValue : undefined;
|
|
10
|
+
export declare type Bifoldr<Monad extends Either<any, any>> = Monad extends Right<infer RightValue> ? RightValue : Monad extends Either<any, infer RightValue> ? RightValue | undefined : never;
|
|
11
11
|
/**
|
|
12
12
|
* Returns the right value of the provided `monad`.
|
|
13
13
|
* If the `monad` is `Left`, returns `undefined`.
|
|
14
14
|
*/
|
|
15
|
-
export default function bifoldr<
|
|
15
|
+
export default function bifoldr<RightValue>(monad: Either<any, RightValue>): RightValue | undefined;
|
|
@@ -10,8 +10,8 @@ var right_1 = require("../../right");
|
|
|
10
10
|
* If the `monad` is `Left`, returns `undefined`.
|
|
11
11
|
*/
|
|
12
12
|
function bifoldr(monad) {
|
|
13
|
-
return (
|
|
13
|
+
return (0, guards_1.isRight)(monad)
|
|
14
14
|
? monad[right_1.rid]
|
|
15
|
-
: undefined
|
|
15
|
+
: undefined;
|
|
16
16
|
}
|
|
17
17
|
exports.default = bifoldr;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Either Operators
|
|
3
3
|
*/
|
|
4
|
-
import type { Either } from '
|
|
5
|
-
import type { Map } from '
|
|
4
|
+
import type { Either } from '../../either';
|
|
5
|
+
import type { Map } from '../../../types/map';
|
|
6
6
|
/**
|
|
7
7
|
* Maps provided `monad` to a value,
|
|
8
8
|
* then returns it.
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
* @module Either Operators
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var compose_1 = require("
|
|
7
|
-
var ternary_1 = require("
|
|
8
|
-
var permutation_3_1 = require("
|
|
9
|
-
var
|
|
10
|
-
var
|
|
6
|
+
var compose_1 = require("../../../compose");
|
|
7
|
+
var ternary_1 = require("../../../ternary");
|
|
8
|
+
var permutation_3_1 = require("../../../permutation/permutation-3");
|
|
9
|
+
var bifold_1 = require("../bifold");
|
|
10
|
+
var bifoldl_map_1 = require("./bifoldl-map");
|
|
11
|
+
var bifoldr_map_1 = require("./bifoldr-map");
|
|
12
|
+
var guards_1 = require("../guards");
|
|
11
13
|
function bifoldMap() {
|
|
12
14
|
var args = [];
|
|
13
15
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -22,7 +24,7 @@ function bifoldMap() {
|
|
|
22
24
|
return (0, compose_1.default)(args[1], bifold_1.default)(args[0]);
|
|
23
25
|
}
|
|
24
26
|
return (0, permutation_3_1.default)(function (monad, mapLeft, mapRight) {
|
|
25
|
-
return (0, ternary_1.default)(guards_1.isLeft, (0,
|
|
27
|
+
return (0, ternary_1.default)(guards_1.isLeft, (0, bifoldl_map_1.default)(mapLeft), (0, bifoldr_map_1.default)(mapRight))(monad);
|
|
26
28
|
}).apply(void 0, args);
|
|
27
29
|
}
|
|
28
30
|
exports.default = bifoldMap;
|
|
@@ -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 provided `monad`'s left value to a new value,
|
|
8
|
+
* then returns it or `undefined`.
|
|
9
|
+
*/
|
|
10
|
+
export default function bifoldlMap<LeftValue, Value>(map: Map<LeftValue, Value>): (monad: Either<LeftValue, any>) => Value | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Maps provided `monad`'s left value to a new value,
|
|
13
|
+
* then returns it or `undefined`.
|
|
14
|
+
*/
|
|
15
|
+
export default function bifoldlMap<LeftValue, Value>(monad: Either<LeftValue, any>, map: Map<LeftValue, Value>): Value | undefined;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Either 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 guards_1 = require("../guards");
|
|
10
|
+
var bifold_1 = require("../bifold");
|
|
11
|
+
function bifoldlMap() {
|
|
12
|
+
var args = [];
|
|
13
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
14
|
+
args[_i] = arguments[_i];
|
|
15
|
+
}
|
|
16
|
+
return (0, permutation_2_1.default)(function (monad, map) {
|
|
17
|
+
return (0, ternary_1.default)(guards_1.isLeft, (0, compose_1.default)(map, bifold_1.bifoldl), function () { return undefined; })(monad);
|
|
18
|
+
}).apply(void 0, args);
|
|
19
|
+
}
|
|
20
|
+
exports.default = bifoldlMap;
|
|
@@ -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 provided `monad`'s right value to a new value,
|
|
8
|
+
* then returns it or `undefined`.
|
|
9
|
+
*/
|
|
10
|
+
export default function bifoldrMap<RightValue, Value>(map: Map<RightValue, Value>): (monad: Either<any, RightValue>) => Value | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Maps provided `monad`'s right value to a new value,
|
|
13
|
+
* then returns it or `undefined`.
|
|
14
|
+
*/
|
|
15
|
+
export default function bifoldrMap<RightValue, Value>(monad: Either<any, RightValue>, map: Map<RightValue, Value>): Value | undefined;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Either 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 guards_1 = require("../guards");
|
|
10
|
+
var bifold_1 = require("../bifold");
|
|
11
|
+
function bifoldrMap() {
|
|
12
|
+
var args = [];
|
|
13
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
14
|
+
args[_i] = arguments[_i];
|
|
15
|
+
}
|
|
16
|
+
return (0, permutation_2_1.default)(function (monad, map) {
|
|
17
|
+
return (0, ternary_1.default)(guards_1.isRight, (0, compose_1.default)(map, bifold_1.bifoldr), function () { return undefined; })(monad);
|
|
18
|
+
}).apply(void 0, args);
|
|
19
|
+
}
|
|
20
|
+
exports.default = bifoldrMap;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bifoldrMap = exports.bifoldlMap = exports.default = void 0;
|
|
4
|
+
var bifold_map_1 = require("./bifold-map");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return bifold_map_1.default; } });
|
|
6
|
+
var bifoldl_map_1 = require("./bifoldl-map");
|
|
7
|
+
Object.defineProperty(exports, "bifoldlMap", { enumerable: true, get: function () { return bifoldl_map_1.default; } });
|
|
8
|
+
var bifoldr_map_1 = require("./bifoldr-map");
|
|
9
|
+
Object.defineProperty(exports, "bifoldrMap", { enumerable: true, get: function () { return bifoldr_map_1.default; } });
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* @module Either Operators
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var left_1 = require("../../left");
|
|
6
7
|
var guards_1 = require("../guards");
|
|
7
8
|
var bifold_1 = require("../bifold");
|
|
8
9
|
var compose_1 = require("../../../compose");
|
|
9
10
|
var ternary_1 = require("../../../ternary");
|
|
10
|
-
var left_1 = require("../../left");
|
|
11
11
|
var identity_1 = require("../../../identity");
|
|
12
12
|
var permutation_2_1 = require("../../../permutation/permutation-2");
|
|
13
13
|
function first() {
|
|
@@ -16,7 +16,7 @@ function first() {
|
|
|
16
16
|
args[_i] = arguments[_i];
|
|
17
17
|
}
|
|
18
18
|
return (0, permutation_2_1.default)(function (monad, mapLeft) {
|
|
19
|
-
return (0, ternary_1.default)(guards_1.isLeft, (0, compose_1.default)(left_1.default, mapLeft, bifold_1.bifoldl), identity_1.default)(monad);
|
|
19
|
+
return (0, ternary_1.default)(guards_1.isLeft, (0, compose_1.default)((0, compose_1.default)(left_1.default, mapLeft), bifold_1.bifoldl), identity_1.default)(monad);
|
|
20
20
|
}).apply(void 0, args);
|
|
21
21
|
}
|
|
22
22
|
exports.default = first;
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
* @module Either Operators
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var right_1 = require("../../right");
|
|
6
7
|
var bifold_1 = require("../bifold");
|
|
7
8
|
var guards_1 = require("../guards");
|
|
8
9
|
var compose_1 = require("../../../compose");
|
|
9
10
|
var ternary_1 = require("../../../ternary");
|
|
10
11
|
var identity_1 = require("../../../identity");
|
|
11
|
-
var right_1 = require("../../right");
|
|
12
12
|
var permutation_2_1 = require("../../../permutation/permutation-2");
|
|
13
13
|
function second() {
|
|
14
14
|
var args = [];
|
|
@@ -16,7 +16,7 @@ function second() {
|
|
|
16
16
|
args[_i] = arguments[_i];
|
|
17
17
|
}
|
|
18
18
|
return (0, permutation_2_1.default)(function (monad, mapRight) {
|
|
19
|
-
return (0, ternary_1.default)(guards_1.isRight, (0, compose_1.default)(right_1.default, mapRight, bifold_1.bifoldr), identity_1.default)(monad);
|
|
19
|
+
return (0, ternary_1.default)(guards_1.isRight, (0, compose_1.default)((0, compose_1.default)(right_1.default, mapRight), bifold_1.bifoldr), identity_1.default)(monad);
|
|
20
20
|
}).apply(void 0, args);
|
|
21
21
|
}
|
|
22
22
|
exports.default = second;
|
|
@@ -5,13 +5,13 @@ import { Left } from '../left';
|
|
|
5
5
|
import { Right } from '../right';
|
|
6
6
|
import type { Either } from '../either';
|
|
7
7
|
/**
|
|
8
|
-
* Type guard function to tell if the provided `
|
|
8
|
+
* Type guard function to tell if the provided `value` is `Left`.
|
|
9
9
|
*/
|
|
10
|
-
export declare function isLeft<LeftValue>(
|
|
10
|
+
export declare function isLeft<LeftValue>(value: any): value is Left<LeftValue>;
|
|
11
11
|
/**
|
|
12
|
-
* Type guard function to tell if the provided `
|
|
12
|
+
* Type guard function to tell if the provided `value` is `Right`.
|
|
13
13
|
*/
|
|
14
|
-
export declare function isRight<RightValue>(
|
|
14
|
+
export declare function isRight<RightValue>(value: any): value is Right<RightValue>;
|
|
15
15
|
/**
|
|
16
16
|
* Type guard function to tell if the provided `value` is `Either`.
|
|
17
17
|
*/
|
|
@@ -7,17 +7,17 @@ exports.isEither = exports.isRight = exports.isLeft = void 0;
|
|
|
7
7
|
var left_1 = require("../left");
|
|
8
8
|
var right_1 = require("../right");
|
|
9
9
|
/**
|
|
10
|
-
* Type guard function to tell if the provided `
|
|
10
|
+
* Type guard function to tell if the provided `value` is `Left`.
|
|
11
11
|
*/
|
|
12
|
-
function isLeft(
|
|
13
|
-
return Object.prototype.hasOwnProperty.call(
|
|
12
|
+
function isLeft(value) {
|
|
13
|
+
return Object.prototype.hasOwnProperty.call(value, left_1.lid);
|
|
14
14
|
}
|
|
15
15
|
exports.isLeft = isLeft;
|
|
16
16
|
/**
|
|
17
|
-
* Type guard function to tell if the provided `
|
|
17
|
+
* Type guard function to tell if the provided `value` is `Right`.
|
|
18
18
|
*/
|
|
19
|
-
function isRight(
|
|
20
|
-
return Object.prototype.hasOwnProperty.call(
|
|
19
|
+
function isRight(value) {
|
|
20
|
+
return Object.prototype.hasOwnProperty.call(value, right_1.rid);
|
|
21
21
|
}
|
|
22
22
|
exports.isRight = isRight;
|
|
23
23
|
/**
|
package/either/right.d.ts
CHANGED
|
@@ -18,4 +18,4 @@ export declare type Right<Value> = {
|
|
|
18
18
|
* Creates the special object with one property, represented as unique symbol
|
|
19
19
|
* key, holding the provided value.
|
|
20
20
|
*/
|
|
21
|
-
export default function right<Value>(value
|
|
21
|
+
export default function right<Value = undefined>(value?: Value): Right<Value>;
|
package/guard.d.ts
CHANGED
|
@@ -16,4 +16,4 @@ export declare type GuardQualifier<Function extends VariadicFunction> = [
|
|
|
16
16
|
*
|
|
17
17
|
* When no `validator` succeeds, the default executor is run.
|
|
18
18
|
*/
|
|
19
|
-
export default function guard<Function extends VariadicFunction>(...qualifiers: [...GuardQualifier<Function>[], Function]):
|
|
19
|
+
export default function guard<Function extends VariadicFunction>(...qualifiers: [...GuardQualifier<Function>[], Function]): Function;
|
package/guard.js
CHANGED
|
@@ -18,7 +18,7 @@ function guard() {
|
|
|
18
18
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
19
19
|
qualifiers[_i] = arguments[_i];
|
|
20
20
|
}
|
|
21
|
-
return function () {
|
|
21
|
+
return (function () {
|
|
22
22
|
var args = [];
|
|
23
23
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
24
24
|
args[_i] = arguments[_i];
|
|
@@ -31,6 +31,6 @@ function guard() {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
return qualifiers[length].apply(qualifiers, args);
|
|
34
|
-
};
|
|
34
|
+
});
|
|
35
35
|
}
|
|
36
36
|
exports.default = guard;
|
package/maybe/just.d.ts
CHANGED
|
@@ -11,11 +11,11 @@ export declare const jid: unique symbol;
|
|
|
11
11
|
* key, holding the provided value type.
|
|
12
12
|
*/
|
|
13
13
|
export declare type Just<Value> = {
|
|
14
|
-
[jid]:
|
|
14
|
+
[jid]: Value;
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* Constructor function for `Just`.
|
|
18
18
|
* Creates the special object with one property, represented as unique symbol
|
|
19
19
|
* key, holding the provided value.
|
|
20
20
|
*/
|
|
21
|
-
export default function just<Value
|
|
21
|
+
export default function just<Value>(value: Value): Just<Value>;
|
package/maybe/maybe.d.ts
CHANGED
|
@@ -12,9 +12,4 @@ export declare type Maybe<Value> = Just<Value> | Nothing;
|
|
|
12
12
|
* Constructor function for `Maybe`.
|
|
13
13
|
* Creates either `just` of a provided value, or `nothing`.
|
|
14
14
|
*/
|
|
15
|
-
export default function maybe(value: null | undefined):
|
|
16
|
-
/**
|
|
17
|
-
* Constructor function for `Maybe`.
|
|
18
|
-
* Creates either `just` of a provided value, or `nothing`.
|
|
19
|
-
*/
|
|
20
|
-
export default function maybe<Value>(value: Value | null | undefined): Just<Value>;
|
|
15
|
+
export default function maybe<Value>(value: Value | null | undefined): Maybe<Value>;
|
package/maybe/nothing.d.ts
CHANGED
package/maybe/nothing.js
CHANGED
|
@@ -16,7 +16,7 @@ exports.nid = Symbol.for('@@functional/nothing');
|
|
|
16
16
|
function nothing() {
|
|
17
17
|
var _a;
|
|
18
18
|
return _a = {},
|
|
19
|
-
_a[exports.nid] =
|
|
19
|
+
_a[exports.nid] = undefined,
|
|
20
20
|
// @ts-expect-error: Undocumented API for external use
|
|
21
21
|
_a.toString = function () {
|
|
22
22
|
return 'Nothing';
|
|
@@ -7,9 +7,9 @@ import type { Map } from '../../types/map';
|
|
|
7
7
|
* Binds the value of the `monad` to new monad created
|
|
8
8
|
* by the `transition` function.
|
|
9
9
|
*/
|
|
10
|
-
export default function bind<Value, NextValue>(map: Map<Value, Maybe<NextValue>>): (monad: Maybe<Value>) => Maybe<
|
|
10
|
+
export default function bind<Value, NextValue>(map: Map<Value, Maybe<NextValue>>): (monad: Maybe<Value>) => Maybe<NextValue>;
|
|
11
11
|
/**
|
|
12
12
|
* Binds the value of the `monad` to new monad created
|
|
13
13
|
* by the `transition` function.
|
|
14
14
|
*/
|
|
15
|
-
export default function bind<Value, NextValue>(monad: Maybe<Value>, map: Map<Value, Maybe<NextValue>>): Maybe<
|
|
15
|
+
export default function bind<Value, NextValue>(monad: Maybe<Value>, map: Map<Value, Maybe<NextValue>>): Maybe<NextValue>;
|
|
@@ -7,9 +7,9 @@ import type { Map } from '../../types/map';
|
|
|
7
7
|
* Maps the value of the provided `monad` through the `transition` function
|
|
8
8
|
* and returns a new `Maybe` of the mapped value.
|
|
9
9
|
*/
|
|
10
|
-
export default function fmap<Value, NextValue
|
|
10
|
+
export default function fmap<Value, NextValue>(map: Map<Value, NextValue>): (monad: Maybe<Value>) => Maybe<NextValue>;
|
|
11
11
|
/**
|
|
12
12
|
* Maps the value of the provided `monad` through the `transition` function
|
|
13
13
|
* and returns a new `Maybe` of the mapped value.
|
|
14
14
|
*/
|
|
15
|
-
export default function fmap<Value, NextValue
|
|
15
|
+
export default function fmap<Value, NextValue>(monad: Maybe<Value>, map: Map<Value, NextValue>): Maybe<NextValue>;
|
package/maybe/operators/fmap.js
CHANGED
|
@@ -7,7 +7,7 @@ var compose_1 = require("../../compose");
|
|
|
7
7
|
var identity_1 = require("../../identity");
|
|
8
8
|
var maybe_1 = require("../maybe");
|
|
9
9
|
var permutation_2_1 = require("../../permutation/permutation-2");
|
|
10
|
-
var
|
|
10
|
+
var fold_map_1 = require("./fold-map");
|
|
11
11
|
var guards_1 = require("./guards");
|
|
12
12
|
var ternary_1 = require("../../ternary");
|
|
13
13
|
function fmap() {
|
|
@@ -16,7 +16,7 @@ function fmap() {
|
|
|
16
16
|
args[_i] = arguments[_i];
|
|
17
17
|
}
|
|
18
18
|
return (0, permutation_2_1.default)(function (monad, map) {
|
|
19
|
-
return (0, ternary_1.default)(guards_1.isJust, (0, compose_1.default)(maybe_1.default,
|
|
19
|
+
return (0, ternary_1.default)(guards_1.isJust, (0, compose_1.default)((maybe_1.default), (0, fold_map_1.default)(map)), identity_1.default)(monad);
|
|
20
20
|
}).apply(void 0, args);
|
|
21
21
|
}
|
|
22
22
|
exports.default = fmap;
|
|
@@ -8,14 +8,14 @@ import type { Map } from '../../types/map';
|
|
|
8
8
|
/**
|
|
9
9
|
* A type to unwrap the provided `Monad` into the new value type.
|
|
10
10
|
*/
|
|
11
|
-
export declare type FoldMap<Monad extends Maybe<any>, NextValue> = Monad extends Just<any> ?
|
|
11
|
+
export declare type FoldMap<Monad extends Maybe<any>, NextValue> = Monad extends Just<any> ? NextValue : Monad extends Nothing ? undefined : Monad extends Maybe<any> ? NextValue | undefined : never;
|
|
12
12
|
/**
|
|
13
13
|
* Maps the value of the provided `monad` through the `transition` function
|
|
14
14
|
* and returns the mapped value or `null`.
|
|
15
15
|
*/
|
|
16
|
-
export default function foldMap<Value, NextValue = Value>(map: Map<Value, NextValue>): (monad: Maybe<Value>) =>
|
|
16
|
+
export default function foldMap<Value, NextValue = Value>(map: Map<Value, NextValue>): (monad: Maybe<Value>) => NextValue | undefined;
|
|
17
17
|
/**
|
|
18
18
|
* Maps the value of the provided `monad` through the `transition` function
|
|
19
19
|
* and returns the mapped value or `null`.
|
|
20
20
|
*/
|
|
21
|
-
export default function foldMap<Value, NextValue = Value>(monad: Maybe<Value>, map: Map<Value, NextValue>):
|
|
21
|
+
export default function foldMap<Value, NextValue = Value>(monad: Maybe<Value>, map: Map<Value, NextValue>): NextValue | undefined;
|
|
@@ -14,7 +14,7 @@ function foldMap() {
|
|
|
14
14
|
args[_i] = arguments[_i];
|
|
15
15
|
}
|
|
16
16
|
return (0, permutation_2_1.default)(function (monad, map) {
|
|
17
|
-
return (0, ternary_1.default)(guards_1.isJust, (0, compose_1.default)(map, fold_1.default), function () { return
|
|
17
|
+
return (0, ternary_1.default)(guards_1.isJust, (0, compose_1.default)(map, fold_1.default), function () { return undefined; })(monad);
|
|
18
18
|
}).apply(void 0, args);
|
|
19
19
|
}
|
|
20
20
|
exports.default = foldMap;
|
|
@@ -7,8 +7,8 @@ import { Nothing } from '../nothing';
|
|
|
7
7
|
/**
|
|
8
8
|
* A type to unwrap the value type of the provided `Monad`.
|
|
9
9
|
*/
|
|
10
|
-
export declare type Fold<Monad extends Maybe<any>> = Monad extends Just<infer Value> ? Value : Monad extends Nothing ?
|
|
10
|
+
export declare type Fold<Monad extends Maybe<any>> = Monad extends Just<infer Value> ? Value : Monad extends Nothing ? undefined : Monad extends Maybe<infer Value> ? Value | undefined : never;
|
|
11
11
|
/**
|
|
12
12
|
* Returns the value of the provided `monad`.
|
|
13
13
|
*/
|
|
14
|
-
export default function fold<
|
|
14
|
+
export default function fold<Value>(monad: Maybe<Value>): Value | undefined;
|
|
@@ -5,13 +5,13 @@ import { Just } from '../just';
|
|
|
5
5
|
import type { Maybe } from '../maybe';
|
|
6
6
|
import { Nothing } from '../nothing';
|
|
7
7
|
/**
|
|
8
|
-
* Type guard function to tell if the provided `
|
|
8
|
+
* Type guard function to tell if the provided `value` is `Just`.
|
|
9
9
|
*/
|
|
10
|
-
export declare function isJust<Value>(
|
|
10
|
+
export declare function isJust<Value>(value: any): value is Just<Value>;
|
|
11
11
|
/**
|
|
12
|
-
* Type guard function to tell if the provided `
|
|
12
|
+
* Type guard function to tell if the provided `value` is `Nothing`.
|
|
13
13
|
*/
|
|
14
|
-
export declare function isNothing
|
|
14
|
+
export declare function isNothing(value: any): value is Nothing;
|
|
15
15
|
/**
|
|
16
16
|
* Type guard function to tell if the provided `value` is `Maybe`.
|
|
17
17
|
*/
|
|
@@ -7,17 +7,17 @@ exports.isMaybe = exports.isNothing = exports.isJust = void 0;
|
|
|
7
7
|
var just_1 = require("../just");
|
|
8
8
|
var nothing_1 = require("../nothing");
|
|
9
9
|
/**
|
|
10
|
-
* Type guard function to tell if the provided `
|
|
10
|
+
* Type guard function to tell if the provided `value` is `Just`.
|
|
11
11
|
*/
|
|
12
|
-
function isJust(
|
|
13
|
-
return Object.prototype.hasOwnProperty.call(
|
|
12
|
+
function isJust(value) {
|
|
13
|
+
return Object.prototype.hasOwnProperty.call(value, just_1.jid);
|
|
14
14
|
}
|
|
15
15
|
exports.isJust = isJust;
|
|
16
16
|
/**
|
|
17
|
-
* Type guard function to tell if the provided `
|
|
17
|
+
* Type guard function to tell if the provided `value` is `Nothing`.
|
|
18
18
|
*/
|
|
19
|
-
function isNothing(
|
|
20
|
-
return Object.prototype.hasOwnProperty.call(
|
|
19
|
+
function isNothing(value) {
|
|
20
|
+
return Object.prototype.hasOwnProperty.call(value, nothing_1.nid);
|
|
21
21
|
}
|
|
22
22
|
exports.isNothing = isNothing;
|
|
23
23
|
/**
|
package/package.json
CHANGED
package/pipe.d.ts
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Composition
|
|
3
3
|
*/
|
|
4
|
-
import type { Last } from './types/last';
|
|
5
|
-
import type { UnaryFunction, VariadicFunction } from './types/function';
|
|
6
4
|
/**
|
|
7
|
-
*
|
|
8
|
-
* Any function with either an incorrect argument or a return type will not fit
|
|
9
|
-
* into the pipeline and should be typed according to it, so that its argument's
|
|
10
|
-
* type matches the return type of the previous function and its return type
|
|
11
|
-
* matches the type of the next function's argument.
|
|
5
|
+
* Applies second onto first onto args.
|
|
12
6
|
*/
|
|
13
|
-
export
|
|
14
|
-
First,
|
|
15
|
-
...Pipeline<First extends UnaryFunction ? Second extends UnaryFunction ? Rest extends UnaryFunction[] ? [(arg: ReturnType<First>) => ReturnType<Second>, ...Rest] : never : never : First extends VariadicFunction ? Second extends UnaryFunction ? Rest extends UnaryFunction[] ? [(arg: ReturnType<First>) => ReturnType<Second>, ...Rest] : never : never : never>
|
|
16
|
-
] : Functions;
|
|
7
|
+
export default function pipe<First, Argument, Return>(first: (arg: Argument) => First, second: (arg: First) => Return): (arg: Argument) => Return;
|
|
17
8
|
/**
|
|
18
|
-
* Applies
|
|
9
|
+
* Applies second onto first onto args.
|
|
19
10
|
*/
|
|
20
|
-
export default function pipe<
|
|
11
|
+
export default function pipe<First, Arguments extends any[], Return>(first: (...args: Arguments) => First, second: (arg: First) => Return): (...args: Arguments) => Return;
|
package/pipe.js
CHANGED
|
@@ -4,26 +4,15 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
/**
|
|
7
|
-
* Applies
|
|
7
|
+
* Applies second onto first onto args.
|
|
8
8
|
*/
|
|
9
|
-
function pipe() {
|
|
10
|
-
var functions = [];
|
|
11
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
12
|
-
functions[_i] = arguments[_i];
|
|
13
|
-
}
|
|
9
|
+
function pipe(first, second) {
|
|
14
10
|
return function () {
|
|
15
11
|
var args = [];
|
|
16
12
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
17
13
|
args[_i] = arguments[_i];
|
|
18
14
|
}
|
|
19
|
-
|
|
20
|
-
var pipeline = functions[0].apply(functions, args);
|
|
21
|
-
if (length > 1) {
|
|
22
|
-
for (var index = 1; index < length; index += 1) {
|
|
23
|
-
pipeline = functions[index](pipeline);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return pipeline;
|
|
15
|
+
return second(first.apply(void 0, args));
|
|
27
16
|
};
|
|
28
17
|
}
|
|
29
18
|
exports.default = pipe;
|