fnts 1.5.3 → 1.7.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.
package/compose.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * @module Composition
3
3
  */
4
4
  import type { Last } from './types/last';
5
- import type { UnaryFunction } from './types/function';
5
+ import type { UnaryFunction, VariadicFunction } from './types/function';
6
6
  /**
7
7
  * Creates a `Composition` type which parses all of the provided functions' types.
8
8
  * Any function with either an incorrect argument or a return type will not fit
@@ -10,12 +10,11 @@ import type { UnaryFunction } from './types/function';
10
10
  * type matches the return type of the next function and its return type
11
11
  * matches the type of the previous function's argument.
12
12
  */
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>,
13
+ export declare type Composition<Functions extends [...UnaryFunction[], VariadicFunction], 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 : Last extends VariadicFunction ? Penultimate extends UnaryFunction ? [...Rest, (arg: ReturnType<Last>) => ReturnType<Penultimate>] : never : never : never>,
15
15
  Last
16
16
  ] : Functions;
17
17
  /**
18
- * Applies all of the provided `functions` one-by-one in right-to-left order
19
- * starting from the `argument`.
18
+ * Applies all of the provided `functions` one-by-one in right-to-left order.
20
19
  */
21
- export default function compose<Functions extends UnaryFunction[]>(...functions: Composition<Functions>): (arg: Parameters<Last<Functions>>[0]) => ReturnType<Functions[0]>;
20
+ export default function compose<Functions extends [...UnaryFunction[], VariadicFunction]>(...functions: Composition<Functions>): (...args: Parameters<Last<Functions>>) => ReturnType<Functions[0]>;
package/compose.js CHANGED
@@ -4,19 +4,24 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  /**
7
- * Applies all of the provided `functions` one-by-one in right-to-left order
8
- * starting from the `argument`.
7
+ * Applies all of the provided `functions` one-by-one in right-to-left order.
9
8
  */
10
9
  function compose() {
11
10
  var functions = [];
12
11
  for (var _i = 0; _i < arguments.length; _i++) {
13
12
  functions[_i] = arguments[_i];
14
13
  }
15
- return function (arg) {
14
+ return function () {
15
+ var args = [];
16
+ for (var _i = 0; _i < arguments.length; _i++) {
17
+ args[_i] = arguments[_i];
18
+ }
16
19
  var length = functions.length;
17
- var composition = arg;
18
- for (var index = length - 1; index >= 0; index -= 1) {
19
- composition = functions[index](composition);
20
+ var composition = functions[length - 1].apply(functions, args);
21
+ if (length > 1) {
22
+ for (var index = length - 2; index >= 0; index -= 1) {
23
+ composition = functions[index](composition);
24
+ }
20
25
  }
21
26
  return composition;
22
27
  };
@@ -12,10 +12,10 @@ var right_1 = require("./right");
12
12
  */
13
13
  function eitherSync(value) {
14
14
  try {
15
- return right_1.default(value());
15
+ return (0, right_1.default)(value());
16
16
  }
17
17
  catch (error) {
18
- return left_1.default(error);
18
+ return (0, left_1.default)(error);
19
19
  }
20
20
  }
21
21
  exports.default = eitherSync;
package/either/left.js CHANGED
@@ -19,7 +19,7 @@ function left(value) {
19
19
  _a[exports.lid] = value,
20
20
  // @ts-expect-error: Undocumented API for external use
21
21
  _a.toString = function () {
22
- return "Left " + value;
22
+ return "Left ".concat(value);
23
23
  },
24
24
  _a;
25
25
  }
@@ -10,6 +10,6 @@ var bifoldr_1 = require("./bifoldr");
10
10
  */
11
11
  function bifold(monad) {
12
12
  var _a;
13
- return (_a = bifoldl_1.default(monad)) !== null && _a !== void 0 ? _a : bifoldr_1.default(monad);
13
+ return (_a = (0, bifoldl_1.default)(monad)) !== null && _a !== void 0 ? _a : (0, bifoldr_1.default)(monad);
14
14
  }
15
15
  exports.default = bifold;
@@ -10,8 +10,8 @@ var left_1 = require("../../left");
10
10
  * If the `monad` is `Right`, returns `undefined`.
11
11
  */
12
12
  function bifoldl(monad) {
13
- return guards_1.isLeft(monad)
13
+ return ((0, guards_1.isLeft)(monad)
14
14
  ? monad[left_1.lid]
15
- : undefined;
15
+ : undefined);
16
16
  }
17
17
  exports.default = bifoldl;
@@ -10,8 +10,8 @@ var right_1 = require("../../right");
10
10
  * If the `monad` is `Left`, returns `undefined`.
11
11
  */
12
12
  function bifoldr(monad) {
13
- return guards_1.isRight(monad)
13
+ return ((0, guards_1.isRight)(monad)
14
14
  ? monad[right_1.rid]
15
- : undefined;
15
+ : undefined);
16
16
  }
17
17
  exports.default = bifoldr;
@@ -3,13 +3,23 @@
3
3
  */
4
4
  import type { Either } from '../either';
5
5
  import type { Map } from '../../types/map';
6
+ /**
7
+ * Maps provided `monad` to a value,
8
+ * then returns it.
9
+ */
10
+ export default function bifoldMap<LeftValue, RightValue, Value>(map: Map<LeftValue | RightValue, Value>): (monad: Either<LeftValue, RightValue>) => Value;
11
+ /**
12
+ * Maps provided `monad` to a value,
13
+ * then returns it.
14
+ */
15
+ export default function bifoldMap<LeftValue, RightValue, Value>(monad: Either<LeftValue, RightValue>, map: Map<LeftValue | RightValue, Value>): Value;
6
16
  /**
7
17
  * Maps left and right values of the provided `monad` to a value,
8
18
  * then returns it.
9
19
  */
10
- export default function bifoldMap<LeftValue, RightValue, MappedValue>(mapLeft: Map<LeftValue, MappedValue>, mapRight: Map<RightValue, MappedValue>): (monad: Either<LeftValue, RightValue>) => MappedValue;
20
+ export default function bifoldMap<LeftValue, RightValue, Value>(mapLeft: Map<LeftValue, Value>, mapRight: Map<RightValue, Value>): (monad: Either<LeftValue, RightValue>) => Value;
11
21
  /**
12
22
  * Maps left and right values of the provided `monad` to a value,
13
23
  * then returns it.
14
24
  */
15
- export default function bifoldMap<LeftValue, RightValue, MappedValue>(monad: Either<LeftValue, RightValue>, mapLeft: Map<LeftValue, MappedValue>, mapRight: Map<RightValue, MappedValue>): MappedValue;
25
+ export default function bifoldMap<LeftValue, RightValue, Value>(monad: Either<LeftValue, RightValue>, mapLeft: Map<LeftValue, Value>, mapRight: Map<RightValue, Value>): Value;
@@ -13,8 +13,16 @@ function bifoldMap() {
13
13
  for (var _i = 0; _i < arguments.length; _i++) {
14
14
  args[_i] = arguments[_i];
15
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);
16
+ if (args.length === 1) {
17
+ return function (monad) {
18
+ return (0, compose_1.default)(args[0], bifold_1.default)(monad);
19
+ };
20
+ }
21
+ if (args.length === 2 && (0, guards_1.isEither)(args[0])) {
22
+ return (0, compose_1.default)(args[1], bifold_1.default)(args[0]);
23
+ }
24
+ return (0, permutation_3_1.default)(function (monad, mapLeft, mapRight) {
25
+ return (0, ternary_1.default)(guards_1.isLeft, (0, compose_1.default)(mapLeft, bifold_1.bifoldl), (0, compose_1.default)(mapRight, bifold_1.bifoldr))(monad);
18
26
  }).apply(void 0, args);
19
27
  }
20
28
  exports.default = bifoldMap;
@@ -13,8 +13,8 @@ function bimap() {
13
13
  for (var _i = 0; _i < arguments.length; _i++) {
14
14
  args[_i] = arguments[_i];
15
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);
16
+ return (0, permutation_3_1.default)(function (monad, mapLeft, mapRight) {
17
+ return (0, ternary_1.default)(guards_1.isLeft, (0, first_1.default)(mapLeft), (0, second_1.default)(mapRight))(monad);
18
18
  }).apply(void 0, args);
19
19
  }
20
20
  exports.default = bimap;
@@ -15,8 +15,8 @@ function first() {
15
15
  for (var _i = 0; _i < arguments.length; _i++) {
16
16
  args[_i] = arguments[_i];
17
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);
18
+ return (0, permutation_2_1.default)(function (monad, mapLeft) {
19
+ return (0, ternary_1.default)(guards_1.isLeft, (0, compose_1.default)(left_1.default, mapLeft, bifold_1.bifoldl), identity_1.default)(monad);
20
20
  }).apply(void 0, args);
21
21
  }
22
22
  exports.default = first;
@@ -15,8 +15,8 @@ function second() {
15
15
  for (var _i = 0; _i < arguments.length; _i++) {
16
16
  args[_i] = arguments[_i];
17
17
  }
18
- return permutation_2_1.default(function (monad, mapRight) {
19
- return ternary_1.default(guards_1.isRight, compose_1.default(right_1.default, mapRight, bifold_1.bifoldr), identity_1.default)(monad);
18
+ return (0, permutation_2_1.default)(function (monad, mapRight) {
19
+ return (0, ternary_1.default)(guards_1.isRight, (0, compose_1.default)(right_1.default, mapRight, bifold_1.bifoldr), identity_1.default)(monad);
20
20
  }).apply(void 0, args);
21
21
  }
22
22
  exports.default = second;
@@ -14,8 +14,8 @@ function bindr() {
14
14
  for (var _i = 0; _i < arguments.length; _i++) {
15
15
  args[_i] = arguments[_i];
16
16
  }
17
- return permutation_2_1.default(function (monad, mapRight) {
18
- return ternary_1.default(guards_1.isRight, compose_1.default(mapRight, bifold_1.bifoldr), identity_1.default)(monad);
17
+ return (0, permutation_2_1.default)(function (monad, mapRight) {
18
+ return (0, ternary_1.default)(guards_1.isRight, (0, compose_1.default)(mapRight, bifold_1.bifoldr), identity_1.default)(monad);
19
19
  }).apply(void 0, args);
20
20
  }
21
21
  exports.default = bindr;
@@ -12,3 +12,7 @@ export declare function isLeft<LeftValue>(monad: Either<LeftValue, any>): monad
12
12
  * Type guard function to tell if the provided `monad` is `Right`.
13
13
  */
14
14
  export declare function isRight<RightValue>(monad: Either<any, RightValue>): monad is Right<RightValue>;
15
+ /**
16
+ * Type guard function to tell if the provided `value` is `Either`.
17
+ */
18
+ export declare function isEither<LeftValue, RightValue>(value: any): value is Either<LeftValue, RightValue>;
@@ -3,7 +3,7 @@
3
3
  * @module Either Operators
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isRight = exports.isLeft = void 0;
6
+ exports.isEither = exports.isRight = exports.isLeft = void 0;
7
7
  var left_1 = require("../left");
8
8
  var right_1 = require("../right");
9
9
  /**
@@ -20,3 +20,10 @@ function isRight(monad) {
20
20
  return Object.prototype.hasOwnProperty.call(monad, right_1.rid);
21
21
  }
22
22
  exports.isRight = isRight;
23
+ /**
24
+ * Type guard function to tell if the provided `value` is `Either`.
25
+ */
26
+ function isEither(value) {
27
+ return isLeft(value) || isRight(value);
28
+ }
29
+ exports.isEither = isEither;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/either/right.js CHANGED
@@ -19,7 +19,7 @@ function right(value) {
19
19
  _a[exports.rid] = value,
20
20
  // @ts-expect-error: Undocumented API for external use
21
21
  _a.toString = function () {
22
- return "Right " + value;
22
+ return "Right ".concat(value);
23
23
  },
24
24
  _a;
25
25
  }
package/inject.js CHANGED
@@ -9,7 +9,7 @@ function inject() {
9
9
  for (var _i = 0; _i < arguments.length; _i++) {
10
10
  args[_i] = arguments[_i];
11
11
  }
12
- return permutation_2_1.default(function (fn, effect) {
12
+ return (0, permutation_2_1.default)(function (fn, effect) {
13
13
  return (function () {
14
14
  var args = [];
15
15
  for (var _i = 0; _i < arguments.length; _i++) {
package/maybe/just.js CHANGED
@@ -19,7 +19,7 @@ function just(value) {
19
19
  _a[exports.jid] = value,
20
20
  // @ts-expect-error: Undocumented API for external use
21
21
  _a.toString = function () {
22
- return "Just " + value;
22
+ return "Just ".concat(value);
23
23
  },
24
24
  _a;
25
25
  }
package/maybe/maybe.js CHANGED
@@ -11,7 +11,7 @@ var nothing_1 = require("./nothing");
11
11
  */
12
12
  function maybe(value) {
13
13
  return value === null || value === undefined
14
- ? nothing_1.default()
15
- : just_1.default(value);
14
+ ? (0, nothing_1.default)()
15
+ : (0, just_1.default)(value);
16
16
  }
17
17
  exports.default = maybe;
@@ -7,9 +7,9 @@ import type { Map } from '../../types/map';
7
7
  * Binds the value of the `monad` to new monad created
8
8
  * by the `transition` function.
9
9
  */
10
- export default function bind<Value, NextValue>(transition: Map<Value, Maybe<NextValue>>): (monad: Maybe<Value>) => Maybe<NonNullable<NextValue>>;
10
+ export default function bind<Value, NextValue>(map: Map<Value, Maybe<NextValue>>): (monad: Maybe<Value>) => Maybe<NonNullable<NextValue>>;
11
11
  /**
12
12
  * Binds the value of the `monad` to new monad created
13
13
  * by the `transition` function.
14
14
  */
15
- export default function bind<Value, NextValue>(monad: Maybe<Value>, transition: Map<Value, Maybe<NextValue>>): Maybe<NonNullable<NextValue>>;
15
+ export default function bind<Value, NextValue>(monad: Maybe<Value>, map: Map<Value, Maybe<NextValue>>): Maybe<NonNullable<NextValue>>;
@@ -14,8 +14,8 @@ function bind() {
14
14
  for (var _i = 0; _i < arguments.length; _i++) {
15
15
  args[_i] = arguments[_i];
16
16
  }
17
- return permutation_2_1.default(function (monad, transition) {
18
- return ternary_1.default(guards_1.isJust, compose_1.default(transition, fold_1.default), identity_1.default)(monad);
17
+ return (0, permutation_2_1.default)(function (monad, map) {
18
+ return (0, ternary_1.default)(guards_1.isJust, (0, compose_1.default)(map, fold_1.default), identity_1.default)(monad);
19
19
  }).apply(void 0, args);
20
20
  }
21
21
  exports.default = bind;
@@ -7,9 +7,9 @@ import type { Map } from '../../types/map';
7
7
  * Maps the value of the provided `monad` through the `transition` function
8
8
  * and returns a new `Maybe` of the mapped value.
9
9
  */
10
- export default function fmap<Value, NextValue = Value>(transition: Map<Value, NextValue>): (monad: Maybe<Value>) => Maybe<NonNullable<NextValue>>;
10
+ export default function fmap<Value, NextValue = Value>(map: Map<Value, NextValue>): (monad: Maybe<Value>) => Maybe<NonNullable<NextValue>>;
11
11
  /**
12
12
  * Maps the value of the provided `monad` through the `transition` function
13
13
  * and returns a new `Maybe` of the mapped value.
14
14
  */
15
- export default function fmap<Value, NextValue = Value>(monad: Maybe<Value>, transition: Map<Value, NextValue>): Maybe<NonNullable<NextValue>>;
15
+ export default function fmap<Value, NextValue = Value>(monad: Maybe<Value>, map: Map<Value, NextValue>): Maybe<NonNullable<NextValue>>;
@@ -15,8 +15,8 @@ function fmap() {
15
15
  for (var _i = 0; _i < arguments.length; _i++) {
16
16
  args[_i] = arguments[_i];
17
17
  }
18
- return permutation_2_1.default(function (monad, transition) {
19
- return ternary_1.default(guards_1.isJust, compose_1.default(maybe_1.default, transition, fold_1.default), identity_1.default)(monad);
18
+ return (0, permutation_2_1.default)(function (monad, map) {
19
+ return (0, ternary_1.default)(guards_1.isJust, (0, compose_1.default)(maybe_1.default, map, fold_1.default), identity_1.default)(monad);
20
20
  }).apply(void 0, args);
21
21
  }
22
22
  exports.default = fmap;
@@ -13,9 +13,9 @@ export declare type FoldMap<Monad extends Maybe<any>, NextValue> = Monad extends
13
13
  * Maps the value of the provided `monad` through the `transition` function
14
14
  * and returns the mapped value or `null`.
15
15
  */
16
- export default function foldMap<Value, NextValue = Value>(transition: Map<Value, NextValue>): (monad: Maybe<Value>) => FoldMap<Maybe<Value>, NextValue>;
16
+ export default function foldMap<Value, NextValue = Value>(map: Map<Value, NextValue>): (monad: Maybe<Value>) => FoldMap<Maybe<Value>, NextValue>;
17
17
  /**
18
18
  * Maps the value of the provided `monad` through the `transition` function
19
19
  * and returns the mapped value or `null`.
20
20
  */
21
- export default function foldMap<Value, NextValue = Value>(monad: Maybe<Value>, transition: Map<Value, NextValue>): FoldMap<Maybe<Value>, NextValue>;
21
+ export default function foldMap<Value, NextValue = Value>(monad: Maybe<Value>, map: Map<Value, NextValue>): FoldMap<Maybe<Value>, NextValue>;
@@ -13,8 +13,8 @@ function foldMap() {
13
13
  for (var _i = 0; _i < arguments.length; _i++) {
14
14
  args[_i] = arguments[_i];
15
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);
16
+ return (0, permutation_2_1.default)(function (monad, map) {
17
+ return (0, ternary_1.default)(guards_1.isJust, (0, compose_1.default)(map, fold_1.default), function () { return null; })(monad);
18
18
  }).apply(void 0, args);
19
19
  }
20
20
  exports.default = foldMap;
@@ -10,7 +10,7 @@ var guards_1 = require("./guards");
10
10
  * Returns the value of the provided `monad`.
11
11
  */
12
12
  function fold(monad) {
13
- return guards_1.isJust(monad)
13
+ return (0, guards_1.isJust)(monad)
14
14
  ? monad[just_1.jid]
15
15
  : monad[nothing_1.nid];
16
16
  }
@@ -12,3 +12,7 @@ export declare function isJust<Value>(monad: Maybe<Value>): monad is Just<Value>
12
12
  * Type guard function to tell if the provided `monad` is `Nothing`.
13
13
  */
14
14
  export declare function isNothing<Value>(monad: Maybe<Value>): monad is Nothing;
15
+ /**
16
+ * Type guard function to tell if the provided `value` is `Maybe`.
17
+ */
18
+ export declare function isMaybe<Value>(value: any): value is Maybe<Value>;
@@ -3,7 +3,7 @@
3
3
  * @module Maybe Operators
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isNothing = exports.isJust = void 0;
6
+ exports.isMaybe = exports.isNothing = exports.isJust = void 0;
7
7
  var just_1 = require("../just");
8
8
  var nothing_1 = require("../nothing");
9
9
  /**
@@ -20,3 +20,10 @@ function isNothing(monad) {
20
20
  return Object.prototype.hasOwnProperty.call(monad, nothing_1.nid);
21
21
  }
22
22
  exports.isNothing = isNothing;
23
+ /**
24
+ * Type guard function to tell if the provided `value` is `Maybe`.
25
+ */
26
+ function isMaybe(value) {
27
+ return isJust(value) || isNothing(value);
28
+ }
29
+ exports.isMaybe = isMaybe;
@@ -1,5 +1,5 @@
1
+ export * from './guards';
1
2
  export { default as fmap } from './fmap';
2
3
  export { default as bind } from './bind';
3
4
  export { default as fold } from './fold';
4
- export { isJust, isNothing } from './guards';
5
5
  export { default as foldMap, FoldMap } from './fold-map';
@@ -1,14 +1,26 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.foldMap = exports.isNothing = exports.isJust = exports.fold = exports.bind = exports.fmap = void 0;
17
+ exports.foldMap = exports.fold = exports.bind = exports.fmap = void 0;
18
+ __exportStar(require("./guards"), exports);
4
19
  var fmap_1 = require("./fmap");
5
20
  Object.defineProperty(exports, "fmap", { enumerable: true, get: function () { return fmap_1.default; } });
6
21
  var bind_1 = require("./bind");
7
22
  Object.defineProperty(exports, "bind", { enumerable: true, get: function () { return bind_1.default; } });
8
23
  var fold_1 = require("./fold");
9
24
  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
25
  var fold_map_1 = require("./fold-map");
14
26
  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.5.3",
3
+ "version": "1.7.0",
4
4
  "license": "MIT",
5
5
  "author": "Dmytro Vasylkivskyi",
6
6
  "description": "TypeScript / JavaScript FP utilities",
package/pipe.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * @module Composition
3
3
  */
4
4
  import type { Last } from './types/last';
5
- import type { UnaryFunction } from './types/function';
5
+ import type { UnaryFunction, VariadicFunction } from './types/function';
6
6
  /**
7
7
  * Creates a `Pipeline` type which parses all of the provided functions' types.
8
8
  * Any function with either an incorrect argument or a return type will not fit
@@ -10,12 +10,11 @@ import type { UnaryFunction } from './types/function';
10
10
  * type matches the return type of the previous function and its return type
11
11
  * matches the type of the next function's argument.
12
12
  */
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
+ export declare type Pipeline<Functions extends [VariadicFunction, ...UnaryFunction[]], Length extends number = Functions['length']> = Length extends 1 ? Functions : Functions extends [infer First, infer Second, ...infer Rest] ? [
14
14
  First,
15
- ...Pipeline<First extends UnaryFunction ? Second extends UnaryFunction ? Rest extends UnaryFunction[] ? [(arg: ReturnType<First>) => ReturnType<Second>, ...Rest] : never : never : never>
15
+ ...Pipeline<First extends UnaryFunction ? Second extends UnaryFunction ? Rest extends UnaryFunction[] ? [(arg: ReturnType<First>) => ReturnType<Second>, ...Rest] : never : never : First extends VariadicFunction ? Second extends UnaryFunction ? Rest extends UnaryFunction[] ? [(arg: ReturnType<First>) => ReturnType<Second>, ...Rest] : never : never : never>
16
16
  ] : Functions;
17
17
  /**
18
- * Applies all of the provided `functions` one-by-one in left-to-right order
19
- * starting from the `argument`.
18
+ * Applies all of the provided `functions` one-by-one in left-to-right order.
20
19
  */
21
- export default function pipe<Functions extends Array<(arg: any) => any>>(...functions: Pipeline<Functions>): (arg: Parameters<Functions[0]>[0]) => ReturnType<Last<Functions>>;
20
+ export default function pipe<Functions extends [VariadicFunction, ...UnaryFunction[]]>(...functions: Pipeline<Functions>): (...args: Parameters<Functions[0]>) => ReturnType<Last<Functions>>;
package/pipe.js CHANGED
@@ -4,19 +4,24 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  /**
7
- * Applies all of the provided `functions` one-by-one in left-to-right order
8
- * starting from the `argument`.
7
+ * Applies all of the provided `functions` one-by-one in left-to-right order.
9
8
  */
10
9
  function pipe() {
11
10
  var functions = [];
12
11
  for (var _i = 0; _i < arguments.length; _i++) {
13
12
  functions[_i] = arguments[_i];
14
13
  }
15
- return function (arg) {
14
+ return function () {
15
+ var args = [];
16
+ for (var _i = 0; _i < arguments.length; _i++) {
17
+ args[_i] = arguments[_i];
18
+ }
16
19
  var length = functions.length;
17
- var pipeline = arg;
18
- for (var index = 0; index < length; index += 1) {
19
- pipeline = functions[index](pipeline);
20
+ var pipeline = functions[0].apply(functions, args);
21
+ if (length > 1) {
22
+ for (var index = 1; index < length; index += 1) {
23
+ pipeline = functions[index](pipeline);
24
+ }
20
25
  }
21
26
  return pipeline;
22
27
  };
package/rethrow.js CHANGED
@@ -9,7 +9,7 @@ var inject_1 = require("./inject");
9
9
  * performing an optional side effect.
10
10
  */
11
11
  function rethrow(effect) {
12
- return inject_1.default(function (error) {
12
+ return (0, inject_1.default)(function (error) {
13
13
  throw error;
14
14
  }, effect);
15
15
  }
package/tap.js CHANGED
@@ -10,6 +10,6 @@ var identity_1 = require("./identity");
10
10
  * passing the received argument through itself.
11
11
  */
12
12
  function tap(effect) {
13
- return inject_1.default(identity_1.default, effect);
13
+ return (0, inject_1.default)(identity_1.default, effect);
14
14
  }
15
15
  exports.default = tap;