fnts 1.7.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.
Files changed (41) hide show
  1. package/compose.d.ts +4 -13
  2. package/compose.js +3 -14
  3. package/either/left.d.ts +1 -1
  4. package/either/operators/bifold/bifold.d.ts +4 -4
  5. package/either/operators/bifold/bifold.js +6 -4
  6. package/either/operators/bifold/bifoldl.d.ts +2 -2
  7. package/either/operators/bifold/bifoldl.js +2 -2
  8. package/either/operators/bifold/bifoldr.d.ts +2 -2
  9. package/either/operators/bifold/bifoldr.js +2 -2
  10. package/either/operators/{bifold-map.d.ts → bifold-map/bifold-map.d.ts} +2 -2
  11. package/either/operators/{bifold-map.js → bifold-map/bifold-map.js} +8 -6
  12. package/either/operators/bifold-map/bifoldl-map.d.ts +15 -0
  13. package/either/operators/bifold-map/bifoldl-map.js +20 -0
  14. package/either/operators/bifold-map/bifoldr-map.d.ts +15 -0
  15. package/either/operators/bifold-map/bifoldr-map.js +20 -0
  16. package/either/operators/bifold-map/index.d.ts +3 -0
  17. package/either/operators/bifold-map/index.js +9 -0
  18. package/either/operators/bimap/first.js +2 -2
  19. package/either/operators/bimap/second.js +2 -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/fmap.d.ts +2 -2
  31. package/maybe/operators/fmap.js +2 -2
  32. package/maybe/operators/fold-map.d.ts +3 -3
  33. package/maybe/operators/fold-map.js +1 -1
  34. package/maybe/operators/fold.d.ts +2 -2
  35. package/maybe/operators/guards.d.ts +4 -4
  36. package/maybe/operators/guards.js +6 -6
  37. package/package.json +1 -1
  38. package/pipe.d.ts +4 -13
  39. package/pipe.js +3 -14
  40. package/rethrow.d.ts +1 -1
  41. package/rethrow.js +3 -3
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
- * Creates a `Composition` type which parses all of the provided functions' types.
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 declare type Composition<Functions extends [...UnaryFunction[], VariadicFunction], Length extends number = Functions['length']> = Length extends 1 ? Functions : Functions extends [...infer Rest, infer Penultimate, infer Last] ? [
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 all of the provided `functions` one-by-one in right-to-left order.
9
+ * Applies first onto second onto args.
19
10
  */
20
- export default function compose<Functions extends [...UnaryFunction[], VariadicFunction]>(...functions: Composition<Functions>): (...args: Parameters<Last<Functions>>) => ReturnType<Functions[0]>;
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 all of the provided `functions` one-by-one in right-to-left order.
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
- var length = functions.length;
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: 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,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<Monad extends Either<any, any>>(monad: Monad): Bifoldl<Monad>;
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 ((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,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<Monad extends Either<any, any>>(monad: Monad): Bifoldr<Monad>;
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 ((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,13 @@
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 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, compose_1.default)(mapLeft, bifold_1.bifoldl), (0, compose_1.default)(mapRight, bifold_1.bifoldr))(monad);
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,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; } });
@@ -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 `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>;
@@ -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,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 fold_1 = require("./fold");
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, map, fold_1.default), identity_1.default)(monad);
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> ? NonNullable<NextValue> : Monad extends Nothing ? null : never;
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>) => FoldMap<Maybe<Value>, NextValue>;
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>): FoldMap<Maybe<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 null; })(monad);
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 ? 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
11
  /**
12
12
  * Returns the value of the provided `monad`.
13
13
  */
14
- export default function fold<Monad extends Maybe<any>>(monad: Monad): Fold<Monad>;
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 `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": "2.0.0-rc.1",
4
4
  "license": "MIT",
5
5
  "author": "Dmytro Vasylkivskyi",
6
6
  "description": "TypeScript / JavaScript FP utilities",
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
- * Creates a `Pipeline` type which parses all of the provided functions' types.
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 declare type Pipeline<Functions extends [VariadicFunction, ...UnaryFunction[]], Length extends number = Functions['length']> = Length extends 1 ? Functions : Functions extends [infer First, infer Second, ...infer Rest] ? [
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 all of the provided `functions` one-by-one in left-to-right order.
9
+ * Applies second onto first onto args.
19
10
  */
20
- export default function pipe<Functions extends [VariadicFunction, ...UnaryFunction[]]>(...functions: Pipeline<Functions>): (...args: Parameters<Functions[0]>) => ReturnType<Last<Functions>>;
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 all of the provided `functions` one-by-one in left-to-right order.
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
- var length = functions.length;
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;
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;