fnts 1.1.0 → 1.3.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 (95) hide show
  1. package/README.md +4 -50
  2. package/compose.d.ts +5 -3
  3. package/compose.js +25 -1
  4. package/curry.d.ts +6 -4
  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 +6 -45
  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 +14 -3
  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 +5 -3
  39. package/guard.js +37 -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 +14 -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 +6 -31
  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 +14 -3
  55. package/maybe/operators/bind.js +21 -1
  56. package/maybe/operators/fmap.d.ts +14 -3
  57. package/maybe/operators/fmap.js +22 -1
  58. package/maybe/operators/fold-map.d.ts +37 -5
  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 +7 -0
  70. package/permutation/permutation-2.js +18 -0
  71. package/permutation/permutation-3.d.ts +7 -0
  72. package/permutation/permutation-3.js +18 -0
  73. package/pipe.d.ts +5 -3
  74. package/pipe.js +25 -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 +9 -0
  83. package/types/gradual.d.ts +17 -0
  84. package/{.internal → types}/last.d.ts +7 -0
  85. package/types/map.d.ts +8 -0
  86. package/{.internal → types}/slice.d.ts +7 -0
  87. package/{.internal → types}/tuple.d.ts +6 -0
  88. package/.internal/gradual.d.ts +0 -5
  89. package/.internal/map.d.ts +0 -1
  90. package/.internal/permutation-of-2.d.ts +0 -1
  91. package/.internal/permutation-of-2.js +0 -1
  92. package/.internal/permutation-of-3.d.ts +0 -1
  93. package/.internal/permutation-of-3.js +0 -1
  94. package/either/operators/bifold.d.ts +0 -31
  95. package/either/operators/bimap.d.ts +0 -29
@@ -1,9 +1,41 @@
1
- import type { Map } from '../../.internal/map';
2
- import type { Maybe, Nothing } from '../maybe';
3
- export declare function foldMap<Value, NextValue>(monad: Nothing, transition: Map<Value, NextValue>): null;
1
+ /**
2
+ * @module Maybe Operators
3
+ */
4
+ import type { Just } from '../just';
5
+ import type { Maybe } from '../maybe';
6
+ import type { Nothing } from '../nothing';
7
+ import type { Map } from '../../types/map';
8
+ /**
9
+ * A type to unwrap the provided `Monad` into the new value type.
10
+ */
11
+ export declare type FoldMap<Monad extends Maybe<any>, NextValue> = Monad extends Just<any> ? NextValue : Monad extends Nothing ? null : never;
12
+ /**
13
+ * Maps the value of the provided `monad` through the `transition` function
14
+ * and returns the mapped value or `null`.
15
+ */
16
+ export default function foldMap<Value, NextValue = Value>(transition: Map<Value, NextValue>): (monad: Just<Value>) => NextValue;
17
+ /**
18
+ * Maps the value of the provided `monad` through the `transition` function
19
+ * and returns the mapped value or `null`.
20
+ */
21
+ export default function foldMap<Value, NextValue = Value>(transition: Map<Value, NextValue>): (monad: Nothing) => null;
22
+ /**
23
+ * Maps the value of the provided `monad` through the `transition` function
24
+ * and returns the mapped value or `null`.
25
+ */
26
+ export default function foldMap<Value, NextValue = Value>(transition: Map<Value, NextValue>): (monad: Maybe<Value>) => NextValue | null;
27
+ /**
28
+ * Maps the value of the provided `monad` through the `transition` function
29
+ * and returns the mapped value or `null`.
30
+ */
31
+ export default function foldMap<Value, NextValue = Value>(monad: Just<Value>, transition: Map<Value, NextValue>): NextValue;
32
+ /**
33
+ * Maps the value of the provided `monad` through the `transition` function
34
+ * and returns the mapped value or `null`.
35
+ */
36
+ export default function foldMap<Value, NextValue = Value>(monad: Nothing, transition: Map<Value, NextValue>): null;
4
37
  /**
5
38
  * Maps the value of the provided `monad` through the `transition` function
6
39
  * and returns the mapped value or `null`.
7
40
  */
8
- export declare function foldMap<Value, NextValue>(monad: Maybe<Value>, transition: Map<Value, NextValue>): NextValue | null;
9
- export default foldMap;
41
+ export default function foldMap<Value, NextValue = Value>(monad: Maybe<Value>, transition: Map<Value, NextValue>): NextValue | null;
@@ -1 +1,20 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.foldMap=foldMap,exports.default=void 0;var _compose=_interopRequireDefault(require("../../compose")),_permutationOf=_interopRequireDefault(require("../../.internal/permutation-of-2")),_fold=_interopRequireDefault(require("./fold")),_guards=require("./guards");function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function foldMap(){return(0,_permutationOf.default)((a,b)=>(0,_guards.isJust)(a)?(0,_compose.default)(b,_fold.default)(a):null)(...arguments)}var _default=foldMap;exports.default=_default;
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;
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @module Maybe Operators
3
+ */
1
4
  import { Just } from '../just';
2
5
  import type { Maybe } from '../maybe';
3
6
  import { Nothing } from '../nothing';
@@ -8,5 +11,4 @@ export declare type Fold<Monad extends Maybe<any>> = Monad extends Just<infer Va
8
11
  /**
9
12
  * Returns the value of the provided `monad`.
10
13
  */
11
- export declare function fold<Monad extends Maybe<any>>(monad: Monad): Fold<Monad>;
12
- export default fold;
14
+ export default function fold<Monad extends Maybe<any>>(monad: Monad): Fold<Monad>;
@@ -1 +1,17 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.fold=fold,exports.default=void 0;var _just=require("../just"),_nothing=require("../nothing"),_guards=require("./guards");function fold(a){return(0,_guards.isJust)(a)?a[_just.jid]:a[_nothing.nid]}var _default=fold;exports.default=_default;
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;
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @module Maybe Operators
3
+ */
1
4
  import { Just } from '../just';
2
5
  import type { Maybe } from '../maybe';
3
6
  import { Nothing } from '../nothing';
@@ -1 +1,22 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isJust=isJust,exports.isNothing=isNothing;var _just=require("../just"),_nothing=require("../nothing");function isJust(a){return Object.prototype.hasOwnProperty.call(a,_just.jid)}function isNothing(a){return Object.prototype.hasOwnProperty.call(a,_nothing.nid)}
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;
@@ -1,5 +1,5 @@
1
- export { fmap } from './fmap';
2
- export { bind } from './bind';
3
- export { fold } from './fold';
1
+ export { default as fmap } from './fmap';
2
+ export { default as bind } from './bind';
3
+ export { default as fold } from './fold';
4
4
  export { isJust, isNothing } from './guards';
5
- export { foldMap, FoldMap } from './fold-map';
5
+ export { default as foldMap, FoldMap } from './fold-map';
@@ -1 +1,14 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"fmap",{enumerable:!0,get:function get(){return _fmap.fmap}}),Object.defineProperty(exports,"bind",{enumerable:!0,get:function get(){return _bind.bind}}),Object.defineProperty(exports,"fold",{enumerable:!0,get:function get(){return _fold.fold}}),Object.defineProperty(exports,"isJust",{enumerable:!0,get:function get(){return _guards.isJust}}),Object.defineProperty(exports,"isNothing",{enumerable:!0,get:function get(){return _guards.isNothing}}),Object.defineProperty(exports,"foldMap",{enumerable:!0,get:function get(){return _foldMap.foldMap}}),Object.defineProperty(exports,"FoldMap",{enumerable:!0,get:function get(){return _foldMap.FoldMap}});var _fmap=require("./fmap"),_bind=require("./bind"),_fold=require("./fold"),_guards=require("./guards"),_foldMap=require("./fold-map");
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; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fnts",
3
- "version": "1.1.0",
3
+ "version": "1.3.1",
4
4
  "license": "MIT",
5
5
  "author": "Dmytro Vasylkivskyi",
6
6
  "description": "TypeScript / JavaScript FP utilities",
@@ -12,9 +12,15 @@
12
12
  "typescript",
13
13
  "javascript"
14
14
  ],
15
- "homepage": "https://github.com/drizzer14/fnts",
16
- "repository": "github:drizzer14/fnts",
15
+ "homepage": "https://drizzer14.github.io/fnts",
16
+ "repository": "https://github.com/drizzer14/fnts",
17
17
  "peerDependencies": {
18
18
  "typescript": ">=4.2.2"
19
- }
19
+ },
20
+ "peerDependenciesMeta": {
21
+ "typescript": {
22
+ "optional": true
23
+ }
24
+ },
25
+ "main": "index.js"
20
26
  }
@@ -0,0 +1,2 @@
1
+ export { default as permutation2 } from './permutation-2';
2
+ export { default as permutation3 } from './permutation-3';
@@ -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,7 @@
1
+ /**
2
+ * @module Permutation
3
+ */
4
+ export declare type BinaryFunction = (a: any, b: any) => any;
5
+ export declare type FirstParameter<Function extends (...args: any[]) => any> = Parameters<Function>[0];
6
+ export declare type SecondParameter<Function extends (...args: any[]) => any> = Parameters<Function>[1];
7
+ export default function permutation2<Function extends BinaryFunction>(fn: Function, shouldCurry?: (a: FirstParameter<Function> | SecondParameter<Function>, b: SecondParameter<Function> | undefined) => boolean): (...args: any[]) => any;
@@ -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,7 @@
1
+ /**
2
+ * @module Permutation
3
+ */
4
+ import type { FirstParameter, SecondParameter } from './permutation-2';
5
+ export declare type TernaryFunction = (a: any, b: any, c: any) => any;
6
+ export declare type ThirdParameter<Function extends (...args: any[]) => any> = Parameters<Function>[2];
7
+ export default function permutation3<Function extends TernaryFunction>(fn: Function, shouldCurry?: (a: FirstParameter<Function> | SecondParameter<Function>, b: SecondParameter<Function> | ThirdParameter<Function>, c: ThirdParameter<Function> | undefined) => boolean): (...args: any[]) => any;
@@ -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/pipe.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 `Pipeline` 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 Pipeline<Functions extends Array<(...args: any[]) => any>, L
17
20
  * Applies all of the provided `functions` one-by-one in left-to-right order
18
21
  * starting from the `argument`.
19
22
  */
20
- export declare function pipe<Functions extends Array<(arg: any) => any>>(...functions: Pipeline<Functions>): (arg: Parameters<Functions[0]>[0]) => ReturnType<Last<Functions>>;
21
- export default pipe;
23
+ export default function pipe<Functions extends Array<(arg: any) => any>>(...functions: Pipeline<Functions>): (arg: Parameters<Functions[0]>[0]) => ReturnType<Last<Functions>>;
package/pipe.js CHANGED
@@ -1 +1,25 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.pipe=pipe,exports.default=void 0;function pipe(){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=0;f<d;f+=1)c=b[f],e=c(e);return e}}var _default=pipe;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 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/rethrow.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @module Side Effects
3
+ */
4
+ import type { Effect } from './types/effect';
5
+ /**
6
+ * Rethrows a received error
7
+ * performing an optional side effect.
8
+ */
9
+ export default function rethrow<Error>(effect: Effect<(error: Error) => never>): (error: Error) => never;
package/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/tap.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @module Side Effects
3
+ */
4
+ import type { Map } from './types/map';
5
+ import type { Identity } from './identity';
6
+ import type { Effect } from './types/effect';
7
+ /**
8
+ * Performs a side effect
9
+ * passing the received argument through itself.
10
+ */
11
+ export default function tap<Value>(effect: Effect<Map<Value, any>>): Identity<Value>;
package/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/ternary.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @module Ternary
3
+ */
4
+ import type { Map } from './types/map';
5
+ /**
6
+ * Functional alternative to the ternary operator.
7
+ * Enforces the same return type for both branches,
8
+ * the result is evaluated lazily.
9
+ */
10
+ export default function ternary<Value, Return>(predicate: Map<Value, boolean>, left: Map<Value, Return>, right: Map<Value, Return>): Map<Value, Return>;
package/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/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "es2019",
3
+ "target": "esnext",
4
4
  "module": "esnext",
5
5
  "moduleResolution": "node",
6
6
  "lib": [
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @module Types
3
+ */
4
+
5
+ /**
6
+ * A simple side effect function descriptor.
7
+ */
8
+ export type Effect<Function extends (...args: any[]) => any> =
9
+ (...args: Parameters<Function>) => void
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @module Types
3
+ */
4
+
5
+ /**
6
+ * Gradual defines a tuple type which accepts any amount
7
+ * of entries from the original one.
8
+ *
9
+ * ```typescript
10
+ * Gradual<[1, 2, 3]> === [1] | [1, 2] | [1, 2, 3]
11
+ * ```
12
+ */
13
+ export type Gradual<T extends any[] | readonly any[]> = T extends [...infer R, any]
14
+ ? R['length'] extends 0
15
+ ? T
16
+ : T | Gradual<R>
17
+ : T
@@ -1,3 +1,10 @@
1
+ /**
2
+ * @module Types
3
+ */
4
+
5
+ /**
6
+ * Picks the last entry from the tuple or array.
7
+ */
1
8
  export type Last<T extends any[]> =
2
9
  T extends [...any[], infer L]
3
10
  ? L
package/types/map.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @module Types
3
+ */
4
+
5
+ /**
6
+ * A type of a function which maps the original value type to another one.
7
+ */
8
+ export type Map<From, To> = (value: From) => To
@@ -1,5 +1,12 @@
1
+ /**
2
+ * @module Types
3
+ */
4
+
1
5
  import type { Tuple } from './tuple'
2
6
 
7
+ /**
8
+ * Slices the tuple by `C` amount of entries from the **end**.
9
+ */
3
10
  export type Slice<
4
11
  T extends any[] | readonly any[],
5
12
  C extends number
@@ -1,4 +1,10 @@
1
1
  /**
2
+ * @module Types
3
+ */
4
+
5
+ /**
6
+ * Creates a tuple of specified length.
7
+ *
2
8
  * {@link https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f Gracefully borrowed from here}
3
9
  */
4
10
  export type Tuple<L extends number, T extends any[] | readonly any[] = []> =
@@ -1,5 +0,0 @@
1
- export type Gradual<T extends any[] | readonly any[]> = T extends [...infer R, any]
2
- ? R['length'] extends 0
3
- ? T
4
- : T | Gradual<R>
5
- : T
@@ -1 +0,0 @@
1
- export type Map<From, To> = (value: From) => To
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.permutationOf2=void 0;var permutationOf2=(a,c)=>function(){for(var d=arguments.length,e=Array(d),f=0;f<d;f++)e[f]=arguments[f];var[g,h]=e;return null!==c&&void 0!==c&&c(g,h)||e.length<a.length?b=>a(b,g):a(g,h)};exports.permutationOf2=permutationOf2;var _default=permutationOf2;exports.default=_default;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.permutationOf3=void 0;var permutationOf3=a=>function(){for(var d=arguments.length,e=Array(d),f=0;f<d;f++)e[f]=arguments[f];var[g,h,b]=e;return e.length<a.length?b=>a(b,g,h):a(g,h,b)};exports.permutationOf3=permutationOf3;var _default=permutationOf3;exports.default=_default;
@@ -1,31 +0,0 @@
1
- import { Either, Left, Right } from '../either';
2
- /**
3
- * A type to unwrap the left value type of the provided `Monad`.
4
- * If the `Monad` is `Right`, returns `undefined`.
5
- */
6
- export declare type Bifoldl<Monad extends Either<any, any>> = Monad extends Left<infer LeftValue> ? LeftValue : undefined;
7
- /**
8
- * Returns the left value of the provided `monad`.
9
- * If the `monad` is `Right`, returns `undefined`.
10
- */
11
- export declare const bifoldl: <Monad extends Either<any, any>>(monad: Monad) => Bifoldl<Monad>;
12
- /**
13
- * A type to unwrap the right value type of the provided `Monad`.
14
- * If the `Monad` is `Left`, returns `undefined`.
15
- */
16
- export declare type Bifoldr<Monad extends Either<any, any>> = Monad extends Right<infer RightValue> ? RightValue : undefined;
17
- /**
18
- * Returns the right value of the provided `monad`.
19
- * If the `monad` is `Left`, returns `undefined`.
20
- */
21
- export declare const bifoldr: <Monad extends Either<any, any>>(monad: Monad) => Bifoldr<Monad>;
22
- /**
23
- * A type to unwrap either the left or the right value type
24
- * of the provided `Monad`.
25
- */
26
- export declare type Bifold<Monad extends Either<any, any>> = Monad extends Left<infer LeftValue> ? LeftValue : Monad extends Right<infer RightValue> ? RightValue : never;
27
- /**
28
- * Unwraps either the left or the right value of the provided `monad`.
29
- */
30
- export declare const bifold: <Monad extends Either<any, any>>(monad: Monad) => Bifold<Monad>;
31
- export default bifold;
@@ -1,29 +0,0 @@
1
- import type { Map } from '../../.internal/map';
2
- import { Either } from '../either';
3
- interface First {
4
- <LeftValue, RightValue, NextLeftValue>(mapLeft: Map<LeftValue, NextLeftValue>): (monad: Either<LeftValue, RightValue>) => Either<NextLeftValue, RightValue>;
5
- <LeftValue, RightValue, NextLeftValue>(monad: Either<LeftValue, RightValue>, mapLeft: Map<LeftValue, NextLeftValue>): Either<NextLeftValue, RightValue>;
6
- }
7
- /**
8
- * Maps the left value of the provided `monad` to a new `Either` monad
9
- * with the same right value.
10
- */
11
- export declare const first: First;
12
- interface Second {
13
- <LeftValue, RightValue, NextRightValue>(mapRight: Map<RightValue, NextRightValue>): (monad: Either<LeftValue, RightValue>) => Either<LeftValue, NextRightValue>;
14
- <LeftValue, RightValue, NextRightValue>(monad: Either<LeftValue, RightValue>, mapRight: Map<RightValue, NextRightValue>): Either<LeftValue, NextRightValue>;
15
- }
16
- /**
17
- * Maps the right value of the provided `monad` to a new `Either` monad
18
- * with the same left value.
19
- */
20
- export declare const second: Second;
21
- interface Bimap {
22
- <LeftValue, RightValue, NextLeftValue, NextRightValue>(mapLeft: Map<LeftValue, NextLeftValue>, mapRight: Map<RightValue, NextRightValue>): (monad: Either<LeftValue, RightValue>) => Either<NextLeftValue, NextRightValue>;
23
- <LeftValue, RightValue, NextLeftValue, NextRightValue>(monad: Either<LeftValue, RightValue>, mapLeft: Map<LeftValue, NextLeftValue>, mapRight: Map<RightValue, NextRightValue>): Either<NextLeftValue, NextRightValue>;
24
- }
25
- /**
26
- * Maps left and right values of the provided `monad` to a new `Either` monad.
27
- */
28
- export declare const bimap: Bimap;
29
- export default bimap;