fnts 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/README.md +4 -50
  2. package/cjs/compose.js +25 -0
  3. package/cjs/curry.js +37 -0
  4. package/cjs/either/either-sync.js +21 -0
  5. package/cjs/either/either.js +18 -0
  6. package/cjs/either/index.js +11 -0
  7. package/cjs/either/left.js +22 -0
  8. package/cjs/either/operators/bifold/bifold.js +15 -0
  9. package/cjs/either/operators/bifold/bifoldl.js +17 -0
  10. package/cjs/either/operators/bifold/bifoldr.js +17 -0
  11. package/cjs/either/operators/bifold/index.js +9 -0
  12. package/cjs/either/operators/bifold-map.js +20 -0
  13. package/cjs/either/operators/bimap/bimap.js +20 -0
  14. package/cjs/either/operators/bimap/first.js +22 -0
  15. package/cjs/either/operators/bimap/index.js +9 -0
  16. package/cjs/either/operators/bimap/second.js +22 -0
  17. package/cjs/either/operators/guards.js +22 -0
  18. package/cjs/either/operators/index.js +24 -0
  19. package/cjs/either/right.js +22 -0
  20. package/cjs/guard.js +37 -0
  21. package/cjs/identity.js +12 -0
  22. package/cjs/index.js +21 -0
  23. package/cjs/inject.js +23 -0
  24. package/cjs/maybe/index.js +9 -0
  25. package/cjs/maybe/just.js +22 -0
  26. package/cjs/maybe/maybe.js +17 -0
  27. package/cjs/maybe/nothing.js +22 -0
  28. package/cjs/maybe/operators/bind.js +21 -0
  29. package/cjs/maybe/operators/fmap.js +22 -0
  30. package/cjs/maybe/operators/fold-map.js +20 -0
  31. package/cjs/maybe/operators/fold.js +17 -0
  32. package/cjs/maybe/operators/guards.js +22 -0
  33. package/cjs/maybe/operators/index.js +14 -0
  34. package/cjs/permutation/index.js +7 -0
  35. package/cjs/permutation/permutation-2.js +18 -0
  36. package/cjs/permutation/permutation-3.js +18 -0
  37. package/cjs/pipe.js +25 -0
  38. package/cjs/rethrow.js +16 -0
  39. package/cjs/tap.js +15 -0
  40. package/cjs/ternary.js +16 -0
  41. package/compose.d.ts +5 -3
  42. package/curry.d.ts +6 -4
  43. package/either/either-sync.d.ts +4 -2
  44. package/either/either.d.ts +4 -2
  45. package/either/index.d.ts +3 -3
  46. package/either/left.d.ts +4 -2
  47. package/either/operators/bifold/bifold.d.ts +4 -2
  48. package/either/operators/bifold/bifoldl.d.ts +4 -2
  49. package/either/operators/bifold/bifoldr.d.ts +4 -2
  50. package/either/operators/bifold/index.d.ts +3 -3
  51. package/either/operators/bifold-map.d.ts +6 -4
  52. package/either/operators/bimap/bimap.d.ts +6 -4
  53. package/either/operators/bimap/first.d.ts +6 -4
  54. package/either/operators/bimap/index.d.ts +3 -3
  55. package/either/operators/bimap/second.d.ts +6 -4
  56. package/either/operators/guards.d.ts +3 -0
  57. package/either/operators/index.d.ts +3 -3
  58. package/either/right.d.ts +4 -2
  59. package/esm/compose.js +18 -0
  60. package/esm/curry.js +23 -0
  61. package/esm/either/either-sync.js +18 -0
  62. package/esm/either/either.js +15 -0
  63. package/esm/either/index.js +4 -0
  64. package/esm/either/left.js +17 -0
  65. package/esm/either/operators/bifold/bifold.js +12 -0
  66. package/esm/either/operators/bifold/bifoldl.js +14 -0
  67. package/esm/either/operators/bifold/bifoldr.js +14 -0
  68. package/esm/either/operators/bifold/index.js +3 -0
  69. package/esm/either/operators/bifold-map.js +13 -0
  70. package/esm/either/operators/bimap/bimap.js +13 -0
  71. package/esm/either/operators/bimap/first.js +15 -0
  72. package/esm/either/operators/bimap/index.js +3 -0
  73. package/esm/either/operators/bimap/second.js +15 -0
  74. package/esm/either/operators/guards.js +17 -0
  75. package/esm/either/operators/index.js +4 -0
  76. package/esm/either/right.js +17 -0
  77. package/esm/guard.js +26 -0
  78. package/esm/identity.js +9 -0
  79. package/esm/index.js +9 -0
  80. package/esm/inject.js +12 -0
  81. package/esm/maybe/index.js +3 -0
  82. package/esm/maybe/just.js +17 -0
  83. package/esm/maybe/maybe.js +14 -0
  84. package/esm/maybe/nothing.js +17 -0
  85. package/esm/maybe/operators/bind.js +14 -0
  86. package/esm/maybe/operators/fmap.js +15 -0
  87. package/esm/maybe/operators/fold-map.js +13 -0
  88. package/esm/maybe/operators/fold.js +14 -0
  89. package/esm/maybe/operators/guards.js +17 -0
  90. package/esm/maybe/operators/index.js +5 -0
  91. package/esm/permutation/index.js +2 -0
  92. package/esm/permutation/permutation-2.js +11 -0
  93. package/esm/permutation/permutation-3.js +11 -0
  94. package/esm/pipe.js +18 -0
  95. package/esm/rethrow.js +13 -0
  96. package/esm/tap.js +12 -0
  97. package/esm/ternary.js +13 -0
  98. package/guard.d.ts +5 -3
  99. package/identity.d.ts +4 -2
  100. package/index.d.ts +9 -5
  101. package/inject.d.ts +6 -4
  102. package/maybe/index.d.ts +2 -2
  103. package/maybe/just.d.ts +4 -2
  104. package/maybe/maybe.d.ts +4 -2
  105. package/maybe/nothing.d.ts +4 -2
  106. package/maybe/operators/bind.d.ts +6 -4
  107. package/maybe/operators/fmap.d.ts +6 -4
  108. package/maybe/operators/fold-map.d.ts +10 -8
  109. package/maybe/operators/fold.d.ts +4 -2
  110. package/maybe/operators/guards.d.ts +3 -0
  111. package/maybe/operators/index.d.ts +4 -4
  112. package/package.json +11 -4
  113. package/permutation/index.d.ts +2 -0
  114. package/permutation/permutation-2.d.ts +7 -0
  115. package/permutation/permutation-3.d.ts +7 -0
  116. package/pipe.d.ts +5 -3
  117. package/rethrow.d.ts +9 -0
  118. package/tap.d.ts +6 -3
  119. package/ternary.d.ts +10 -0
  120. package/tsconfig.json +1 -1
  121. package/{.internal → types}/effect.d.ts +7 -0
  122. package/types/gradual.d.ts +17 -0
  123. package/{.internal → types}/last.d.ts +7 -0
  124. package/types/map.d.ts +8 -0
  125. package/{.internal → types}/slice.d.ts +7 -0
  126. package/{.internal → types}/tuple.d.ts +6 -0
  127. package/.internal/gradual.d.ts +0 -5
  128. package/.internal/map.d.ts +0 -1
  129. package/.internal/permutation-of-2.d.ts +0 -1
  130. package/.internal/permutation-of-2.js +0 -1
  131. package/.internal/permutation-of-3.d.ts +0 -1
  132. package/.internal/permutation-of-3.js +0 -1
  133. package/compose.js +0 -1
  134. package/curry.js +0 -1
  135. package/either/either-sync.js +0 -1
  136. package/either/either.js +0 -1
  137. package/either/index.js +0 -1
  138. package/either/left.js +0 -1
  139. package/either/operators/bifold/bifold.js +0 -1
  140. package/either/operators/bifold/bifoldl.js +0 -1
  141. package/either/operators/bifold/bifoldr.js +0 -1
  142. package/either/operators/bifold/index.js +0 -1
  143. package/either/operators/bifold-map.js +0 -1
  144. package/either/operators/bimap/bimap.js +0 -1
  145. package/either/operators/bimap/first.js +0 -1
  146. package/either/operators/bimap/index.js +0 -1
  147. package/either/operators/bimap/second.js +0 -1
  148. package/either/operators/guards.js +0 -1
  149. package/either/operators/index.js +0 -1
  150. package/either/right.js +0 -1
  151. package/guard.js +0 -1
  152. package/identity.js +0 -1
  153. package/index.js +0 -1
  154. package/inject.js +0 -1
  155. package/maybe/index.js +0 -1
  156. package/maybe/just.js +0 -1
  157. package/maybe/maybe.js +0 -1
  158. package/maybe/nothing.js +0 -1
  159. package/maybe/operators/bind.js +0 -1
  160. package/maybe/operators/fmap.js +0 -1
  161. package/maybe/operators/fold-map.js +0 -1
  162. package/maybe/operators/fold.js +0 -1
  163. package/maybe/operators/guards.js +0 -1
  164. package/maybe/operators/index.js +0 -1
  165. package/pipe.js +0 -1
  166. package/tap.js +0 -1
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * @module Maybe Operators
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var compose_1 = require("../../compose");
7
+ var identity_1 = require("../../identity");
8
+ var maybe_1 = require("../maybe");
9
+ var permutation_2_1 = require("../../permutation/permutation-2");
10
+ var fold_1 = require("./fold");
11
+ var guards_1 = require("./guards");
12
+ var ternary_1 = require("../../ternary");
13
+ function fmap() {
14
+ var args = [];
15
+ for (var _i = 0; _i < arguments.length; _i++) {
16
+ args[_i] = arguments[_i];
17
+ }
18
+ return permutation_2_1.default(function (monad, transition) {
19
+ return ternary_1.default(guards_1.isJust, compose_1.default(maybe_1.default, transition, fold_1.default), identity_1.default)(monad);
20
+ }).apply(void 0, args);
21
+ }
22
+ exports.default = fmap;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /**
3
+ * @module Maybe Operators
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var compose_1 = require("../../compose");
7
+ var ternary_1 = require("../../ternary");
8
+ var permutation_2_1 = require("../../permutation/permutation-2");
9
+ var fold_1 = require("./fold");
10
+ var guards_1 = require("./guards");
11
+ function foldMap() {
12
+ var args = [];
13
+ for (var _i = 0; _i < arguments.length; _i++) {
14
+ args[_i] = arguments[_i];
15
+ }
16
+ return permutation_2_1.default(function (monad, transition) {
17
+ return ternary_1.default(guards_1.isJust, compose_1.default(transition, fold_1.default), function () { return null; })(monad);
18
+ }).apply(void 0, args);
19
+ }
20
+ exports.default = foldMap;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /**
3
+ * @module Maybe Operators
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var just_1 = require("../just");
7
+ var nothing_1 = require("../nothing");
8
+ var guards_1 = require("./guards");
9
+ /**
10
+ * Returns the value of the provided `monad`.
11
+ */
12
+ function fold(monad) {
13
+ return guards_1.isJust(monad)
14
+ ? monad[just_1.jid]
15
+ : monad[nothing_1.nid];
16
+ }
17
+ exports.default = fold;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * @module Maybe Operators
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isNothing = exports.isJust = void 0;
7
+ var just_1 = require("../just");
8
+ var nothing_1 = require("../nothing");
9
+ /**
10
+ * Type guard function to tell if the provided `monad` is `Just`.
11
+ */
12
+ function isJust(monad) {
13
+ return Object.prototype.hasOwnProperty.call(monad, just_1.jid);
14
+ }
15
+ exports.isJust = isJust;
16
+ /**
17
+ * Type guard function to tell if the provided `monad` is `Nothing`.
18
+ */
19
+ function isNothing(monad) {
20
+ return Object.prototype.hasOwnProperty.call(monad, nothing_1.nid);
21
+ }
22
+ exports.isNothing = isNothing;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.foldMap = exports.isNothing = exports.isJust = exports.fold = exports.bind = exports.fmap = void 0;
4
+ var fmap_1 = require("./fmap");
5
+ Object.defineProperty(exports, "fmap", { enumerable: true, get: function () { return fmap_1.default; } });
6
+ var bind_1 = require("./bind");
7
+ Object.defineProperty(exports, "bind", { enumerable: true, get: function () { return bind_1.default; } });
8
+ var fold_1 = require("./fold");
9
+ Object.defineProperty(exports, "fold", { enumerable: true, get: function () { return fold_1.default; } });
10
+ var guards_1 = require("./guards");
11
+ Object.defineProperty(exports, "isJust", { enumerable: true, get: function () { return guards_1.isJust; } });
12
+ Object.defineProperty(exports, "isNothing", { enumerable: true, get: function () { return guards_1.isNothing; } });
13
+ var fold_map_1 = require("./fold-map");
14
+ Object.defineProperty(exports, "foldMap", { enumerable: true, get: function () { return fold_map_1.default; } });
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.permutation3 = exports.permutation2 = void 0;
4
+ var permutation_2_1 = require("./permutation-2");
5
+ Object.defineProperty(exports, "permutation2", { enumerable: true, get: function () { return permutation_2_1.default; } });
6
+ var permutation_3_1 = require("./permutation-3");
7
+ Object.defineProperty(exports, "permutation3", { enumerable: true, get: function () { return permutation_3_1.default; } });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ /**
3
+ * @module Permutation
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ function permutation2(fn, shouldCurry) {
7
+ return function () {
8
+ var args = [];
9
+ for (var _i = 0; _i < arguments.length; _i++) {
10
+ args[_i] = arguments[_i];
11
+ }
12
+ var a1 = args[0], b = args[1];
13
+ return (shouldCurry === null || shouldCurry === void 0 ? void 0 : shouldCurry(a1, b)) || args.length < fn.length
14
+ ? function (a2) { return fn(a2, a1); }
15
+ : fn(a1, b);
16
+ };
17
+ }
18
+ exports.default = permutation2;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ /**
3
+ * @module Permutation
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ function permutation3(fn, shouldCurry) {
7
+ return function () {
8
+ var args = [];
9
+ for (var _i = 0; _i < arguments.length; _i++) {
10
+ args[_i] = arguments[_i];
11
+ }
12
+ var a1 = args[0], b = args[1], c = args[2];
13
+ return (shouldCurry === null || shouldCurry === void 0 ? void 0 : shouldCurry(a1, b, c)) || args.length < fn.length
14
+ ? function (a2) { return fn(a2, a1, b); }
15
+ : fn(a1, b, c);
16
+ };
17
+ }
18
+ exports.default = permutation3;
package/cjs/pipe.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * @module Composition
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ /**
7
+ * Applies all of the provided `functions` one-by-one in left-to-right order
8
+ * starting from the `argument`.
9
+ */
10
+ function pipe() {
11
+ var functions = [];
12
+ for (var _i = 0; _i < arguments.length; _i++) {
13
+ functions[_i] = arguments[_i];
14
+ }
15
+ return function (arg) {
16
+ var length = functions.length;
17
+ var pipeline = arg;
18
+ for (var index = 0; index < length; index += 1) {
19
+ var current = functions[index];
20
+ pipeline = current(pipeline);
21
+ }
22
+ return pipeline;
23
+ };
24
+ }
25
+ exports.default = pipe;
package/cjs/rethrow.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ /**
3
+ * @module Side Effects
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var inject_1 = require("./inject");
7
+ /**
8
+ * Rethrows a received error
9
+ * performing an optional side effect.
10
+ */
11
+ function rethrow(effect) {
12
+ return inject_1.default(function (error) {
13
+ throw error;
14
+ }, effect);
15
+ }
16
+ exports.default = rethrow;
package/cjs/tap.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ /**
3
+ * @module Side Effects
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var inject_1 = require("./inject");
7
+ var identity_1 = require("./identity");
8
+ /**
9
+ * Performs a side effect
10
+ * passing the received argument through itself.
11
+ */
12
+ function tap(effect) {
13
+ return inject_1.default(identity_1.default, effect);
14
+ }
15
+ exports.default = tap;
package/cjs/ternary.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ /**
3
+ * @module Ternary
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ /**
7
+ * Functional alternative to the ternary operator.
8
+ * Enforces the same return type for both branches,
9
+ * the result is evaluated lazily.
10
+ */
11
+ function ternary(predicate, left, right) {
12
+ return function (value) {
13
+ return predicate(value) ? left(value) : right(value);
14
+ };
15
+ }
16
+ exports.default = ternary;
package/compose.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- import type { Last } from './.internal/last';
1
+ /**
2
+ * @module Composition
3
+ */
4
+ import type { Last } from './types/last';
2
5
  /**
3
6
  * Creates a `Composition` type which parses all of the provided functions' types.
4
7
  * Any function with either an incorrect argument or a return type will not fit
@@ -17,5 +20,4 @@ export declare type Composition<Functions extends Array<(...args: any[]) => any>
17
20
  * Applies all of the provided `functions` one-by-one in right-to-left order
18
21
  * starting from the `argument`.
19
22
  */
20
- export declare function compose<Functions extends Array<(arg: any) => any>>(...functions: Composition<Functions>): (arg: Parameters<Last<Functions>>[0]) => ReturnType<Functions[0]>;
21
- export default compose;
23
+ export default function compose<Functions extends Array<(arg: any) => any>>(...functions: Composition<Functions>): (arg: Parameters<Last<Functions>>[0]) => ReturnType<Functions[0]>;
package/curry.d.ts CHANGED
@@ -1,5 +1,8 @@
1
- import type { Slice } from './.internal/slice';
2
- import type { Gradual } from './.internal/gradual';
1
+ /**
2
+ * @module Curry
3
+ */
4
+ import type { Slice } from './types/slice';
5
+ import type { Gradual } from './types/gradual';
3
6
  /**
4
7
  * Creates a type for an auto-curried function.
5
8
  */
@@ -12,5 +15,4 @@ export declare type Currying<Function extends (...args: any[]) => any, Length ex
12
15
  * of arguments.
13
16
  * Any excess arguments will not be applied.
14
17
  */
15
- export declare function curry<Function extends (...args: any[]) => any, Length extends number = Parameters<Function>['length']>(fn: Function, length?: Length): Currying<Function, Length>;
16
- export default curry;
18
+ export default function curry<Function extends (...args: any[]) => any, Length extends number = Parameters<Function>['length']>(fn: Function, length?: Length): Currying<Function, Length>;
@@ -1,8 +1,10 @@
1
+ /**
2
+ * @module Either
3
+ */
1
4
  import type { Either } from './either';
2
5
  /**
3
6
  * Type constructor for `Either`.
4
7
  * Creates either `Right` of the value provided,
5
8
  * or `Left` of the thrown error.
6
9
  */
7
- export declare function eitherSync<LeftValue, RightValue>(value: () => RightValue): Either<LeftValue, RightValue>;
8
- export default eitherSync;
10
+ export default function eitherSync<LeftValue, RightValue>(value: () => RightValue): Either<LeftValue, RightValue>;
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @module Either
3
+ */
1
4
  import { Left } from './left';
2
5
  import { Right } from './right';
3
6
  /**
@@ -11,5 +14,4 @@ export declare type Either<LeftValue, RightValue> = Left<LeftValue> | Right<Righ
11
14
  * Creates either `Right` of the value provided,
12
15
  * or `Left` of the error thrown.
13
16
  */
14
- export declare function either<LeftValue, RightValue>(value: () => Promise<RightValue>): Promise<Either<LeftValue, RightValue>>;
15
- export default either;
17
+ export default function either<LeftValue, RightValue>(value: () => Promise<RightValue>): Promise<Either<LeftValue, RightValue>>;
package/either/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { left, Left } from './left';
2
- export { right, Right } from './right';
3
- export { eitherSync } from './either-sync';
4
1
  export { default, Either } from './either';
2
+ export { default as left, Left } from './left';
3
+ export { default as right, Right } from './right';
4
+ export { default as eitherSync } from './either-sync';
package/either/left.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @module Either
3
+ */
1
4
  /**
2
5
  * Internal unique identifier for `Left`.
3
6
  */
@@ -15,5 +18,4 @@ export declare type Left<Value> = {
15
18
  * Creates the special object with one property, represented as unique symbol
16
19
  * key, holding the provided value.
17
20
  */
18
- export declare function left<Value>(value: Value): Left<Value>;
19
- export default left;
21
+ export default function left<Value>(value: Value): Left<Value>;
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @module Either Operators
3
+ */
1
4
  import type { Left } from '../../left';
2
5
  import type { Right } from '../../right';
3
6
  import type { Either } from '../../either';
@@ -9,5 +12,4 @@ export declare type Bifold<Monad extends Either<any, any>> = Monad extends Left<
9
12
  /**
10
13
  * Unwraps either the left or the right value of the provided `monad`.
11
14
  */
12
- export declare function bifold<Monad extends Either<any, any>>(monad: Monad): Bifold<Monad>;
13
- export default bifold;
15
+ export default function bifold<Monad extends Either<any, any>>(monad: Monad): Bifold<Monad>;
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @module Either Operators
3
+ */
1
4
  import { Left } from '../../left';
2
5
  import type { Either } from '../../either';
3
6
  /**
@@ -9,5 +12,4 @@ export declare type Bifoldl<Monad extends Either<any, any>> = Monad extends Left
9
12
  * Returns the left value of the provided `monad`.
10
13
  * If the `monad` is `Right`, returns `undefined`.
11
14
  */
12
- export declare function bifoldl<Monad extends Either<any, any>>(monad: Monad): Bifoldl<Monad>;
13
- export default bifoldl;
15
+ export default function bifoldl<Monad extends Either<any, any>>(monad: Monad): Bifoldl<Monad>;
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @module Either Operators
3
+ */
1
4
  import { Right } from '../../right';
2
5
  import type { Either } from '../../either';
3
6
  /**
@@ -9,5 +12,4 @@ export declare type Bifoldr<Monad extends Either<any, any>> = Monad extends Righ
9
12
  * Returns the right value of the provided `monad`.
10
13
  * If the `monad` is `Left`, returns `undefined`.
11
14
  */
12
- export declare function bifoldr<Monad extends Either<any, any>>(monad: Monad): Bifoldr<Monad>;
13
- export default bifoldr;
15
+ export default function bifoldr<Monad extends Either<any, any>>(monad: Monad): Bifoldr<Monad>;
@@ -1,3 +1,3 @@
1
- export { bifoldl, Bifoldl } from './bifoldl';
2
- export { bifoldr, Bifoldr } from './bifoldr';
3
- export { default, bifold, Bifold } from './bifold';
1
+ export { default, Bifold } from './bifold';
2
+ export { default as bifoldl, Bifoldl } from './bifoldl';
3
+ export { default as bifoldr, Bifoldr } from './bifoldr';
@@ -1,13 +1,15 @@
1
+ /**
2
+ * @module Either Operators
3
+ */
1
4
  import type { Either } from '../either';
2
- import type { Map } from '../../.internal/map';
5
+ import type { Map } from '../../types/map';
3
6
  /**
4
7
  * Maps left and right values of the provided `monad` to a value,
5
8
  * then returns it.
6
9
  */
7
- export declare function bifoldMap<LeftValue, RightValue, MappedValue>(mapLeft: Map<LeftValue, MappedValue>, mapRight: Map<RightValue, MappedValue>): (monad: Either<LeftValue, RightValue>) => MappedValue;
10
+ export default function bifoldMap<LeftValue, RightValue, MappedValue>(mapLeft: Map<LeftValue, MappedValue>, mapRight: Map<RightValue, MappedValue>): (monad: Either<LeftValue, RightValue>) => MappedValue;
8
11
  /**
9
12
  * Maps left and right values of the provided `monad` to a value,
10
13
  * then returns it.
11
14
  */
12
- export declare function bifoldMap<LeftValue, RightValue, MappedValue>(monad: Either<LeftValue, RightValue>, mapLeft: Map<LeftValue, MappedValue>, mapRight: Map<RightValue, MappedValue>): MappedValue;
13
- export default bifoldMap;
15
+ export default function bifoldMap<LeftValue, RightValue, MappedValue>(monad: Either<LeftValue, RightValue>, mapLeft: Map<LeftValue, MappedValue>, mapRight: Map<RightValue, MappedValue>): MappedValue;
@@ -1,11 +1,13 @@
1
+ /**
2
+ * @module Either Operators
3
+ */
1
4
  import type { Either } from '../../either';
2
- import type { Map } from '../../../.internal/map';
5
+ import type { Map } from '../../../types/map';
3
6
  /**
4
7
  * Maps left and right values of the provided `monad` to a new `Either` monad.
5
8
  */
6
- export declare function bimap<LeftValue, RightValue, NextLeftValue, NextRightValue>(mapLeft: Map<LeftValue, NextLeftValue>, mapRight: Map<RightValue, NextRightValue>): (monad: Either<LeftValue, RightValue>) => Either<NextLeftValue, NextRightValue>;
9
+ export default function bimap<LeftValue, RightValue, NextLeftValue, NextRightValue>(mapLeft: Map<LeftValue, NextLeftValue>, mapRight: Map<RightValue, NextRightValue>): (monad: Either<LeftValue, RightValue>) => Either<NextLeftValue, NextRightValue>;
7
10
  /**
8
11
  * Maps left and right values of the provided `monad` to a new `Either` monad.
9
12
  */
10
- export declare function bimap<LeftValue, RightValue, NextLeftValue, NextRightValue>(monad: Either<LeftValue, RightValue>, mapLeft: Map<LeftValue, NextLeftValue>, mapRight: Map<RightValue, NextRightValue>): Either<NextLeftValue, NextRightValue>;
11
- export default bimap;
13
+ export default function bimap<LeftValue, RightValue, NextLeftValue, NextRightValue>(monad: Either<LeftValue, RightValue>, mapLeft: Map<LeftValue, NextLeftValue>, mapRight: Map<RightValue, NextRightValue>): Either<NextLeftValue, NextRightValue>;
@@ -1,13 +1,15 @@
1
+ /**
2
+ * @module Either Operators
3
+ */
1
4
  import type { Either } from '../../either';
2
- import type { Map } from '../../../.internal/map';
5
+ import type { Map } from '../../../types/map';
3
6
  /**
4
7
  * Maps the left value of the provided `monad` to a new `Either` monad
5
8
  * with the same right value.
6
9
  */
7
- export declare function first<LeftValue, RightValue, NextLeftValue>(mapLeft: Map<LeftValue, NextLeftValue>): (monad: Either<LeftValue, RightValue>) => Either<NextLeftValue, RightValue>;
10
+ export default function first<LeftValue, RightValue, NextLeftValue>(mapLeft: Map<LeftValue, NextLeftValue>): (monad: Either<LeftValue, RightValue>) => Either<NextLeftValue, RightValue>;
8
11
  /**
9
12
  * Maps the left value of the provided `monad` to a new `Either` monad
10
13
  * with the same right value.
11
14
  */
12
- export declare function first<LeftValue, RightValue, NextLeftValue>(monad: Either<LeftValue, RightValue>, mapLeft: Map<LeftValue, NextLeftValue>): Either<NextLeftValue, RightValue>;
13
- export default first;
15
+ export default function first<LeftValue, RightValue, NextLeftValue>(monad: Either<LeftValue, RightValue>, mapLeft: Map<LeftValue, NextLeftValue>): Either<NextLeftValue, RightValue>;
@@ -1,3 +1,3 @@
1
- export { first } from './first';
2
- export { second } from './second';
3
- export { default, bimap } from './bimap';
1
+ export { default } from './bimap';
2
+ export { default as first } from './first';
3
+ export { default as second } from './second';
@@ -1,13 +1,15 @@
1
+ /**
2
+ * @module Either Operators
3
+ */
1
4
  import type { Either } from '../../either';
2
- import type { Map } from '../../../.internal/map';
5
+ import type { Map } from '../../../types/map';
3
6
  /**
4
7
  * Maps the right value of the provided `monad` to a new `Either` monad
5
8
  * with the same left value.
6
9
  */
7
- export declare function second<LeftValue, RightValue, NextRightValue>(mapRight: Map<RightValue, NextRightValue>): (monad: Either<LeftValue, RightValue>) => Either<LeftValue, NextRightValue>;
10
+ export default function second<LeftValue, RightValue, NextRightValue>(mapRight: Map<RightValue, NextRightValue>): (monad: Either<LeftValue, RightValue>) => Either<LeftValue, NextRightValue>;
8
11
  /**
9
12
  * Maps the right value of the provided `monad` to a new `Either` monad
10
13
  * with the same left value.
11
14
  */
12
- export declare function second<LeftValue, RightValue, NextRightValue>(monad: Either<LeftValue, RightValue>, mapRight: Map<RightValue, NextRightValue>): Either<LeftValue, NextRightValue>;
13
- export default second;
15
+ export default function second<LeftValue, RightValue, NextRightValue>(monad: Either<LeftValue, RightValue>, mapRight: Map<RightValue, NextRightValue>): Either<LeftValue, NextRightValue>;
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @module Either Operators
3
+ */
1
4
  import { Left } from '../left';
2
5
  import { Right } from '../right';
3
6
  import type { Either } from '../either';
@@ -1,4 +1,4 @@
1
- export { bifoldl, Bifoldl, bifoldr, Bifoldr, bifold, Bifold, } from './bifold';
1
+ export { bifoldl, Bifoldl, bifoldr, Bifoldr, default as bifold, Bifold, } from './bifold';
2
2
  export * from './guards';
3
- export * from './bifold-map';
4
- export { bimap, first, second } from './bimap';
3
+ export { default as bifoldMap } from './bifold-map';
4
+ export { default as bimap, first, second } from './bimap';
package/either/right.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @module Either
3
+ */
1
4
  /**
2
5
  * Internal unique identifier for `Right`.
3
6
  */
@@ -15,5 +18,4 @@ export declare type Right<Value> = {
15
18
  * Creates the special object with one property, represented as unique symbol
16
19
  * key, holding the provided value.
17
20
  */
18
- export declare function right<Value>(value: Value): Right<Value>;
19
- export default right;
21
+ export default function right<Value>(value: Value): Right<Value>;
package/esm/compose.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @module Composition
3
+ */
4
+ /**
5
+ * Applies all of the provided `functions` one-by-one in right-to-left order
6
+ * starting from the `argument`.
7
+ */
8
+ export default function compose(...functions) {
9
+ return (arg) => {
10
+ const length = functions.length;
11
+ let composition = arg;
12
+ for (let index = length - 1; index >= 0; index -= 1) {
13
+ const current = functions[index];
14
+ composition = current(composition);
15
+ }
16
+ return composition;
17
+ };
18
+ }
package/esm/curry.js ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @module Curry
3
+ */
4
+ /**
5
+ * Creates an auto-curried function from the one provided.
6
+ * Until the curried function receives an expected number of arguments,
7
+ * defined by either its `length` property or the `length` argument of `curry`,
8
+ * it will return new function which receives from one to the remaining amount
9
+ * of arguments.
10
+ * Any excess arguments will not be applied.
11
+ */
12
+ export default function curry(fn, length = fn.length) {
13
+ return (...args) => {
14
+ const argsLength = args.length;
15
+ if (argsLength === length) {
16
+ return fn(...args);
17
+ }
18
+ if (argsLength > length) {
19
+ return fn(...args.slice(0, length));
20
+ }
21
+ return curry((...nextArgs) => fn(...args.concat(nextArgs)), length - argsLength);
22
+ };
23
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @module Either
3
+ */
4
+ import left from './left';
5
+ import right from './right';
6
+ /**
7
+ * Type constructor for `Either`.
8
+ * Creates either `Right` of the value provided,
9
+ * or `Left` of the thrown error.
10
+ */
11
+ export default function eitherSync(value) {
12
+ try {
13
+ return right(value());
14
+ }
15
+ catch (error) {
16
+ return left(error);
17
+ }
18
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @module Either
3
+ */
4
+ import left from './left';
5
+ import right from './right';
6
+ /**
7
+ * Type constructor for `Either`.
8
+ * Creates either `Right` of the value provided,
9
+ * or `Left` of the error thrown.
10
+ */
11
+ export default function either(value) {
12
+ return value()
13
+ .then(right)
14
+ .catch(left);
15
+ }
@@ -0,0 +1,4 @@
1
+ export { default } from './either';
2
+ export { default as left } from './left';
3
+ export { default as right } from './right';
4
+ export { default as eitherSync } from './either-sync';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @module Either
3
+ */
4
+ /**
5
+ * Internal unique identifier for `Left`.
6
+ */
7
+ export const lid = Symbol.for('@@functional/left');
8
+ /**
9
+ * Constructor function for `Left`.
10
+ * Creates the special object with one property, represented as unique symbol
11
+ * key, holding the provided value.
12
+ */
13
+ export default function left(value) {
14
+ return {
15
+ [lid]: value
16
+ };
17
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @module Either Operators
3
+ */
4
+ import bifoldl from './bifoldl';
5
+ import bifoldr from './bifoldr';
6
+ /**
7
+ * Unwraps either the left or the right value of the provided `monad`.
8
+ */
9
+ export default function bifold(monad) {
10
+ var _a;
11
+ return (_a = bifoldl(monad)) !== null && _a !== void 0 ? _a : bifoldr(monad);
12
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @module Either Operators
3
+ */
4
+ import { isLeft } from '../guards';
5
+ import { lid } from '../../left';
6
+ /**
7
+ * Returns the left value of the provided `monad`.
8
+ * If the `monad` is `Right`, returns `undefined`.
9
+ */
10
+ export default function bifoldl(monad) {
11
+ return isLeft(monad)
12
+ ? monad[lid]
13
+ : undefined;
14
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @module Either Operators
3
+ */
4
+ import { isRight } from '../guards';
5
+ import { rid } from '../../right';
6
+ /**
7
+ * Returns the right value of the provided `monad`.
8
+ * If the `monad` is `Left`, returns `undefined`.
9
+ */
10
+ export default function bifoldr(monad) {
11
+ return isRight(monad)
12
+ ? monad[rid]
13
+ : undefined;
14
+ }
@@ -0,0 +1,3 @@
1
+ export { default } from './bifold';
2
+ export { default as bifoldl } from './bifoldl';
3
+ export { default as bifoldr } from './bifoldr';