fnts 1.6.0 → 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;
@@ -14,13 +14,15 @@ function bifoldMap() {
14
14
  args[_i] = arguments[_i];
15
15
  }
16
16
  if (args.length === 1) {
17
- return function (monad) { return args[0](monad); };
17
+ return function (monad) {
18
+ return (0, compose_1.default)(args[0], bifold_1.default)(monad);
19
+ };
18
20
  }
19
- if (args.length === 2 && guards_1.isEither(args[0])) {
20
- return compose_1.default(args[1], bifold_1.default)(args[0]);
21
+ if (args.length === 2 && (0, guards_1.isEither)(args[0])) {
22
+ return (0, compose_1.default)(args[1], bifold_1.default)(args[0]);
21
23
  }
22
- return permutation_3_1.default(function (monad, mapLeft, mapRight) {
23
- return ternary_1.default(guards_1.isLeft, compose_1.default(mapLeft, bifold_1.bifoldl), compose_1.default(mapRight, bifold_1.bifoldr))(monad);
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);
24
26
  }).apply(void 0, args);
25
27
  }
26
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;
@@ -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;
@@ -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, map) {
18
- return ternary_1.default(guards_1.isJust, compose_1.default(map, 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;
@@ -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, map) {
19
- return ternary_1.default(guards_1.isJust, compose_1.default(maybe_1.default, map, 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,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, map) {
17
- return ternary_1.default(guards_1.isJust, compose_1.default(map, 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
  }
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fnts",
3
- "version": "1.6.0",
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;