fnts 1.3.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.
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]>;
package/compose.js CHANGED
@@ -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>;
@@ -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 = [];
@@ -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 = [];
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>;
package/guard.js CHANGED
@@ -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;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fnts",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "license": "MIT",
5
5
  "author": "Dmytro Vasylkivskyi",
6
6
  "description": "TypeScript / JavaScript FP utilities",
@@ -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`.
package/pipe.js CHANGED
@@ -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
  };
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';