fnts 1.5.1 → 1.6.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.
@@ -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,6 +13,12 @@ function bifoldMap() {
13
13
  for (var _i = 0; _i < arguments.length; _i++) {
14
14
  args[_i] = arguments[_i];
15
15
  }
16
+ if (args.length === 1) {
17
+ return function (monad) { return args[0](monad); };
18
+ }
19
+ if (args.length === 2 && guards_1.isEither(args[0])) {
20
+ return compose_1.default(args[1], bifold_1.default)(args[0]);
21
+ }
16
22
  return permutation_3_1.default(function (monad, mapLeft, mapRight) {
17
23
  return ternary_1.default(guards_1.isLeft, compose_1.default(mapLeft, bifold_1.bifoldl), compose_1.default(mapRight, bifold_1.bifoldr))(monad);
18
24
  }).apply(void 0, args);
@@ -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;
package/maybe/just.d.ts CHANGED
@@ -11,11 +11,11 @@ export declare const jid: unique symbol;
11
11
  * key, holding the provided value type.
12
12
  */
13
13
  export declare type Just<Value> = {
14
- [jid]: Exclude<Value, null | undefined>;
14
+ [jid]: NonNullable<Value>;
15
15
  };
16
16
  /**
17
17
  * Constructor function for `Just`.
18
18
  * Creates the special object with one property, represented as unique symbol
19
19
  * key, holding the provided value.
20
20
  */
21
- export default function just<Value>(value: Value): Just<Value>;
21
+ export default function just<Value extends NonNullable<any>>(value: Value): Just<Value>;
package/maybe/maybe.d.ts CHANGED
@@ -12,4 +12,9 @@ export declare type Maybe<Value> = Just<Value> | Nothing;
12
12
  * Constructor function for `Maybe`.
13
13
  * Creates either `just` of a provided value, or `nothing`.
14
14
  */
15
- export default function maybe<Value>(value: Value | null | undefined): Maybe<Value>;
15
+ export default function maybe(value: null | undefined): Nothing;
16
+ /**
17
+ * Constructor function for `Maybe`.
18
+ * Creates either `just` of a provided value, or `nothing`.
19
+ */
20
+ export default function maybe<Value>(value: Value | null | undefined): Just<Value>;
@@ -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<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<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 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);
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<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<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 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);
20
20
  }).apply(void 0, args);
21
21
  }
22
22
  exports.default = fmap;
@@ -8,14 +8,14 @@ import type { Map } from '../../types/map';
8
8
  /**
9
9
  * A type to unwrap the provided `Monad` into the new value type.
10
10
  */
11
- export declare type FoldMap<Monad extends Maybe<any>, NextValue> = Monad extends Just<any> ? NextValue : Monad extends Nothing ? null : never;
11
+ export declare type FoldMap<Monad extends Maybe<any>, NextValue> = Monad extends Just<any> ? NonNullable<NextValue> : Monad extends Nothing ? null : never;
12
12
  /**
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>) => NextValue | null;
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>): NextValue | null;
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 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);
18
18
  }).apply(void 0, args);
19
19
  }
20
20
  exports.default = foldMap;
@@ -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,22 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
2
12
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.foldMap = exports.isNothing = exports.isJust = exports.fold = exports.bind = exports.fmap = void 0;
13
+ exports.foldMap = exports.fold = exports.bind = exports.fmap = void 0;
14
+ __exportStar(require("./guards"), exports);
4
15
  var fmap_1 = require("./fmap");
5
16
  Object.defineProperty(exports, "fmap", { enumerable: true, get: function () { return fmap_1.default; } });
6
17
  var bind_1 = require("./bind");
7
18
  Object.defineProperty(exports, "bind", { enumerable: true, get: function () { return bind_1.default; } });
8
19
  var fold_1 = require("./fold");
9
20
  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
21
  var fold_map_1 = require("./fold-map");
14
22
  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.1",
3
+ "version": "1.6.0",
4
4
  "license": "MIT",
5
5
  "author": "Dmytro Vasylkivskyi",
6
6
  "description": "TypeScript / JavaScript FP utilities",