fnts 1.7.0 → 1.9.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.
Files changed (43) hide show
  1. package/either/left.d.ts +1 -1
  2. package/either/operators/bifold/bifold.d.ts +4 -4
  3. package/either/operators/bifold/bifold.js +6 -4
  4. package/either/operators/bifold/bifoldl.d.ts +7 -2
  5. package/either/operators/bifold/bifoldl.js +2 -2
  6. package/either/operators/bifold/bifoldr.d.ts +7 -2
  7. package/either/operators/bifold/bifoldr.js +2 -2
  8. package/either/operators/{bifold-map.d.ts → bifold-map/bifold-map.d.ts} +2 -2
  9. package/either/operators/{bifold-map.js → bifold-map/bifold-map.js} +9 -6
  10. package/either/operators/bifold-map/bifoldl-map.d.ts +27 -0
  11. package/either/operators/bifold-map/bifoldl-map.js +21 -0
  12. package/either/operators/bifold-map/bifoldr-map.d.ts +27 -0
  13. package/either/operators/bifold-map/bifoldr-map.js +21 -0
  14. package/either/operators/bifold-map/index.d.ts +3 -0
  15. package/either/operators/bifold-map/index.js +9 -0
  16. package/either/operators/bimap/bimap.js +3 -2
  17. package/either/operators/bimap/first.js +5 -4
  18. package/either/operators/bimap/second.js +4 -3
  19. package/either/operators/bindr.js +3 -2
  20. package/either/operators/guards.d.ts +4 -4
  21. package/either/operators/guards.js +6 -6
  22. package/either/right.d.ts +1 -1
  23. package/guard.d.ts +1 -1
  24. package/guard.js +2 -2
  25. package/maybe/just.d.ts +2 -2
  26. package/maybe/maybe.d.ts +1 -6
  27. package/maybe/nothing.d.ts +1 -1
  28. package/maybe/nothing.js +1 -1
  29. package/maybe/operators/bind.d.ts +2 -2
  30. package/maybe/operators/bind.js +3 -2
  31. package/maybe/operators/fmap.d.ts +2 -2
  32. package/maybe/operators/fmap.js +4 -3
  33. package/maybe/operators/fold-map.d.ts +14 -3
  34. package/maybe/operators/fold-map.js +4 -3
  35. package/maybe/operators/fold.d.ts +5 -1
  36. package/maybe/operators/guards.d.ts +4 -4
  37. package/maybe/operators/guards.js +6 -6
  38. package/package.json +1 -1
  39. package/rethrow.d.ts +1 -1
  40. package/rethrow.js +3 -3
  41. package/ternary.d.ts +2 -0
  42. package/ternary.js +2 -0
  43. package/tsconfig.json +2 -2
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: Value): Left<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 type { Left } from '../../left';
5
- import type { Right } from '../../right';
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<Monad extends Either<any, any>>(monad: Monad): Bifold<Monad>;
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 bifoldl_1 = require("./bifoldl");
7
- var bifoldr_1 = require("./bifoldr");
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
- var _a;
13
- return (_a = (0, bifoldl_1.default)(monad)) !== null && _a !== void 0 ? _a : (0, bifoldr_1.default)(monad);
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,14 @@ 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<Monad extends Either<any, any>>(monad: Monad): Bifoldl<Monad>;
15
+ export default function bifoldl<LeftValue>(monad: Either<LeftValue, any>): LeftValue | undefined;
16
+ /**
17
+ * Returns the left value of the provided `monad`.
18
+ * If the `monad` is `Right`, returns `undefined`.
19
+ */
20
+ export default function bifoldl<Monad extends Left<any>>(monad: Monad): Bifoldl<Monad>;
@@ -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 ((0, guards_1.isLeft)(monad)
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,14 @@ 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<Monad extends Either<any, any>>(monad: Monad): Bifoldr<Monad>;
15
+ export default function bifoldr<RightValue>(monad: Either<any, RightValue>): RightValue | undefined;
16
+ /**
17
+ * Returns the right value of the provided `monad`.
18
+ * If the `monad` is `Left`, returns `undefined`.
19
+ */
20
+ export default function bifoldr<Monad extends Right<any>>(monad: Monad): Bifoldr<Monad>;
@@ -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 ((0, guards_1.isRight)(monad)
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 '../either';
5
- import type { Map } from '../../types/map';
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,12 @@
3
3
  * @module Either Operators
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var compose_1 = require("../../compose");
7
- var ternary_1 = require("../../ternary");
8
- var permutation_3_1 = require("../../permutation/permutation-3");
9
- var guards_1 = require("./guards");
10
- var bifold_1 = require("./bifold");
6
+ var bifold_1 = require("../bifold");
7
+ var compose_1 = require("../../../compose");
8
+ var guards_1 = require("../guards");
9
+ var permutation_3_1 = require("../../../permutation/permutation-3");
10
+ var bifoldl_map_1 = require("./bifoldl-map");
11
+ var bifoldr_map_1 = require("./bifoldr-map");
11
12
  function bifoldMap() {
12
13
  var args = [];
13
14
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -22,7 +23,9 @@ function bifoldMap() {
22
23
  return (0, compose_1.default)(args[1], bifold_1.default)(args[0]);
23
24
  }
24
25
  return (0, permutation_3_1.default)(function (monad, mapLeft, mapRight) {
25
- return (0, ternary_1.default)(guards_1.isLeft, (0, compose_1.default)(mapLeft, bifold_1.bifoldl), (0, compose_1.default)(mapRight, bifold_1.bifoldr))(monad);
26
+ return ((0, guards_1.isLeft)(monad)
27
+ ? (0, bifoldl_map_1.default)(monad, mapLeft)
28
+ : (0, bifoldr_map_1.default)(monad, mapRight));
26
29
  }).apply(void 0, args);
27
30
  }
28
31
  exports.default = bifoldMap;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @module Either Operators
3
+ */
4
+ import type { Left } from '../../left';
5
+ import type { Either } from '../../either';
6
+ import type { Map } from '../../../types/map';
7
+ import { Bifoldl } from '../bifold/bifoldl';
8
+ /**
9
+ * Maps provided `monad`'s left value to a new value,
10
+ * then returns it or `undefined`.
11
+ */
12
+ export default function bifoldlMap<LeftValue, Value>(map: Map<LeftValue, Value>): (monad: Either<LeftValue, any>) => Value | undefined;
13
+ /**
14
+ * Maps provided `monad`'s left value to a new value,
15
+ * then returns it or `undefined`.
16
+ */
17
+ export default function bifoldlMap<LeftValue, Value>(monad: Either<LeftValue, any>, map: Map<LeftValue, Value>): Value | undefined;
18
+ /**
19
+ * Maps provided `monad`'s left value to a new value,
20
+ * then returns it or `undefined`.
21
+ */
22
+ export default function bifoldlMap<Monad extends Left<any>, Value>(map: Map<Bifoldl<Monad>, Value>): (monad: Monad) => Value;
23
+ /**
24
+ * Maps provided `monad`'s left value to a new value,
25
+ * then returns it or `undefined`.
26
+ */
27
+ export default function bifoldlMap<Monad extends Left<any>, Value>(monad: Monad, map: Map<Bifoldl<Monad>, Value>): Value;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /**
3
+ * @module Either Operators
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var guards_1 = require("../guards");
7
+ var compose_1 = require("../../../compose");
8
+ var bifoldl_1 = require("../bifold/bifoldl");
9
+ var permutation_2_1 = require("../../../permutation/permutation-2");
10
+ function bifoldlMap() {
11
+ var args = [];
12
+ for (var _i = 0; _i < arguments.length; _i++) {
13
+ args[_i] = arguments[_i];
14
+ }
15
+ return (0, permutation_2_1.default)(function (monad, map) {
16
+ return (0, guards_1.isLeft)(monad)
17
+ ? (0, compose_1.default)(map, bifoldl_1.default)(monad)
18
+ : undefined;
19
+ }).apply(void 0, args);
20
+ }
21
+ exports.default = bifoldlMap;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @module Either Operators
3
+ */
4
+ import { Right } from '../../right';
5
+ import type { Either } from '../../either';
6
+ import type { Map } from '../../../types/map';
7
+ import { Bifoldr } from '../bifold/bifoldr';
8
+ /**
9
+ * Maps provided `monad`'s right value to a new value,
10
+ * then returns it or `undefined`.
11
+ */
12
+ export default function bifoldrMap<RightValue, Value>(map: Map<RightValue, Value>): (monad: Either<any, RightValue>) => Value | undefined;
13
+ /**
14
+ * Maps provided `monad`'s right value to a new value,
15
+ * then returns it or `undefined`.
16
+ */
17
+ export default function bifoldrMap<RightValue, Value>(monad: Either<any, RightValue>, map: Map<RightValue, Value>): Value | undefined;
18
+ /**
19
+ * Maps provided `monad`'s right value to a new value,
20
+ * then returns it or `undefined`.
21
+ */
22
+ export default function bifoldrMap<Monad extends Right<any>, Value>(map: Map<Bifoldr<Monad>, Value>): (monad: Monad) => Value;
23
+ /**
24
+ * Maps provided `monad`'s right value to a new value,
25
+ * then returns it or `undefined`.
26
+ */
27
+ export default function bifoldrMap<Monad extends Right<any>, Value>(monad: Monad, map: Map<Bifoldr<Monad>, Value>): Value;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /**
3
+ * @module Either Operators
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var guards_1 = require("../guards");
7
+ var compose_1 = require("../../../compose");
8
+ var bifoldr_1 = require("../bifold/bifoldr");
9
+ var permutation_2_1 = require("../../../permutation/permutation-2");
10
+ function bifoldrMap() {
11
+ var args = [];
12
+ for (var _i = 0; _i < arguments.length; _i++) {
13
+ args[_i] = arguments[_i];
14
+ }
15
+ return (0, permutation_2_1.default)(function (monad, map) {
16
+ return (0, guards_1.isRight)(monad)
17
+ ? (0, compose_1.default)(map, bifoldr_1.default)(monad)
18
+ : undefined;
19
+ }).apply(void 0, args);
20
+ }
21
+ exports.default = bifoldrMap;
@@ -0,0 +1,3 @@
1
+ export { default } from './bifold-map';
2
+ export { default as bifoldlMap } from './bifoldl-map';
3
+ export { default as bifoldrMap } from './bifoldr-map';
@@ -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; } });
@@ -4,7 +4,6 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var guards_1 = require("../guards");
7
- var ternary_1 = require("../../../ternary");
8
7
  var permutation_3_1 = require("../../../permutation/permutation-3");
9
8
  var first_1 = require("./first");
10
9
  var second_1 = require("./second");
@@ -14,7 +13,9 @@ function bimap() {
14
13
  args[_i] = arguments[_i];
15
14
  }
16
15
  return (0, permutation_3_1.default)(function (monad, mapLeft, mapRight) {
17
- return (0, ternary_1.default)(guards_1.isLeft, (0, first_1.default)(mapLeft), (0, second_1.default)(mapRight))(monad);
16
+ return (0, guards_1.isLeft)(monad)
17
+ ? (0, first_1.default)(monad, mapLeft)
18
+ : (0, second_1.default)(monad, mapRight);
18
19
  }).apply(void 0, args);
19
20
  }
20
21
  exports.default = bimap;
@@ -3,11 +3,10 @@
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
- var bifold_1 = require("../bifold");
8
8
  var compose_1 = require("../../../compose");
9
- var ternary_1 = require("../../../ternary");
10
- var left_1 = require("../../left");
9
+ var bifoldl_1 = require("../bifold/bifoldl");
11
10
  var identity_1 = require("../../../identity");
12
11
  var permutation_2_1 = require("../../../permutation/permutation-2");
13
12
  function first() {
@@ -16,7 +15,9 @@ function first() {
16
15
  args[_i] = arguments[_i];
17
16
  }
18
17
  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);
18
+ return (0, guards_1.isLeft)(monad)
19
+ ? (0, compose_1.default)((left_1.default), mapLeft, bifoldl_1.default)(monad)
20
+ : (0, identity_1.default)(monad);
20
21
  }).apply(void 0, args);
21
22
  }
22
23
  exports.default = first;
@@ -3,12 +3,11 @@
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
- var ternary_1 = require("../../../ternary");
10
10
  var identity_1 = require("../../../identity");
11
- var right_1 = require("../../right");
12
11
  var permutation_2_1 = require("../../../permutation/permutation-2");
13
12
  function second() {
14
13
  var args = [];
@@ -16,7 +15,9 @@ function second() {
16
15
  args[_i] = arguments[_i];
17
16
  }
18
17
  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);
18
+ return (0, guards_1.isRight)(monad)
19
+ ? (0, compose_1.default)((right_1.default), mapRight, bifold_1.bifoldr)(monad)
20
+ : (0, identity_1.default)(monad);
20
21
  }).apply(void 0, args);
21
22
  }
22
23
  exports.default = second;
@@ -4,7 +4,6 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var compose_1 = require("../../compose");
7
- var ternary_1 = require("../../ternary");
8
7
  var identity_1 = require("../../identity");
9
8
  var permutation_2_1 = require("../../permutation/permutation-2");
10
9
  var bifold_1 = require("./bifold");
@@ -15,7 +14,9 @@ function bindr() {
15
14
  args[_i] = arguments[_i];
16
15
  }
17
16
  return (0, permutation_2_1.default)(function (monad, mapRight) {
18
- return (0, ternary_1.default)(guards_1.isRight, (0, compose_1.default)(mapRight, bifold_1.bifoldr), identity_1.default)(monad);
17
+ return (0, guards_1.isRight)(monad)
18
+ ? (0, compose_1.default)(mapRight, bifold_1.bifoldr)(monad)
19
+ : (0, identity_1.default)(monad);
19
20
  }).apply(void 0, args);
20
21
  }
21
22
  exports.default = bindr;
@@ -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 `monad` is `Left`.
8
+ * Type guard function to tell if the provided `value` is `Left`.
9
9
  */
10
- export declare function isLeft<LeftValue>(monad: Either<LeftValue, any>): monad is Left<LeftValue>;
10
+ export declare function isLeft<LeftValue>(value: any): value is Left<LeftValue>;
11
11
  /**
12
- * Type guard function to tell if the provided `monad` is `Right`.
12
+ * Type guard function to tell if the provided `value` is `Right`.
13
13
  */
14
- export declare function isRight<RightValue>(monad: Either<any, RightValue>): monad is Right<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 `monad` is `Left`.
10
+ * Type guard function to tell if the provided `value` is `Left`.
11
11
  */
12
- function isLeft(monad) {
13
- return Object.prototype.hasOwnProperty.call(monad, left_1.lid);
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 `monad` is `Right`.
17
+ * Type guard function to tell if the provided `value` is `Right`.
18
18
  */
19
- function isRight(monad) {
20
- return Object.prototype.hasOwnProperty.call(monad, right_1.rid);
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: Value): Right<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]): (...args: Parameters<Function>) => ReturnType<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]: NonNullable<Value>;
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 extends NonNullable<any>>(value: Value): 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): Nothing;
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>;
@@ -11,7 +11,7 @@ export declare const nid: unique symbol;
11
11
  * key, holding the `null` value type.
12
12
  */
13
13
  export declare type Nothing = {
14
- [nid]: null;
14
+ [nid]: undefined;
15
15
  };
16
16
  /**
17
17
  * Constructor function for `Nothing`.
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] = null,
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<NonNullable<NextValue>>;
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<NonNullable<NextValue>>;
15
+ export default function bind<Value, NextValue>(monad: Maybe<Value>, map: Map<Value, Maybe<NextValue>>): Maybe<NextValue>;
@@ -4,7 +4,6 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var compose_1 = require("../../compose");
7
- var ternary_1 = require("../../ternary");
8
7
  var identity_1 = require("../../identity");
9
8
  var permutation_2_1 = require("../../permutation/permutation-2");
10
9
  var fold_1 = require("./fold");
@@ -15,7 +14,9 @@ function bind() {
15
14
  args[_i] = arguments[_i];
16
15
  }
17
16
  return (0, permutation_2_1.default)(function (monad, map) {
18
- return (0, ternary_1.default)(guards_1.isJust, (0, compose_1.default)(map, fold_1.default), identity_1.default)(monad);
17
+ return (0, guards_1.isJust)(monad)
18
+ ? (0, compose_1.default)(map, fold_1.default)(monad)
19
+ : (0, identity_1.default)(monad);
19
20
  }).apply(void 0, args);
20
21
  }
21
22
  exports.default = bind;
@@ -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 = Value>(map: Map<Value, NextValue>): (monad: Maybe<Value>) => Maybe<NonNullable<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 = Value>(monad: Maybe<Value>, map: Map<Value, NextValue>): Maybe<NonNullable<NextValue>>;
15
+ export default function fmap<Value, NextValue>(monad: Maybe<Value>, map: Map<Value, NextValue>): Maybe<NextValue>;
@@ -7,16 +7,17 @@ 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 fold_1 = require("./fold");
10
+ var fold_map_1 = require("./fold-map");
11
11
  var guards_1 = require("./guards");
12
- var ternary_1 = require("../../ternary");
13
12
  function fmap() {
14
13
  var args = [];
15
14
  for (var _i = 0; _i < arguments.length; _i++) {
16
15
  args[_i] = arguments[_i];
17
16
  }
18
17
  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, map, fold_1.default), identity_1.default)(monad);
18
+ return (0, guards_1.isJust)(monad)
19
+ ? (0, compose_1.default)((maybe_1.default), (0, fold_map_1.default)(map))(monad)
20
+ : (0, identity_1.default)(monad);
20
21
  }).apply(void 0, args);
21
22
  }
22
23
  exports.default = fmap;
@@ -5,17 +5,28 @@ import type { Just } from '../just';
5
5
  import type { Maybe } from '../maybe';
6
6
  import type { Nothing } from '../nothing';
7
7
  import type { Map } from '../../types/map';
8
+ import { Fold } from './fold';
8
9
  /**
9
10
  * A type to unwrap the provided `Monad` into the new value type.
10
11
  */
11
- export declare type FoldMap<Monad extends Maybe<any>, NextValue> = Monad extends Just<any> ? NonNullable<NextValue> : Monad extends Nothing ? null : never;
12
+ 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
13
  /**
13
14
  * Maps the value of the provided `monad` through the `transition` function
14
15
  * and returns the mapped value or `null`.
15
16
  */
16
- export default function foldMap<Value, NextValue = Value>(map: Map<Value, NextValue>): (monad: Maybe<Value>) => FoldMap<Maybe<Value>, NextValue>;
17
+ export default function foldMap<Value, NextValue>(map: Map<Value, NextValue>): (monad: Maybe<Value>) => NextValue | undefined;
17
18
  /**
18
19
  * Maps the value of the provided `monad` through the `transition` function
19
20
  * and returns the mapped value or `null`.
20
21
  */
21
- export default function foldMap<Value, NextValue = Value>(monad: Maybe<Value>, map: Map<Value, NextValue>): FoldMap<Maybe<Value>, NextValue>;
22
+ export default function foldMap<Value, NextValue>(monad: Maybe<Value>, map: Map<Value, NextValue>): NextValue | undefined;
23
+ /**
24
+ * Maps the value of the provided `monad` through the `transition` function
25
+ * and returns the mapped value or `null`.
26
+ */
27
+ export default function foldMap<Monad extends Just<any>, NextValue>(map: Map<Fold<Monad>, NextValue>): (monad: Monad) => NextValue;
28
+ /**
29
+ * Maps the value of the provided `monad` through the `transition` function
30
+ * and returns the mapped value or `null`.
31
+ */
32
+ export default function foldMap<Monad extends Just<any>, NextValue>(monad: Monad, map: Map<Fold<Monad>, NextValue>): NextValue;
@@ -4,17 +4,18 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var compose_1 = require("../../compose");
7
- var ternary_1 = require("../../ternary");
8
7
  var permutation_2_1 = require("../../permutation/permutation-2");
9
- var fold_1 = require("./fold");
10
8
  var guards_1 = require("./guards");
9
+ var fold_1 = require("./fold");
11
10
  function foldMap() {
12
11
  var args = [];
13
12
  for (var _i = 0; _i < arguments.length; _i++) {
14
13
  args[_i] = arguments[_i];
15
14
  }
16
15
  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 null; })(monad);
16
+ return (0, guards_1.isJust)(monad)
17
+ ? (0, compose_1.default)(map, fold_1.default)(monad)
18
+ : undefined;
18
19
  }).apply(void 0, args);
19
20
  }
20
21
  exports.default = foldMap;
@@ -7,7 +7,11 @@ 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 ? null : never;
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
+ /**
12
+ * Returns the value of the provided `monad`.
13
+ */
14
+ export default function fold<Value>(monad: Maybe<Value>): Value | undefined;
11
15
  /**
12
16
  * Returns the value of the provided `monad`.
13
17
  */
@@ -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 `monad` is `Just`.
8
+ * Type guard function to tell if the provided `value` is `Just`.
9
9
  */
10
- export declare function isJust<Value>(monad: Maybe<Value>): monad is Just<Value>;
10
+ export declare function isJust<Value>(value: any): value is Just<Value>;
11
11
  /**
12
- * Type guard function to tell if the provided `monad` is `Nothing`.
12
+ * Type guard function to tell if the provided `value` is `Nothing`.
13
13
  */
14
- export declare function isNothing<Value>(monad: Maybe<Value>): monad is Nothing;
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 `monad` is `Just`.
10
+ * Type guard function to tell if the provided `value` is `Just`.
11
11
  */
12
- function isJust(monad) {
13
- return Object.prototype.hasOwnProperty.call(monad, just_1.jid);
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 `monad` is `Nothing`.
17
+ * Type guard function to tell if the provided `value` is `Nothing`.
18
18
  */
19
- function isNothing(monad) {
20
- return Object.prototype.hasOwnProperty.call(monad, nothing_1.nid);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fnts",
3
- "version": "1.7.0",
3
+ "version": "1.9.0-rc.1",
4
4
  "license": "MIT",
5
5
  "author": "Dmytro Vasylkivskyi",
6
6
  "description": "TypeScript / JavaScript FP utilities",
package/rethrow.d.ts CHANGED
@@ -6,4 +6,4 @@ import type { Effect } from './types/effect';
6
6
  * Rethrows a received error
7
7
  * performing an optional side effect.
8
8
  */
9
- export default function rethrow<Error>(effect: Effect<(error: Error) => never>): (error: Error) => never;
9
+ export default function rethrow<Error>(effect?: Effect<(error: Error) => never>): (error: Error) => never;
package/rethrow.js CHANGED
@@ -3,14 +3,14 @@
3
3
  * @module Side Effects
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var inject_1 = require("./inject");
7
6
  /**
8
7
  * Rethrows a received error
9
8
  * performing an optional side effect.
10
9
  */
11
10
  function rethrow(effect) {
12
- return (0, inject_1.default)(function (error) {
11
+ return function (error) {
12
+ effect === null || effect === void 0 ? void 0 : effect(error);
13
13
  throw error;
14
- }, effect);
14
+ };
15
15
  }
16
16
  exports.default = rethrow;
package/ternary.d.ts CHANGED
@@ -6,5 +6,7 @@ import type { Map } from './types/map';
6
6
  * Functional alternative to the ternary operator.
7
7
  * Enforces the same return type for both branches,
8
8
  * the result is evaluated lazily.
9
+ *
10
+ * @deprecated
9
11
  */
10
12
  export default function ternary<Value, Return>(predicate: Map<Value, boolean>, left: Map<Value, Return>, right: Map<Value, Return>): Map<Value, Return>;
package/ternary.js CHANGED
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  * Functional alternative to the ternary operator.
8
8
  * Enforces the same return type for both branches,
9
9
  * the result is evaluated lazily.
10
+ *
11
+ * @deprecated
10
12
  */
11
13
  function ternary(predicate, left, right) {
12
14
  return function (value) {
package/tsconfig.json CHANGED
@@ -11,10 +11,10 @@
11
11
  "alwaysStrict": true,
12
12
  "skipLibCheck": true,
13
13
  "noImplicitAny": true,
14
- "noUnusedLocals": true,
14
+ "noUnusedLocals": false,
15
15
  "strictNullChecks": true,
16
16
  "noImplicitReturns": true,
17
- "noUnusedParameters": true,
17
+ "noUnusedParameters": false,
18
18
  "strictFunctionTypes": true,
19
19
  "strictBindCallApply": true,
20
20
  "noStrictGenericChecks": true,