fnts 1.3.0 → 1.4.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 (90) hide show
  1. package/compose.d.ts +5 -7
  2. package/{cjs/compose.js → compose.js} +1 -2
  3. package/curry.d.ts +3 -2
  4. package/{cjs/curry.js → curry.js} +0 -0
  5. package/{cjs/either → either}/either-sync.js +0 -0
  6. package/{cjs/either → either}/either.js +0 -0
  7. package/{cjs/either → either}/index.js +0 -0
  8. package/{cjs/either → either}/left.js +4 -0
  9. package/{cjs/either → either}/operators/bifold/bifold.js +0 -0
  10. package/{cjs/either → either}/operators/bifold/bifoldl.js +0 -0
  11. package/{cjs/either → either}/operators/bifold/bifoldr.js +0 -0
  12. package/{cjs/either → either}/operators/bifold/index.js +0 -0
  13. package/{cjs/either → either}/operators/bifold-map.js +0 -0
  14. package/{cjs/either → either}/operators/bimap/bimap.js +0 -0
  15. package/{cjs/either → either}/operators/bimap/first.js +1 -1
  16. package/{cjs/either → either}/operators/bimap/index.js +0 -0
  17. package/{cjs/either → either}/operators/bimap/second.js +1 -1
  18. package/{cjs/either → either}/operators/guards.js +0 -0
  19. package/{cjs/either → either}/operators/index.js +0 -0
  20. package/{cjs/either → either}/right.js +4 -0
  21. package/guard.d.ts +3 -2
  22. package/{cjs/guard.js → guard.js} +1 -2
  23. package/{cjs/identity.js → identity.js} +0 -0
  24. package/{cjs/index.js → index.js} +0 -0
  25. package/inject.d.ts +3 -2
  26. package/{cjs/inject.js → inject.js} +0 -0
  27. package/{cjs/maybe → maybe}/index.js +0 -0
  28. package/{cjs/maybe → maybe}/just.js +4 -0
  29. package/{cjs/maybe → maybe}/maybe.js +0 -0
  30. package/{cjs/maybe → maybe}/nothing.js +4 -0
  31. package/{cjs/maybe → maybe}/operators/bind.js +0 -0
  32. package/{cjs/maybe → maybe}/operators/fmap.js +0 -0
  33. package/maybe/operators/fold-map.d.ts +0 -20
  34. package/{cjs/maybe → maybe}/operators/fold-map.js +0 -0
  35. package/{cjs/maybe → maybe}/operators/fold.js +0 -0
  36. package/{cjs/maybe → maybe}/operators/guards.js +0 -0
  37. package/{cjs/maybe → maybe}/operators/index.js +0 -0
  38. package/package.json +2 -3
  39. package/{cjs/permutation → permutation}/index.js +0 -0
  40. package/permutation/permutation-2.d.ts +4 -3
  41. package/{cjs/permutation → permutation}/permutation-2.js +0 -0
  42. package/permutation/permutation-3.d.ts +3 -2
  43. package/{cjs/permutation → permutation}/permutation-3.js +0 -0
  44. package/pipe.d.ts +4 -6
  45. package/{cjs/pipe.js → pipe.js} +1 -2
  46. package/{cjs/rethrow.js → rethrow.js} +0 -0
  47. package/{cjs/tap.js → tap.js} +0 -0
  48. package/{cjs/ternary.js → ternary.js} +0 -0
  49. package/types/effect.d.ts +3 -1
  50. package/types/function.d.ts +13 -0
  51. package/types/index.d.ts +7 -0
  52. package/esm/compose.js +0 -18
  53. package/esm/curry.js +0 -23
  54. package/esm/either/either-sync.js +0 -18
  55. package/esm/either/either.js +0 -15
  56. package/esm/either/index.js +0 -4
  57. package/esm/either/left.js +0 -17
  58. package/esm/either/operators/bifold/bifold.js +0 -12
  59. package/esm/either/operators/bifold/bifoldl.js +0 -14
  60. package/esm/either/operators/bifold/bifoldr.js +0 -14
  61. package/esm/either/operators/bifold/index.js +0 -3
  62. package/esm/either/operators/bifold-map.js +0 -13
  63. package/esm/either/operators/bimap/bimap.js +0 -13
  64. package/esm/either/operators/bimap/first.js +0 -15
  65. package/esm/either/operators/bimap/index.js +0 -3
  66. package/esm/either/operators/bimap/second.js +0 -15
  67. package/esm/either/operators/guards.js +0 -17
  68. package/esm/either/operators/index.js +0 -4
  69. package/esm/either/right.js +0 -17
  70. package/esm/guard.js +0 -26
  71. package/esm/identity.js +0 -9
  72. package/esm/index.js +0 -9
  73. package/esm/inject.js +0 -12
  74. package/esm/maybe/index.js +0 -3
  75. package/esm/maybe/just.js +0 -17
  76. package/esm/maybe/maybe.js +0 -14
  77. package/esm/maybe/nothing.js +0 -17
  78. package/esm/maybe/operators/bind.js +0 -14
  79. package/esm/maybe/operators/fmap.js +0 -15
  80. package/esm/maybe/operators/fold-map.js +0 -13
  81. package/esm/maybe/operators/fold.js +0 -14
  82. package/esm/maybe/operators/guards.js +0 -17
  83. package/esm/maybe/operators/index.js +0 -5
  84. package/esm/permutation/index.js +0 -2
  85. package/esm/permutation/permutation-2.js +0 -11
  86. package/esm/permutation/permutation-3.js +0 -11
  87. package/esm/pipe.js +0 -18
  88. package/esm/rethrow.js +0 -13
  89. package/esm/tap.js +0 -12
  90. package/esm/ternary.js +0 -13
package/compose.d.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  * @module Composition
3
3
  */
4
4
  import type { Last } from './types/last';
5
+ import type { UnaryFunction } from './types/function';
5
6
  /**
6
7
  * Creates a `Composition` type which parses all of the provided functions' types.
7
8
  * Any function with either an incorrect argument or a return type will not fit
@@ -9,15 +10,12 @@ import type { Last } from './types/last';
9
10
  * type matches the return type of the next function and its return type
10
11
  * matches the type of the previous function's argument.
11
12
  */
12
- 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] ? [
13
- ...Composition<[
14
- ...Rest,
15
- (arg: ReturnType<Last>) => ReturnType<Penultimate>
16
- ]>,
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>,
17
15
  Last
18
- ] : any;
16
+ ] : Functions;
19
17
  /**
20
18
  * Applies all of the provided `functions` one-by-one in right-to-left order
21
19
  * starting from the `argument`.
22
20
  */
23
- export default function compose<Functions extends Array<(arg: any) => any>>(...functions: Composition<Functions>): (arg: Parameters<Last<Functions>>[0]) => ReturnType<Functions[0]>;
21
+ export default function compose<Functions extends UnaryFunction[]>(...functions: Composition<Functions>): (arg: Parameters<Last<Functions>>[0]) => ReturnType<Functions[0]>;
@@ -16,8 +16,7 @@ function compose() {
16
16
  var length = functions.length;
17
17
  var composition = arg;
18
18
  for (var index = length - 1; index >= 0; index -= 1) {
19
- var current = functions[index];
20
- composition = current(composition);
19
+ composition = functions[index](composition);
21
20
  }
22
21
  return composition;
23
22
  };
package/curry.d.ts CHANGED
@@ -3,10 +3,11 @@
3
3
  */
4
4
  import type { Slice } from './types/slice';
5
5
  import type { Gradual } from './types/gradual';
6
+ import type { VariadicFunction } from './types/function';
6
7
  /**
7
8
  * Creates a type for an auto-curried function.
8
9
  */
9
- 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>>;
10
11
  /**
11
12
  * Creates an auto-curried function from the one provided.
12
13
  * Until the curried function receives an expected number of arguments,
@@ -15,4 +16,4 @@ export declare type Currying<Function extends (...args: any[]) => any, Length ex
15
16
  * of arguments.
16
17
  * Any excess arguments will not be applied.
17
18
  */
18
- export default function curry<Function extends (...args: any[]) => any, Length extends number = Parameters<Function>['length']>(fn: Function, length?: Length): Currying<Function, Length>;
19
+ export default function curry<Function extends VariadicFunction, Length extends number = Parameters<Function>['length']>(fn: Function, length?: Length): Currying<Function, Length>;
File without changes
File without changes
File without changes
File without changes
@@ -17,6 +17,10 @@ function left(value) {
17
17
  var _a;
18
18
  return _a = {},
19
19
  _a[exports.lid] = value,
20
+ // @ts-expect-error: Undocumented API for external use
21
+ _a.toString = function () {
22
+ return "Left " + value;
23
+ },
20
24
  _a;
21
25
  }
22
26
  exports.default = left;
File without changes
File without changes
File without changes
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var guards_1 = require("../guards");
7
7
  var bifold_1 = require("../bifold");
8
8
  var compose_1 = require("../../../compose");
9
+ var ternary_1 = require("../../../ternary");
9
10
  var left_1 = require("../../left");
10
11
  var identity_1 = require("../../../identity");
11
- var ternary_1 = require("../../../ternary");
12
12
  var permutation_2_1 = require("../../../permutation/permutation-2");
13
13
  function first() {
14
14
  var args = [];
File without changes
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var bifold_1 = require("../bifold");
7
7
  var guards_1 = require("../guards");
8
8
  var compose_1 = require("../../../compose");
9
+ var ternary_1 = require("../../../ternary");
9
10
  var identity_1 = require("../../../identity");
10
11
  var right_1 = require("../../right");
11
- var ternary_1 = require("../../../ternary");
12
12
  var permutation_2_1 = require("../../../permutation/permutation-2");
13
13
  function second() {
14
14
  var args = [];
File without changes
File without changes
@@ -17,6 +17,10 @@ function right(value) {
17
17
  var _a;
18
18
  return _a = {},
19
19
  _a[exports.rid] = value,
20
+ // @ts-expect-error: Undocumented API for external use
21
+ _a.toString = function () {
22
+ return "Right " + value;
23
+ },
20
24
  _a;
21
25
  }
22
26
  exports.default = right;
package/guard.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @module Guard
3
3
  */
4
- export declare type GuardQualifier<Function extends (...args: any[]) => any> = [
4
+ import type { VariadicFunction } from './types/function';
5
+ export declare type GuardQualifier<Function extends VariadicFunction> = [
5
6
  validator: <Result extends boolean>(...args: Parameters<Function>) => Result,
6
7
  executor: Function
7
8
  ];
@@ -15,4 +16,4 @@ export declare type GuardQualifier<Function extends (...args: any[]) => any> = [
15
16
  *
16
17
  * When no `validator` succeeds, the default executor is run.
17
18
  */
18
- export default function guard<Function extends (...args: any[]) => any>(...qualifiers: [...GuardQualifier<Function>[], Function]): (...args: Parameters<Function>) => ReturnType<Function>;
19
+ export default function guard<Function extends VariadicFunction>(...qualifiers: [...GuardQualifier<Function>[], Function]): (...args: Parameters<Function>) => ReturnType<Function>;
@@ -24,14 +24,13 @@ function guard() {
24
24
  args[_i] = arguments[_i];
25
25
  }
26
26
  var length = qualifiers.length - 1;
27
- var defaultExpression = qualifiers[length];
28
27
  for (var index = 0; index < length; index += 1) {
29
28
  var _a = qualifiers[index], validator = _a[0], expression = _a[1];
30
29
  if (validator.apply(void 0, args)) {
31
30
  return expression.apply(void 0, args);
32
31
  }
33
32
  }
34
- return defaultExpression.apply(void 0, args);
33
+ return qualifiers[length].apply(qualifiers, args);
35
34
  };
36
35
  }
37
36
  exports.default = guard;
File without changes
File without changes
package/inject.d.ts CHANGED
@@ -2,13 +2,14 @@
2
2
  * @module Side Effects
3
3
  */
4
4
  import type { Effect } from './types/effect';
5
+ import type { VariadicFunction } from './types/function';
5
6
  /**
6
7
  * Injects a function with a side effect.
7
8
  * Returns the copy of the original function.
8
9
  */
9
- export default function inject<Function extends (...args: any[]) => any>(effect: Effect<Function>): (fn: Function) => Function;
10
+ export default function inject<Function extends VariadicFunction>(effect: Effect<Function>): (fn: Function) => Function;
10
11
  /**
11
12
  * Injects a function with a side effect.
12
13
  * Returns the copy of the original function.
13
14
  */
14
- export default function inject<Function extends (...args: any[]) => any>(fn: Function, effect: Effect<Function>): Function;
15
+ export default function inject<Function extends VariadicFunction>(fn: Function, effect: Effect<Function>): Function;
File without changes
File without changes
@@ -17,6 +17,10 @@ function just(value) {
17
17
  var _a;
18
18
  return _a = {},
19
19
  _a[exports.jid] = value,
20
+ // @ts-expect-error: Undocumented API for external use
21
+ _a.toString = function () {
22
+ return "Just " + value;
23
+ },
20
24
  _a;
21
25
  }
22
26
  exports.default = just;
File without changes
@@ -17,6 +17,10 @@ function nothing() {
17
17
  var _a;
18
18
  return _a = {},
19
19
  _a[exports.nid] = null,
20
+ // @ts-expect-error: Undocumented API for external use
21
+ _a.toString = function () {
22
+ return 'Nothing';
23
+ },
20
24
  _a;
21
25
  }
22
26
  exports.default = nothing;
File without changes
File without changes
@@ -9,31 +9,11 @@ import type { Map } from '../../types/map';
9
9
  * A type to unwrap the provided `Monad` into the new value type.
10
10
  */
11
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
12
  /**
23
13
  * Maps the value of the provided `monad` through the `transition` function
24
14
  * and returns the mapped value or `null`.
25
15
  */
26
16
  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;
37
17
  /**
38
18
  * Maps the value of the provided `monad` through the `transition` function
39
19
  * and returns the mapped value or `null`.
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fnts",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "license": "MIT",
5
5
  "author": "Dmytro Vasylkivskyi",
6
6
  "description": "TypeScript / JavaScript FP utilities",
@@ -22,6 +22,5 @@
22
22
  "optional": true
23
23
  }
24
24
  },
25
- "main": "cjs/index.js",
26
- "module": "esm/index.js"
25
+ "main": "index.js"
27
26
  }
File without changes
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @module Permutation
3
3
  */
4
+ import type { VariadicFunction } from './../types/function';
4
5
  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;
6
+ export declare type FirstParameter<Function extends VariadicFunction> = Parameters<Function>[0];
7
+ export declare type SecondParameter<Function extends VariadicFunction> = Parameters<Function>[1];
8
+ export default function permutation2<Function extends BinaryFunction>(fn: Function, shouldCurry?: (a: FirstParameter<Function> | SecondParameter<Function>, b: SecondParameter<Function> | undefined) => boolean): VariadicFunction;
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @module Permutation
3
3
  */
4
+ import type { VariadicFunction } from './../types/function';
4
5
  import type { FirstParameter, SecondParameter } from './permutation-2';
5
6
  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;
7
+ export declare type ThirdParameter<Function extends VariadicFunction> = Parameters<Function>[2];
8
+ 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): VariadicFunction;
package/pipe.d.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  * @module Composition
3
3
  */
4
4
  import type { Last } from './types/last';
5
+ import type { UnaryFunction } from './types/function';
5
6
  /**
6
7
  * Creates a `Pipeline` type which parses all of the provided functions' types.
7
8
  * Any function with either an incorrect argument or a return type will not fit
@@ -9,13 +10,10 @@ import type { Last } from './types/last';
9
10
  * type matches the return type of the previous function and its return type
10
11
  * matches the type of the next function's argument.
11
12
  */
12
- export declare type Pipeline<Functions extends Array<(...args: any[]) => any>, Length extends number = Functions['length']> = Length extends 1 ? Functions : Functions extends [infer First, infer Second, ...infer Rest] ? [
13
+ export declare type Pipeline<Functions extends UnaryFunction[], Length extends number = Functions['length']> = Length extends 1 ? Functions : Functions extends [infer First, infer Second, ...infer Rest] ? [
13
14
  First,
14
- ...Pipeline<[
15
- (arg: ReturnType<First>) => ReturnType<Second>,
16
- ...Rest
17
- ]>
18
- ] : any;
15
+ ...Pipeline<First extends UnaryFunction ? Second extends UnaryFunction ? Rest extends UnaryFunction[] ? [(arg: ReturnType<First>) => ReturnType<Second>, ...Rest] : never : never : never>
16
+ ] : Functions;
19
17
  /**
20
18
  * Applies all of the provided `functions` one-by-one in left-to-right order
21
19
  * starting from the `argument`.
@@ -16,8 +16,7 @@ function pipe() {
16
16
  var length = functions.length;
17
17
  var pipeline = arg;
18
18
  for (var index = 0; index < length; index += 1) {
19
- var current = functions[index];
20
- pipeline = current(pipeline);
19
+ pipeline = functions[index](pipeline);
21
20
  }
22
21
  return pipeline;
23
22
  };
File without changes
File without changes
File without changes
package/types/effect.d.ts CHANGED
@@ -2,8 +2,10 @@
2
2
  * @module Types
3
3
  */
4
4
 
5
+ import type { VariadicFunction } from './function';
6
+
5
7
  /**
6
8
  * A simple side effect function descriptor.
7
9
  */
8
- export type Effect<Function extends (...args: any[]) => any> =
10
+ export type Effect<Function extends VariadicFunction> =
9
11
  (...args: Parameters<Function>) => void
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @module Types
3
+ */
4
+
5
+ /**
6
+ * A type of a function accepting exactly one argument
7
+ */
8
+ export type UnaryFunction = (arg: any) => any
9
+
10
+ /**
11
+ * A type of a function accepting an arbitrary amount of arguments
12
+ */
13
+ export type VariadicFunction = (...args: any[]) => any
@@ -0,0 +1,7 @@
1
+ export type { Map } from './map';
2
+ export type { Last } from './last';
3
+ export type { Slice } from './slice';
4
+ export type { Tuple } from './tuple';
5
+ export type { Effect } from './effect';
6
+ export type { Gradual } from './gradual';
7
+ export type { UnaryFunction, VariadicFunction } from './function';
package/esm/compose.js DELETED
@@ -1,18 +0,0 @@
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 DELETED
@@ -1,23 +0,0 @@
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
- }
@@ -1,18 +0,0 @@
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
- }
@@ -1,15 +0,0 @@
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
- }
@@ -1,4 +0,0 @@
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';
@@ -1,17 +0,0 @@
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
- }
@@ -1,12 +0,0 @@
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
- }
@@ -1,14 +0,0 @@
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
- }
@@ -1,14 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- export { default } from './bifold';
2
- export { default as bifoldl } from './bifoldl';
3
- export { default as bifoldr } from './bifoldr';
@@ -1,13 +0,0 @@
1
- /**
2
- * @module Either Operators
3
- */
4
- import compose from '../../compose';
5
- import ternary from '../../ternary';
6
- import permutation3 from '../../permutation/permutation-3';
7
- import { isLeft } from './guards';
8
- import { bifoldl, bifoldr } from './bifold';
9
- export default function bifoldMap(...args) {
10
- return permutation3((monad, mapLeft, mapRight) => {
11
- return ternary(isLeft, compose(mapLeft, bifoldl), compose(mapRight, bifoldr))(monad);
12
- })(...args);
13
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * @module Either Operators
3
- */
4
- import { isLeft } from '../guards';
5
- import ternary from '../../../ternary';
6
- import permutation3 from '../../../permutation/permutation-3';
7
- import first from './first';
8
- import second from './second';
9
- export default function bimap(...args) {
10
- return permutation3((monad, mapLeft, mapRight) => {
11
- return ternary(isLeft, first(mapLeft), second(mapRight))(monad);
12
- })(...args);
13
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * @module Either Operators
3
- */
4
- import { isLeft } from '../guards';
5
- import { bifoldl } from '../bifold';
6
- import compose from '../../../compose';
7
- import left from '../../left';
8
- import identity from '../../../identity';
9
- import ternary from '../../../ternary';
10
- import permutation2 from '../../../permutation/permutation-2';
11
- export default function first(...args) {
12
- return permutation2((monad, mapLeft) => {
13
- return ternary(isLeft, compose(left, mapLeft, bifoldl), identity)(monad);
14
- })(...args);
15
- }
@@ -1,3 +0,0 @@
1
- export { default } from './bimap';
2
- export { default as first } from './first';
3
- export { default as second } from './second';
@@ -1,15 +0,0 @@
1
- /**
2
- * @module Either Operators
3
- */
4
- import { bifoldr } from '../bifold';
5
- import { isRight } from '../guards';
6
- import compose from '../../../compose';
7
- import identity from '../../../identity';
8
- import right from '../../right';
9
- import ternary from '../../../ternary';
10
- import permutation2 from '../../../permutation/permutation-2';
11
- export default function second(...args) {
12
- return permutation2((monad, mapRight) => {
13
- return ternary(isRight, compose(right, mapRight, bifoldr), identity)(monad);
14
- })(...args);
15
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * @module Either Operators
3
- */
4
- import { lid } from '../left';
5
- import { rid } from '../right';
6
- /**
7
- * Type guard function to tell if the provided `monad` is `Left`.
8
- */
9
- export function isLeft(monad) {
10
- return Object.prototype.hasOwnProperty.call(monad, lid);
11
- }
12
- /**
13
- * Type guard function to tell if the provided `monad` is `Right`.
14
- */
15
- export function isRight(monad) {
16
- return Object.prototype.hasOwnProperty.call(monad, rid);
17
- }
@@ -1,4 +0,0 @@
1
- export { bifoldl, bifoldr, default as bifold, } from './bifold';
2
- export * from './guards';
3
- export { default as bifoldMap } from './bifold-map';
4
- export { default as bimap, first, second } from './bimap';
@@ -1,17 +0,0 @@
1
- /**
2
- * @module Either
3
- */
4
- /**
5
- * Internal unique identifier for `Right`.
6
- */
7
- export const rid = Symbol.for('@@functional/right');
8
- /**
9
- * Constructor function for `Right`.
10
- * Creates the special object with one property, represented as unique symbol
11
- * key, holding the provided value.
12
- */
13
- export default function right(value) {
14
- return {
15
- [rid]: value
16
- };
17
- }
package/esm/guard.js DELETED
@@ -1,26 +0,0 @@
1
- /**
2
- * @module Guard
3
- */
4
- /**
5
- * A function which accepts the pairs of guards:
6
- * the first one is the `validator`, expected to return a boolean value.
7
- *
8
- * If the value is `true`, it's `executor` should run with the provided `args`
9
- * and return from the `guards` function.
10
- * If the value is `false`, the process continues to the next `validator`.
11
- *
12
- * When no `validator` succeeds, the default executor is run.
13
- */
14
- export default function guard(...qualifiers) {
15
- return (...args) => {
16
- const length = qualifiers.length - 1;
17
- const defaultExpression = qualifiers[length];
18
- for (let index = 0; index < length; index += 1) {
19
- const [validator, expression] = qualifiers[index];
20
- if (validator(...args)) {
21
- return expression(...args);
22
- }
23
- }
24
- return defaultExpression(...args);
25
- };
26
- }
package/esm/identity.js DELETED
@@ -1,9 +0,0 @@
1
- /**
2
- * @module Identity
3
- */
4
- /**
5
- * A function which returns the provided value.
6
- */
7
- export default function identity(x) {
8
- return x;
9
- }
package/esm/index.js DELETED
@@ -1,9 +0,0 @@
1
- export { default as tap } from './tap';
2
- export { default as pipe } from './pipe';
3
- export { default as curry } from './curry';
4
- export { default as match } from './guard';
5
- export { default as inject } from './inject';
6
- export { default as compose } from './compose';
7
- export { default as rethrow } from './rethrow';
8
- export { default as ternary } from './ternary';
9
- export { default as identity } from './identity';
package/esm/inject.js DELETED
@@ -1,12 +0,0 @@
1
- /**
2
- * @module Side Effects
3
- */
4
- import permutation2 from './permutation/permutation-2';
5
- export default function inject(...args) {
6
- return permutation2((fn, effect) => {
7
- return ((...args) => {
8
- effect(...args);
9
- return fn(...args);
10
- });
11
- })(...args);
12
- }
@@ -1,3 +0,0 @@
1
- export { default } from './maybe';
2
- export { default as just } from './just';
3
- export { default as nothing } from './nothing';
package/esm/maybe/just.js DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * @module Maybe
3
- */
4
- /**
5
- * Internal unique identifier for `Just`.
6
- */
7
- export const jid = Symbol.for('@@functional/just');
8
- /**
9
- * Constructor function for `Just`.
10
- * Creates the special object with one property, represented as unique symbol
11
- * key, holding the provided value.
12
- */
13
- export default function just(value) {
14
- return {
15
- [jid]: value
16
- };
17
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * @module Maybe
3
- */
4
- import just from './just';
5
- import nothing from './nothing';
6
- /**
7
- * Constructor function for `Maybe`.
8
- * Creates either `just` of a provided value, or `nothing`.
9
- */
10
- export default function maybe(value) {
11
- return value === null || value === undefined
12
- ? nothing()
13
- : just(value);
14
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * @module Maybe
3
- */
4
- /**
5
- * Internal unique identifier for `Nothing`.
6
- */
7
- export const nid = Symbol.for('@@functional/nothing');
8
- /**
9
- * Constructor function for `Nothing`.
10
- * Creates the special object with one property, represented as unique symbol
11
- * key, holding the `null` value.
12
- */
13
- export default function nothing() {
14
- return {
15
- [nid]: null
16
- };
17
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * @module Maybe Operators
3
- */
4
- import compose from '../../compose';
5
- import ternary from '../../ternary';
6
- import identity from '../../identity';
7
- import permutation2 from '../../permutation/permutation-2';
8
- import fold from './fold';
9
- import { isJust } from './guards';
10
- export default function bind(...args) {
11
- return permutation2((monad, transition) => {
12
- return ternary(isJust, compose(transition, fold), identity)(monad);
13
- })(...args);
14
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * @module Maybe Operators
3
- */
4
- import compose from '../../compose';
5
- import identity from '../../identity';
6
- import maybe from '../maybe';
7
- import permutation2 from '../../permutation/permutation-2';
8
- import fold from './fold';
9
- import { isJust } from './guards';
10
- import ternary from '../../ternary';
11
- export default function fmap(...args) {
12
- return permutation2((monad, transition) => {
13
- return ternary(isJust, compose(maybe, transition, fold), identity)(monad);
14
- })(...args);
15
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * @module Maybe Operators
3
- */
4
- import compose from '../../compose';
5
- import ternary from '../../ternary';
6
- import permutation2 from '../../permutation/permutation-2';
7
- import fold from './fold';
8
- import { isJust } from './guards';
9
- export default function foldMap(...args) {
10
- return permutation2((monad, transition) => {
11
- return ternary(isJust, compose(transition, fold), () => null)(monad);
12
- })(...args);
13
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * @module Maybe Operators
3
- */
4
- import { jid } from '../just';
5
- import { nid } from '../nothing';
6
- import { isJust } from './guards';
7
- /**
8
- * Returns the value of the provided `monad`.
9
- */
10
- export default function fold(monad) {
11
- return isJust(monad)
12
- ? monad[jid]
13
- : monad[nid];
14
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * @module Maybe Operators
3
- */
4
- import { jid } from '../just';
5
- import { nid } from '../nothing';
6
- /**
7
- * Type guard function to tell if the provided `monad` is `Just`.
8
- */
9
- export function isJust(monad) {
10
- return Object.prototype.hasOwnProperty.call(monad, jid);
11
- }
12
- /**
13
- * Type guard function to tell if the provided `monad` is `Nothing`.
14
- */
15
- export function isNothing(monad) {
16
- return Object.prototype.hasOwnProperty.call(monad, nid);
17
- }
@@ -1,5 +0,0 @@
1
- export { default as fmap } from './fmap';
2
- export { default as bind } from './bind';
3
- export { default as fold } from './fold';
4
- export { isJust, isNothing } from './guards';
5
- export { default as foldMap } from './fold-map';
@@ -1,2 +0,0 @@
1
- export { default as permutation2 } from './permutation-2';
2
- export { default as permutation3 } from './permutation-3';
@@ -1,11 +0,0 @@
1
- /**
2
- * @module Permutation
3
- */
4
- export default function permutation2(fn, shouldCurry) {
5
- return (...args) => {
6
- const [a1, b] = args;
7
- return (shouldCurry === null || shouldCurry === void 0 ? void 0 : shouldCurry(a1, b)) || args.length < fn.length
8
- ? (a2) => fn(a2, a1)
9
- : fn(a1, b);
10
- };
11
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * @module Permutation
3
- */
4
- export default function permutation3(fn, shouldCurry) {
5
- return (...args) => {
6
- const [a1, b, c] = args;
7
- return (shouldCurry === null || shouldCurry === void 0 ? void 0 : shouldCurry(a1, b, c)) || args.length < fn.length
8
- ? (a2) => fn(a2, a1, b)
9
- : fn(a1, b, c);
10
- };
11
- }
package/esm/pipe.js DELETED
@@ -1,18 +0,0 @@
1
- /**
2
- * @module Composition
3
- */
4
- /**
5
- * Applies all of the provided `functions` one-by-one in left-to-right order
6
- * starting from the `argument`.
7
- */
8
- export default function pipe(...functions) {
9
- return (arg) => {
10
- const length = functions.length;
11
- let pipeline = arg;
12
- for (let index = 0; index < length; index += 1) {
13
- const current = functions[index];
14
- pipeline = current(pipeline);
15
- }
16
- return pipeline;
17
- };
18
- }
package/esm/rethrow.js DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * @module Side Effects
3
- */
4
- import inject from './inject';
5
- /**
6
- * Rethrows a received error
7
- * performing an optional side effect.
8
- */
9
- export default function rethrow(effect) {
10
- return inject((error) => {
11
- throw error;
12
- }, effect);
13
- }
package/esm/tap.js DELETED
@@ -1,12 +0,0 @@
1
- /**
2
- * @module Side Effects
3
- */
4
- import inject from './inject';
5
- import identity from './identity';
6
- /**
7
- * Performs a side effect
8
- * passing the received argument through itself.
9
- */
10
- export default function tap(effect) {
11
- return inject(identity, effect);
12
- }
package/esm/ternary.js DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * @module Ternary
3
- */
4
- /**
5
- * Functional alternative to the ternary operator.
6
- * Enforces the same return type for both branches,
7
- * the result is evaluated lazily.
8
- */
9
- export default function ternary(predicate, left, right) {
10
- return (value) => {
11
- return predicate(value) ? left(value) : right(value);
12
- };
13
- }