fnts 1.1.1 → 1.3.2

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 (95) hide show
  1. package/README.md +4 -50
  2. package/compose.d.ts +9 -9
  3. package/compose.js +24 -1
  4. package/curry.d.ts +8 -5
  5. package/curry.js +37 -1
  6. package/either/either-sync.d.ts +4 -2
  7. package/either/either-sync.js +21 -1
  8. package/either/either.d.ts +4 -2
  9. package/either/either.js +18 -1
  10. package/either/index.d.ts +3 -3
  11. package/either/index.js +11 -1
  12. package/either/left.d.ts +4 -2
  13. package/either/left.js +22 -1
  14. package/either/operators/bifold/bifold.d.ts +4 -2
  15. package/either/operators/bifold/bifold.js +15 -1
  16. package/either/operators/bifold/bifoldl.d.ts +4 -2
  17. package/either/operators/bifold/bifoldl.js +17 -1
  18. package/either/operators/bifold/bifoldr.d.ts +4 -2
  19. package/either/operators/bifold/bifoldr.js +17 -1
  20. package/either/operators/bifold/index.d.ts +3 -3
  21. package/either/operators/bifold/index.js +9 -1
  22. package/either/operators/bifold-map.d.ts +6 -4
  23. package/either/operators/bifold-map.js +20 -1
  24. package/either/operators/bimap/bimap.d.ts +6 -4
  25. package/either/operators/bimap/bimap.js +20 -1
  26. package/either/operators/bimap/first.d.ts +6 -4
  27. package/either/operators/bimap/first.js +22 -1
  28. package/either/operators/bimap/index.d.ts +3 -3
  29. package/either/operators/bimap/index.js +9 -1
  30. package/either/operators/bimap/second.d.ts +6 -4
  31. package/either/operators/bimap/second.js +22 -1
  32. package/either/operators/guards.d.ts +3 -0
  33. package/either/operators/guards.js +22 -1
  34. package/either/operators/index.d.ts +3 -3
  35. package/either/operators/index.js +24 -1
  36. package/either/right.d.ts +4 -2
  37. package/either/right.js +22 -1
  38. package/guard.d.ts +6 -3
  39. package/guard.js +36 -1
  40. package/identity.d.ts +4 -2
  41. package/identity.js +12 -1
  42. package/index.d.ts +9 -5
  43. package/index.js +21 -1
  44. package/inject.d.ts +15 -0
  45. package/inject.js +23 -0
  46. package/maybe/index.d.ts +2 -2
  47. package/maybe/index.js +9 -1
  48. package/maybe/just.d.ts +4 -2
  49. package/maybe/just.js +22 -1
  50. package/maybe/maybe.d.ts +4 -2
  51. package/maybe/maybe.js +17 -1
  52. package/maybe/nothing.d.ts +4 -2
  53. package/maybe/nothing.js +22 -1
  54. package/maybe/operators/bind.d.ts +6 -4
  55. package/maybe/operators/bind.js +21 -1
  56. package/maybe/operators/fmap.d.ts +6 -4
  57. package/maybe/operators/fmap.js +22 -1
  58. package/maybe/operators/fold-map.d.ts +10 -8
  59. package/maybe/operators/fold-map.js +20 -1
  60. package/maybe/operators/fold.d.ts +4 -2
  61. package/maybe/operators/fold.js +17 -1
  62. package/maybe/operators/guards.d.ts +3 -0
  63. package/maybe/operators/guards.js +22 -1
  64. package/maybe/operators/index.d.ts +4 -4
  65. package/maybe/operators/index.js +14 -1
  66. package/package.json +10 -4
  67. package/permutation/index.d.ts +2 -0
  68. package/permutation/index.js +7 -0
  69. package/permutation/permutation-2.d.ts +8 -0
  70. package/permutation/permutation-2.js +18 -0
  71. package/permutation/permutation-3.d.ts +8 -0
  72. package/permutation/permutation-3.js +18 -0
  73. package/pipe.d.ts +9 -9
  74. package/pipe.js +24 -1
  75. package/rethrow.d.ts +9 -0
  76. package/rethrow.js +16 -0
  77. package/tap.d.ts +11 -0
  78. package/tap.js +15 -0
  79. package/ternary.d.ts +10 -0
  80. package/ternary.js +16 -0
  81. package/tsconfig.json +1 -1
  82. package/types/effect.d.ts +11 -0
  83. package/types/function.d.ts +13 -0
  84. package/types/gradual.d.ts +17 -0
  85. package/types/index.d.ts +7 -0
  86. package/{.internal → types}/last.d.ts +7 -0
  87. package/types/map.d.ts +8 -0
  88. package/{.internal → types}/slice.d.ts +7 -0
  89. package/{.internal → types}/tuple.d.ts +6 -0
  90. package/.internal/gradual.d.ts +0 -5
  91. package/.internal/map.d.ts +0 -1
  92. package/.internal/permutation-of-2.d.ts +0 -1
  93. package/.internal/permutation-of-2.js +0 -1
  94. package/.internal/permutation-of-3.d.ts +0 -1
  95. package/.internal/permutation-of-3.js +0 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <p align="center">
2
2
  <img src="https://raw.githubusercontent.com/drizzer14/fnts/main/logo.svg" height="64" />
3
- <h1 align="center">fnts</h1>
3
+ <h1 align="center">λ fnts</h1>
4
4
  </p>
5
5
 
6
6
  <p align="center">
@@ -24,62 +24,16 @@ TypeScript / JavaScript functional programming utilities inspired by the
24
24
  **TypeScript 4.2.2 is required for this package's typings to work properly.**
25
25
 
26
26
  ```shell
27
- λ npm i fnts typescript@4.2.2
27
+ npm i fnts
28
28
  ```
29
29
 
30
30
  ```shell
31
- λ yarn add fnts typescript@4.2.2
31
+ yarn add fnts
32
32
  ```
33
33
 
34
34
  ## Usage
35
35
 
36
- Every function comes with its own module providing the named export of every public API
37
- and default export of the function itself:
38
-
39
- ```typescript
40
- import compose from 'fnts/compose'
41
- import maybe, { Maybe } from 'fnts/maybe'
42
- ```
43
-
44
- Also, it is possible to import everything from the root by name:
45
-
46
- ```typescript
47
- import { compose, maybe, identity } from 'fnts'
48
- ```
49
-
50
- ### Currying
51
-
52
- The [curry](src/curry.ts) function is an attempt to create
53
- a generic currying without relying on overloads.
54
- It supports the currying of functions with a set amount of arguments,
55
- as well as variadic functions or the functions with optional arguments.
56
- The last two, though, require you to set the threshold upon which to curry them,
57
- as JavaScript does not supply the information about the number of arguments
58
- in those kinds of functions.
59
-
60
- ### Composition and pipelines
61
-
62
- [Compose](src/compose.ts) and [pipe](src/pipe.ts) functions you'll encounter
63
- here are pretty unique in their implementation, as they also are described
64
- generically rather than through overloads.
65
- If you encounter any unexpected behaviour in them,
66
- please feel free to create an [issue](https://github.com/drizzer14/fnts/issues).
67
-
68
- ### Monads
69
-
70
- There are two commonly used monads in this package:
71
- [Maybe](src/maybe/maybe.ts) and [Either](src/either/either.ts).
72
-
73
- Both have their own set of constructors, which rely upon special tags
74
- represented through symbols – this way the "operators" know you pass them
75
- the objects related to those monads
76
- (e.g. [just](src/maybe/maybe.ts) and [nothing](src/maybe/maybe.ts) from `Maybe` monad).
77
-
78
- For both monads there are aforementioned operators,
79
- which can perform different transformations on their monads.
80
- These operators look just like plain functions, so,
81
- if you are familiar with Haskell or RxJS,
82
- you should quickly get a grasp on them.
36
+ Please, visit the [documentation](https://drizzer14.github.io/fnts) to obtain the information about the usage and API of `fnts`.
83
37
 
84
38
  ## Motivation
85
39
 
package/compose.d.ts CHANGED
@@ -1,4 +1,8 @@
1
- import type { Last } from './.internal/last';
1
+ /**
2
+ * @module Composition
3
+ */
4
+ import type { Last } from './types/last';
5
+ import type { UnaryFunction } from './types/function';
2
6
  /**
3
7
  * Creates a `Composition` type which parses all of the provided functions' types.
4
8
  * Any function with either an incorrect argument or a return type will not fit
@@ -6,16 +10,12 @@ import type { Last } from './.internal/last';
6
10
  * type matches the return type of the next function and its return type
7
11
  * matches the type of the previous function's argument.
8
12
  */
9
- export declare type Composition<Functions extends Array<(...args: any[]) => any>, Length extends number = Functions['length']> = Length extends 1 ? Functions : Functions extends [...infer Rest, infer Penultimate, infer Last] ? [
10
- ...Composition<[
11
- ...Rest,
12
- (arg: ReturnType<Last>) => ReturnType<Penultimate>
13
- ]>,
13
+ export declare type Composition<Functions extends UnaryFunction[], 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 : never : never>,
14
15
  Last
15
- ] : any;
16
+ ] : Functions;
16
17
  /**
17
18
  * Applies all of the provided `functions` one-by-one in right-to-left order
18
19
  * starting from the `argument`.
19
20
  */
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;
21
+ export default function compose<Functions extends UnaryFunction[]>(...functions: Composition<Functions>): (arg: Parameters<Last<Functions>>[0]) => ReturnType<Functions[0]>;
package/compose.js CHANGED
@@ -1 +1,24 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.compose=compose,exports.default=void 0;function compose(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return a=>{for(var c,d=b.length,e=a,f=d-1;0<=f;f-=1)c=b[f],e=c(e);return e}}var _default=compose;exports.default=_default;
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 right-to-left order
8
+ * starting from the `argument`.
9
+ */
10
+ function compose() {
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 composition = arg;
18
+ for (var index = length - 1; index >= 0; index -= 1) {
19
+ composition = functions[index](composition);
20
+ }
21
+ return composition;
22
+ };
23
+ }
24
+ exports.default = compose;
package/curry.d.ts CHANGED
@@ -1,9 +1,13 @@
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';
6
+ import type { VariadicFunction } from './types/function';
3
7
  /**
4
8
  * Creates a type for an auto-curried function.
5
9
  */
6
- export declare type Currying<Function extends (...args: any[]) => any, Length extends number = Parameters<Function>['length']> = <Args extends Gradual<Parameters<Function>>>(...args: Args) => Args['length'] extends 1 ? (arg: Parameters<Function>[0]) => ReturnType<Function> : Args['length'] extends Length ? ReturnType<Function> : Currying<(...args: Slice<Parameters<Function>, Args['length']>) => ReturnType<Function>>;
10
+ export declare type Currying<Function extends VariadicFunction, Length extends number = Parameters<Function>['length']> = <Args extends Gradual<Parameters<Function>>>(...args: Args) => Args['length'] extends Length ? ReturnType<Function> : Currying<(...args: Slice<Parameters<Function>, Args['length']>) => ReturnType<Function>>;
7
11
  /**
8
12
  * Creates an auto-curried function from the one provided.
9
13
  * Until the curried function receives an expected number of arguments,
@@ -12,5 +16,4 @@ export declare type Currying<Function extends (...args: any[]) => any, Length ex
12
16
  * of arguments.
13
17
  * Any excess arguments will not be applied.
14
18
  */
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;
19
+ export default function curry<Function extends VariadicFunction, Length extends number = Parameters<Function>['length']>(fn: Function, length?: Length): Currying<Function, Length>;
package/curry.js CHANGED
@@ -1 +1,37 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.curry=curry,exports.default=void 0;function curry(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:a.length;return function(){for(var c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];var f=d.length;return f===b?a.apply(void 0,d):f>b?a.apply(void 0,d.slice(0,b)):curry(a.bind(void 0,...d))}}var _default=curry;exports.default=_default;
1
+ "use strict";
2
+ /**
3
+ * @module Curry
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ /**
7
+ * Creates an auto-curried function from the one provided.
8
+ * Until the curried function receives an expected number of arguments,
9
+ * defined by either its `length` property or the `length` argument of `curry`,
10
+ * it will return new function which receives from one to the remaining amount
11
+ * of arguments.
12
+ * Any excess arguments will not be applied.
13
+ */
14
+ function curry(fn, length) {
15
+ if (length === void 0) { length = fn.length; }
16
+ return function () {
17
+ var args = [];
18
+ for (var _i = 0; _i < arguments.length; _i++) {
19
+ args[_i] = arguments[_i];
20
+ }
21
+ var argsLength = args.length;
22
+ if (argsLength === length) {
23
+ return fn.apply(void 0, args);
24
+ }
25
+ if (argsLength > length) {
26
+ return fn.apply(void 0, args.slice(0, length));
27
+ }
28
+ return curry(function () {
29
+ var nextArgs = [];
30
+ for (var _i = 0; _i < arguments.length; _i++) {
31
+ nextArgs[_i] = arguments[_i];
32
+ }
33
+ return fn.apply(void 0, args.concat(nextArgs));
34
+ }, length - argsLength);
35
+ };
36
+ }
37
+ exports.default = curry;
@@ -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 +1,21 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.eitherSync=eitherSync,exports.default=void 0;var _left=_interopRequireDefault(require("./left")),_right=_interopRequireDefault(require("./right"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function eitherSync(a){try{return(0,_right.default)(a())}catch(a){return(0,_left.default)(a)}}var _default=eitherSync;exports.default=_default;
1
+ "use strict";
2
+ /**
3
+ * @module Either
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var left_1 = require("./left");
7
+ var right_1 = require("./right");
8
+ /**
9
+ * Type constructor for `Either`.
10
+ * Creates either `Right` of the value provided,
11
+ * or `Left` of the thrown error.
12
+ */
13
+ function eitherSync(value) {
14
+ try {
15
+ return right_1.default(value());
16
+ }
17
+ catch (error) {
18
+ return left_1.default(error);
19
+ }
20
+ }
21
+ exports.default = eitherSync;
@@ -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/either.js CHANGED
@@ -1 +1,18 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.either=either,exports.default=void 0;var _left=_interopRequireWildcard(require("./left")),_right=_interopRequireWildcard(require("./right"));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;return _getRequireWildcardCache=function(){return a},a}function _interopRequireWildcard(a){if(a&&a.__esModule)return a;if(null===a||"object"!=typeof a&&"function"!=typeof a)return{default:a};var b=_getRequireWildcardCache();if(b&&b.has(a))return b.get(a);var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a)if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;f&&(f.get||f.set)?Object.defineProperty(c,e,f):c[e]=a[e]}return c.default=a,b&&b.set(a,c),c}function either(a){return a().then(_right.default).catch(_left.default)}var _default=either;exports.default=_default;
1
+ "use strict";
2
+ /**
3
+ * @module Either
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var left_1 = require("./left");
7
+ var right_1 = require("./right");
8
+ /**
9
+ * Type constructor for `Either`.
10
+ * Creates either `Right` of the value provided,
11
+ * or `Left` of the error thrown.
12
+ */
13
+ function either(value) {
14
+ return value()
15
+ .then(right_1.default)
16
+ .catch(left_1.default);
17
+ }
18
+ exports.default = either;
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/index.js CHANGED
@@ -1 +1,11 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"left",{enumerable:!0,get:function get(){return _left.left}}),Object.defineProperty(exports,"Left",{enumerable:!0,get:function get(){return _left.Left}}),Object.defineProperty(exports,"right",{enumerable:!0,get:function get(){return _right.right}}),Object.defineProperty(exports,"Right",{enumerable:!0,get:function get(){return _right.Right}}),Object.defineProperty(exports,"eitherSync",{enumerable:!0,get:function get(){return _eitherSync.eitherSync}}),Object.defineProperty(exports,"default",{enumerable:!0,get:function get(){return _either.default}}),Object.defineProperty(exports,"Either",{enumerable:!0,get:function get(){return _either.Either}});var _left=require("./left"),_right=require("./right"),_eitherSync=require("./either-sync"),_either=_interopRequireWildcard(require("./either"));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;return _getRequireWildcardCache=function(){return a},a}function _interopRequireWildcard(a){if(a&&a.__esModule)return a;if(null===a||"object"!=typeof a&&"function"!=typeof a)return{default:a};var b=_getRequireWildcardCache();if(b&&b.has(a))return b.get(a);var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a)if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;f&&(f.get||f.set)?Object.defineProperty(c,e,f):c[e]=a[e]}return c.default=a,b&&b.set(a,c),c}
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.eitherSync = exports.right = exports.left = exports.default = void 0;
4
+ var either_1 = require("./either");
5
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return either_1.default; } });
6
+ var left_1 = require("./left");
7
+ Object.defineProperty(exports, "left", { enumerable: true, get: function () { return left_1.default; } });
8
+ var right_1 = require("./right");
9
+ Object.defineProperty(exports, "right", { enumerable: true, get: function () { return right_1.default; } });
10
+ var either_sync_1 = require("./either-sync");
11
+ Object.defineProperty(exports, "eitherSync", { enumerable: true, get: function () { return either_sync_1.default; } });
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>;
package/either/left.js CHANGED
@@ -1 +1,22 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.left=left,exports.default=exports.lid=void 0;var lid=Symbol.for("@@functional/left");exports.lid=lid;function left(a){return{[lid]:a}}var _default=left;exports.default=_default;
1
+ "use strict";
2
+ /**
3
+ * @module Either
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.lid = void 0;
7
+ /**
8
+ * Internal unique identifier for `Left`.
9
+ */
10
+ exports.lid = Symbol.for('@@functional/left');
11
+ /**
12
+ * Constructor function for `Left`.
13
+ * Creates the special object with one property, represented as unique symbol
14
+ * key, holding the provided value.
15
+ */
16
+ function left(value) {
17
+ var _a;
18
+ return _a = {},
19
+ _a[exports.lid] = value,
20
+ _a;
21
+ }
22
+ exports.default = left;
@@ -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 +1,15 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.bifold=bifold,exports.default=void 0;var _bifoldl2=_interopRequireDefault(require("./bifoldl")),_bifoldr=_interopRequireDefault(require("./bifoldr"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function bifold(a){var b;return null!==(b=(0,_bifoldl2.default)(a))&&void 0!==b?b:(0,_bifoldr.default)(a)}var _default=bifold;exports.default=_default;
1
+ "use strict";
2
+ /**
3
+ * @module Either Operators
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var bifoldl_1 = require("./bifoldl");
7
+ var bifoldr_1 = require("./bifoldr");
8
+ /**
9
+ * Unwraps either the left or the right value of the provided `monad`.
10
+ */
11
+ function bifold(monad) {
12
+ var _a;
13
+ return (_a = bifoldl_1.default(monad)) !== null && _a !== void 0 ? _a : bifoldr_1.default(monad);
14
+ }
15
+ exports.default = bifold;
@@ -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 +1,17 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.bifoldl=bifoldl,exports.default=void 0;var _guards=require("../guards"),_left=require("../../left");function bifoldl(a){return(0,_guards.isLeft)(a)?a[_left.lid]:void 0}var _default=bifoldl;exports.default=_default;
1
+ "use strict";
2
+ /**
3
+ * @module Either Operators
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var guards_1 = require("../guards");
7
+ var left_1 = require("../../left");
8
+ /**
9
+ * Returns the left value of the provided `monad`.
10
+ * If the `monad` is `Right`, returns `undefined`.
11
+ */
12
+ function bifoldl(monad) {
13
+ return guards_1.isLeft(monad)
14
+ ? monad[left_1.lid]
15
+ : undefined;
16
+ }
17
+ exports.default = bifoldl;
@@ -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 +1,17 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.bifoldr=bifoldr,exports.default=void 0;var _guards=require("../guards"),_right=require("../../right");function bifoldr(a){return(0,_guards.isRight)(a)?a[_right.rid]:void 0}var _default=bifoldr;exports.default=_default;
1
+ "use strict";
2
+ /**
3
+ * @module Either Operators
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var guards_1 = require("../guards");
7
+ var right_1 = require("../../right");
8
+ /**
9
+ * Returns the right value of the provided `monad`.
10
+ * If the `monad` is `Left`, returns `undefined`.
11
+ */
12
+ function bifoldr(monad) {
13
+ return guards_1.isRight(monad)
14
+ ? monad[right_1.rid]
15
+ : undefined;
16
+ }
17
+ exports.default = bifoldr;
@@ -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 +1,9 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"bifoldl",{enumerable:!0,get:function get(){return _bifoldl.bifoldl}}),Object.defineProperty(exports,"Bifoldl",{enumerable:!0,get:function get(){return _bifoldl.Bifoldl}}),Object.defineProperty(exports,"bifoldr",{enumerable:!0,get:function get(){return _bifoldr.bifoldr}}),Object.defineProperty(exports,"Bifoldr",{enumerable:!0,get:function get(){return _bifoldr.Bifoldr}}),Object.defineProperty(exports,"default",{enumerable:!0,get:function get(){return _bifold.default}}),Object.defineProperty(exports,"bifold",{enumerable:!0,get:function get(){return _bifold.bifold}}),Object.defineProperty(exports,"Bifold",{enumerable:!0,get:function get(){return _bifold.Bifold}});var _bifoldl=require("./bifoldl"),_bifoldr=require("./bifoldr"),_bifold=_interopRequireWildcard(require("./bifold"));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;return _getRequireWildcardCache=function(){return a},a}function _interopRequireWildcard(a){if(a&&a.__esModule)return a;if(null===a||"object"!=typeof a&&"function"!=typeof a)return{default:a};var b=_getRequireWildcardCache();if(b&&b.has(a))return b.get(a);var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a)if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;f&&(f.get||f.set)?Object.defineProperty(c,e,f):c[e]=a[e]}return c.default=a,b&&b.set(a,c),c}
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bifoldr = exports.bifoldl = exports.default = void 0;
4
+ var bifold_1 = require("./bifold");
5
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return bifold_1.default; } });
6
+ var bifoldl_1 = require("./bifoldl");
7
+ Object.defineProperty(exports, "bifoldl", { enumerable: true, get: function () { return bifoldl_1.default; } });
8
+ var bifoldr_1 = require("./bifoldr");
9
+ Object.defineProperty(exports, "bifoldr", { enumerable: true, get: function () { return bifoldr_1.default; } });
@@ -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 +1,20 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.bifoldMap=bifoldMap,exports.default=void 0;var _compose=_interopRequireDefault(require("../../compose")),_permutationOf=_interopRequireDefault(require("../../.internal/permutation-of-3")),_guards=require("./guards"),_bifold=require("./bifold");function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function bifoldMap(){return(0,_permutationOf.default)((a,b,c)=>(0,_guards.isLeft)(a)?(0,_compose.default)(b,_bifold.bifoldl)(a):(0,_compose.default)(c,_bifold.bifoldr)(a))(...arguments)}var _default=bifoldMap;exports.default=_default;
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_3_1 = require("../../permutation/permutation-3");
9
+ var guards_1 = require("./guards");
10
+ var bifold_1 = require("./bifold");
11
+ function bifoldMap() {
12
+ var args = [];
13
+ for (var _i = 0; _i < arguments.length; _i++) {
14
+ args[_i] = arguments[_i];
15
+ }
16
+ return permutation_3_1.default(function (monad, mapLeft, mapRight) {
17
+ return ternary_1.default(guards_1.isLeft, compose_1.default(mapLeft, bifold_1.bifoldl), compose_1.default(mapRight, bifold_1.bifoldr))(monad);
18
+ }).apply(void 0, args);
19
+ }
20
+ exports.default = bifoldMap;
@@ -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 +1,20 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.bimap=bimap,exports.default=void 0;var _guards=require("../guards"),_permutationOf=_interopRequireDefault(require("../../../.internal/permutation-of-3")),_first=_interopRequireDefault(require("./first")),_second=_interopRequireDefault(require("./second"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function bimap(){return(0,_permutationOf.default)((a,b,c)=>(0,_guards.isLeft)(a)?(0,_first.default)(a,b):(0,_second.default)(a,c))(...arguments)}var _default=bimap;exports.default=_default;
1
+ "use strict";
2
+ /**
3
+ * @module Either Operators
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var guards_1 = require("../guards");
7
+ var ternary_1 = require("../../../ternary");
8
+ var permutation_3_1 = require("../../../permutation/permutation-3");
9
+ var first_1 = require("./first");
10
+ var second_1 = require("./second");
11
+ function bimap() {
12
+ var args = [];
13
+ for (var _i = 0; _i < arguments.length; _i++) {
14
+ args[_i] = arguments[_i];
15
+ }
16
+ return permutation_3_1.default(function (monad, mapLeft, mapRight) {
17
+ return ternary_1.default(guards_1.isLeft, first_1.default(mapLeft), second_1.default(mapRight))(monad);
18
+ }).apply(void 0, args);
19
+ }
20
+ exports.default = bimap;
@@ -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 +1,22 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.first=first,exports.default=void 0;var _guards=require("../guards"),_bifold=require("../bifold"),_compose=_interopRequireDefault(require("../../../compose")),_left=_interopRequireWildcard(require("../../left")),_permutationOf=_interopRequireDefault(require("../../../.internal/permutation-of-2"));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;return _getRequireWildcardCache=function(){return a},a}function _interopRequireWildcard(a){if(a&&a.__esModule)return a;if(null===a||"object"!=typeof a&&"function"!=typeof a)return{default:a};var b=_getRequireWildcardCache();if(b&&b.has(a))return b.get(a);var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a)if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;f&&(f.get||f.set)?Object.defineProperty(c,e,f):c[e]=a[e]}return c.default=a,b&&b.set(a,c),c}function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function first(){return(0,_permutationOf.default)((a,b)=>(0,_guards.isLeft)(a)?(0,_compose.default)(_left.default,b,_bifold.bifoldl)(a):a)(...arguments)}var _default=first;exports.default=_default;
1
+ "use strict";
2
+ /**
3
+ * @module Either Operators
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var guards_1 = require("../guards");
7
+ var bifold_1 = require("../bifold");
8
+ var compose_1 = require("../../../compose");
9
+ var ternary_1 = require("../../../ternary");
10
+ var left_1 = require("../../left");
11
+ var identity_1 = require("../../../identity");
12
+ var permutation_2_1 = require("../../../permutation/permutation-2");
13
+ function first() {
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, mapLeft) {
19
+ return ternary_1.default(guards_1.isLeft, compose_1.default(left_1.default, mapLeft, bifold_1.bifoldl), identity_1.default)(monad);
20
+ }).apply(void 0, args);
21
+ }
22
+ exports.default = first;
@@ -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 +1,9 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"first",{enumerable:!0,get:function get(){return _first.first}}),Object.defineProperty(exports,"second",{enumerable:!0,get:function get(){return _second.second}}),Object.defineProperty(exports,"default",{enumerable:!0,get:function get(){return _bimap.default}}),Object.defineProperty(exports,"bimap",{enumerable:!0,get:function get(){return _bimap.bimap}});var _first=require("./first"),_second=require("./second"),_bimap=_interopRequireWildcard(require("./bimap"));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;return _getRequireWildcardCache=function(){return a},a}function _interopRequireWildcard(a){if(a&&a.__esModule)return a;if(null===a||"object"!=typeof a&&"function"!=typeof a)return{default:a};var b=_getRequireWildcardCache();if(b&&b.has(a))return b.get(a);var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a)if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;f&&(f.get||f.set)?Object.defineProperty(c,e,f):c[e]=a[e]}return c.default=a,b&&b.set(a,c),c}
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.second = exports.first = exports.default = void 0;
4
+ var bimap_1 = require("./bimap");
5
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return bimap_1.default; } });
6
+ var first_1 = require("./first");
7
+ Object.defineProperty(exports, "first", { enumerable: true, get: function () { return first_1.default; } });
8
+ var second_1 = require("./second");
9
+ Object.defineProperty(exports, "second", { enumerable: true, get: function () { return second_1.default; } });