fnts 1.2.0 → 1.3.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/README.md +4 -50
- package/cjs/compose.js +25 -0
- package/cjs/curry.js +37 -0
- package/cjs/either/either-sync.js +21 -0
- package/cjs/either/either.js +18 -0
- package/cjs/either/index.js +11 -0
- package/cjs/either/left.js +22 -0
- package/cjs/either/operators/bifold/bifold.js +15 -0
- package/cjs/either/operators/bifold/bifoldl.js +17 -0
- package/cjs/either/operators/bifold/bifoldr.js +17 -0
- package/cjs/either/operators/bifold/index.js +9 -0
- package/cjs/either/operators/bifold-map.js +20 -0
- package/cjs/either/operators/bimap/bimap.js +20 -0
- package/cjs/either/operators/bimap/first.js +22 -0
- package/cjs/either/operators/bimap/index.js +9 -0
- package/cjs/either/operators/bimap/second.js +22 -0
- package/cjs/either/operators/guards.js +22 -0
- package/cjs/either/operators/index.js +24 -0
- package/cjs/either/right.js +22 -0
- package/cjs/guard.js +37 -0
- package/cjs/identity.js +12 -0
- package/cjs/index.js +21 -0
- package/cjs/inject.js +23 -0
- package/cjs/maybe/index.js +9 -0
- package/cjs/maybe/just.js +22 -0
- package/cjs/maybe/maybe.js +17 -0
- package/cjs/maybe/nothing.js +22 -0
- package/cjs/maybe/operators/bind.js +21 -0
- package/cjs/maybe/operators/fmap.js +22 -0
- package/cjs/maybe/operators/fold-map.js +20 -0
- package/cjs/maybe/operators/fold.js +17 -0
- package/cjs/maybe/operators/guards.js +22 -0
- package/cjs/maybe/operators/index.js +14 -0
- package/cjs/permutation/index.js +7 -0
- package/cjs/permutation/permutation-2.js +18 -0
- package/cjs/permutation/permutation-3.js +18 -0
- package/cjs/pipe.js +25 -0
- package/cjs/rethrow.js +16 -0
- package/cjs/tap.js +15 -0
- package/cjs/ternary.js +16 -0
- package/compose.d.ts +5 -3
- package/curry.d.ts +6 -4
- package/either/either-sync.d.ts +4 -2
- package/either/either.d.ts +4 -2
- package/either/index.d.ts +3 -3
- package/either/left.d.ts +4 -2
- package/either/operators/bifold/bifold.d.ts +4 -2
- package/either/operators/bifold/bifoldl.d.ts +4 -2
- package/either/operators/bifold/bifoldr.d.ts +4 -2
- package/either/operators/bifold/index.d.ts +3 -3
- package/either/operators/bifold-map.d.ts +6 -4
- package/either/operators/bimap/bimap.d.ts +6 -4
- package/either/operators/bimap/first.d.ts +6 -4
- package/either/operators/bimap/index.d.ts +3 -3
- package/either/operators/bimap/second.d.ts +6 -4
- package/either/operators/guards.d.ts +3 -0
- package/either/operators/index.d.ts +3 -3
- package/either/right.d.ts +4 -2
- package/esm/compose.js +18 -0
- package/esm/curry.js +23 -0
- package/esm/either/either-sync.js +18 -0
- package/esm/either/either.js +15 -0
- package/esm/either/index.js +4 -0
- package/esm/either/left.js +17 -0
- package/esm/either/operators/bifold/bifold.js +12 -0
- package/esm/either/operators/bifold/bifoldl.js +14 -0
- package/esm/either/operators/bifold/bifoldr.js +14 -0
- package/esm/either/operators/bifold/index.js +3 -0
- package/esm/either/operators/bifold-map.js +13 -0
- package/esm/either/operators/bimap/bimap.js +13 -0
- package/esm/either/operators/bimap/first.js +15 -0
- package/esm/either/operators/bimap/index.js +3 -0
- package/esm/either/operators/bimap/second.js +15 -0
- package/esm/either/operators/guards.js +17 -0
- package/esm/either/operators/index.js +4 -0
- package/esm/either/right.js +17 -0
- package/esm/guard.js +26 -0
- package/esm/identity.js +9 -0
- package/esm/index.js +9 -0
- package/esm/inject.js +12 -0
- package/esm/maybe/index.js +3 -0
- package/esm/maybe/just.js +17 -0
- package/esm/maybe/maybe.js +14 -0
- package/esm/maybe/nothing.js +17 -0
- package/esm/maybe/operators/bind.js +14 -0
- package/esm/maybe/operators/fmap.js +15 -0
- package/esm/maybe/operators/fold-map.js +13 -0
- package/esm/maybe/operators/fold.js +14 -0
- package/esm/maybe/operators/guards.js +17 -0
- package/esm/maybe/operators/index.js +5 -0
- package/esm/permutation/index.js +2 -0
- package/esm/permutation/permutation-2.js +11 -0
- package/esm/permutation/permutation-3.js +11 -0
- package/esm/pipe.js +18 -0
- package/esm/rethrow.js +13 -0
- package/esm/tap.js +12 -0
- package/esm/ternary.js +13 -0
- package/guard.d.ts +5 -3
- package/identity.d.ts +4 -2
- package/index.d.ts +9 -5
- package/inject.d.ts +6 -4
- package/maybe/index.d.ts +2 -2
- package/maybe/just.d.ts +4 -2
- package/maybe/maybe.d.ts +4 -2
- package/maybe/nothing.d.ts +4 -2
- package/maybe/operators/bind.d.ts +6 -4
- package/maybe/operators/fmap.d.ts +6 -4
- package/maybe/operators/fold-map.d.ts +10 -8
- package/maybe/operators/fold.d.ts +4 -2
- package/maybe/operators/guards.d.ts +3 -0
- package/maybe/operators/index.d.ts +4 -4
- package/package.json +11 -4
- package/permutation/index.d.ts +2 -0
- package/permutation/permutation-2.d.ts +7 -0
- package/permutation/permutation-3.d.ts +7 -0
- package/pipe.d.ts +5 -3
- package/rethrow.d.ts +9 -0
- package/tap.d.ts +6 -3
- package/ternary.d.ts +10 -0
- package/tsconfig.json +1 -1
- package/{.internal → types}/effect.d.ts +7 -0
- package/types/gradual.d.ts +17 -0
- package/{.internal → types}/last.d.ts +7 -0
- package/types/map.d.ts +8 -0
- package/{.internal → types}/slice.d.ts +7 -0
- package/{.internal → types}/tuple.d.ts +6 -0
- package/.internal/gradual.d.ts +0 -5
- package/.internal/map.d.ts +0 -1
- package/.internal/permutation-of-2.d.ts +0 -1
- package/.internal/permutation-of-2.js +0 -1
- package/.internal/permutation-of-3.d.ts +0 -1
- package/.internal/permutation-of-3.js +0 -1
- package/compose.js +0 -1
- package/curry.js +0 -1
- package/either/either-sync.js +0 -1
- package/either/either.js +0 -1
- package/either/index.js +0 -1
- package/either/left.js +0 -1
- package/either/operators/bifold/bifold.js +0 -1
- package/either/operators/bifold/bifoldl.js +0 -1
- package/either/operators/bifold/bifoldr.js +0 -1
- package/either/operators/bifold/index.js +0 -1
- package/either/operators/bifold-map.js +0 -1
- package/either/operators/bimap/bimap.js +0 -1
- package/either/operators/bimap/first.js +0 -1
- package/either/operators/bimap/index.js +0 -1
- package/either/operators/bimap/second.js +0 -1
- package/either/operators/guards.js +0 -1
- package/either/operators/index.js +0 -1
- package/either/right.js +0 -1
- package/guard.js +0 -1
- package/identity.js +0 -1
- package/index.js +0 -1
- package/inject.js +0 -1
- package/maybe/index.js +0 -1
- package/maybe/just.js +0 -1
- package/maybe/maybe.js +0 -1
- package/maybe/nothing.js +0 -1
- package/maybe/operators/bind.js +0 -1
- package/maybe/operators/fmap.js +0 -1
- package/maybe/operators/fold-map.js +0 -1
- package/maybe/operators/fold.js +0 -1
- package/maybe/operators/guards.js +0 -1
- package/maybe/operators/index.js +0 -1
- package/pipe.js +0 -1
- package/tap.js +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<img src="https://raw.githubusercontent.com/drizzer14/fnts/main/logo.svg" height="64" />
|
|
3
|
-
<h1 align="center"
|
|
3
|
+
<h1 align="center">λ fnts</h1>
|
|
4
4
|
</p>
|
|
5
5
|
|
|
6
6
|
<p align="center">
|
|
@@ -24,62 +24,16 @@ TypeScript / JavaScript functional programming utilities inspired by the
|
|
|
24
24
|
**TypeScript 4.2.2 is required for this package's typings to work properly.**
|
|
25
25
|
|
|
26
26
|
```shell
|
|
27
|
-
|
|
27
|
+
npm i fnts
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
```shell
|
|
31
|
-
|
|
31
|
+
yarn add fnts
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
## Usage
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
and default export of the function itself:
|
|
38
|
-
|
|
39
|
-
```typescript
|
|
40
|
-
import compose from 'fnts/compose'
|
|
41
|
-
import maybe, { Maybe } from 'fnts/maybe'
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
Also, it is possible to import everything from the root by name:
|
|
45
|
-
|
|
46
|
-
```typescript
|
|
47
|
-
import { compose, maybe, identity } from 'fnts'
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### Currying
|
|
51
|
-
|
|
52
|
-
The [curry](src/curry.ts) function is an attempt to create
|
|
53
|
-
a generic currying without relying on overloads.
|
|
54
|
-
It supports the currying of functions with a set amount of arguments,
|
|
55
|
-
as well as variadic functions or the functions with optional arguments.
|
|
56
|
-
The last two, though, require you to set the threshold upon which to curry them,
|
|
57
|
-
as JavaScript does not supply the information about the number of arguments
|
|
58
|
-
in those kinds of functions.
|
|
59
|
-
|
|
60
|
-
### Composition and pipelines
|
|
61
|
-
|
|
62
|
-
[Compose](src/compose.ts) and [pipe](src/pipe.ts) functions you'll encounter
|
|
63
|
-
here are pretty unique in their implementation, as they also are described
|
|
64
|
-
generically rather than through overloads.
|
|
65
|
-
If you encounter any unexpected behaviour in them,
|
|
66
|
-
please feel free to create an [issue](https://github.com/drizzer14/fnts/issues).
|
|
67
|
-
|
|
68
|
-
### Monads
|
|
69
|
-
|
|
70
|
-
There are two commonly used monads in this package:
|
|
71
|
-
[Maybe](src/maybe/maybe.ts) and [Either](src/either/either.ts).
|
|
72
|
-
|
|
73
|
-
Both have their own set of constructors, which rely upon special tags
|
|
74
|
-
represented through symbols – this way the "operators" know you pass them
|
|
75
|
-
the objects related to those monads
|
|
76
|
-
(e.g. [just](src/maybe/maybe.ts) and [nothing](src/maybe/maybe.ts) from `Maybe` monad).
|
|
77
|
-
|
|
78
|
-
For both monads there are aforementioned operators,
|
|
79
|
-
which can perform different transformations on their monads.
|
|
80
|
-
These operators look just like plain functions, so,
|
|
81
|
-
if you are familiar with Haskell or RxJS,
|
|
82
|
-
you should quickly get a grasp on them.
|
|
36
|
+
Please, visit the [documentation](https://drizzer14.github.io/fnts) to obtain the information about the usage and API of `fnts`.
|
|
83
37
|
|
|
84
38
|
## Motivation
|
|
85
39
|
|
package/cjs/compose.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Composition
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/**
|
|
7
|
+
* Applies all of the provided `functions` one-by-one in right-to-left order
|
|
8
|
+
* starting from the `argument`.
|
|
9
|
+
*/
|
|
10
|
+
function compose() {
|
|
11
|
+
var functions = [];
|
|
12
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
13
|
+
functions[_i] = arguments[_i];
|
|
14
|
+
}
|
|
15
|
+
return function (arg) {
|
|
16
|
+
var length = functions.length;
|
|
17
|
+
var composition = arg;
|
|
18
|
+
for (var index = length - 1; index >= 0; index -= 1) {
|
|
19
|
+
var current = functions[index];
|
|
20
|
+
composition = current(composition);
|
|
21
|
+
}
|
|
22
|
+
return composition;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.default = compose;
|
package/cjs/curry.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Curry
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/**
|
|
7
|
+
* Creates an auto-curried function from the one provided.
|
|
8
|
+
* Until the curried function receives an expected number of arguments,
|
|
9
|
+
* defined by either its `length` property or the `length` argument of `curry`,
|
|
10
|
+
* it will return new function which receives from one to the remaining amount
|
|
11
|
+
* of arguments.
|
|
12
|
+
* Any excess arguments will not be applied.
|
|
13
|
+
*/
|
|
14
|
+
function curry(fn, length) {
|
|
15
|
+
if (length === void 0) { length = fn.length; }
|
|
16
|
+
return function () {
|
|
17
|
+
var args = [];
|
|
18
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
19
|
+
args[_i] = arguments[_i];
|
|
20
|
+
}
|
|
21
|
+
var argsLength = args.length;
|
|
22
|
+
if (argsLength === length) {
|
|
23
|
+
return fn.apply(void 0, args);
|
|
24
|
+
}
|
|
25
|
+
if (argsLength > length) {
|
|
26
|
+
return fn.apply(void 0, args.slice(0, length));
|
|
27
|
+
}
|
|
28
|
+
return curry(function () {
|
|
29
|
+
var nextArgs = [];
|
|
30
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
31
|
+
nextArgs[_i] = arguments[_i];
|
|
32
|
+
}
|
|
33
|
+
return fn.apply(void 0, args.concat(nextArgs));
|
|
34
|
+
}, length - argsLength);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
exports.default = curry;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Either
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var left_1 = require("./left");
|
|
7
|
+
var right_1 = require("./right");
|
|
8
|
+
/**
|
|
9
|
+
* Type constructor for `Either`.
|
|
10
|
+
* Creates either `Right` of the value provided,
|
|
11
|
+
* or `Left` of the thrown error.
|
|
12
|
+
*/
|
|
13
|
+
function eitherSync(value) {
|
|
14
|
+
try {
|
|
15
|
+
return right_1.default(value());
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
return left_1.default(error);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = eitherSync;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Either
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var left_1 = require("./left");
|
|
7
|
+
var right_1 = require("./right");
|
|
8
|
+
/**
|
|
9
|
+
* Type constructor for `Either`.
|
|
10
|
+
* Creates either `Right` of the value provided,
|
|
11
|
+
* or `Left` of the error thrown.
|
|
12
|
+
*/
|
|
13
|
+
function either(value) {
|
|
14
|
+
return value()
|
|
15
|
+
.then(right_1.default)
|
|
16
|
+
.catch(left_1.default);
|
|
17
|
+
}
|
|
18
|
+
exports.default = either;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.eitherSync = exports.right = exports.left = exports.default = void 0;
|
|
4
|
+
var either_1 = require("./either");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return either_1.default; } });
|
|
6
|
+
var left_1 = require("./left");
|
|
7
|
+
Object.defineProperty(exports, "left", { enumerable: true, get: function () { return left_1.default; } });
|
|
8
|
+
var right_1 = require("./right");
|
|
9
|
+
Object.defineProperty(exports, "right", { enumerable: true, get: function () { return right_1.default; } });
|
|
10
|
+
var either_sync_1 = require("./either-sync");
|
|
11
|
+
Object.defineProperty(exports, "eitherSync", { enumerable: true, get: function () { return either_sync_1.default; } });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Either
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.lid = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Internal unique identifier for `Left`.
|
|
9
|
+
*/
|
|
10
|
+
exports.lid = Symbol.for('@@functional/left');
|
|
11
|
+
/**
|
|
12
|
+
* Constructor function for `Left`.
|
|
13
|
+
* Creates the special object with one property, represented as unique symbol
|
|
14
|
+
* key, holding the provided value.
|
|
15
|
+
*/
|
|
16
|
+
function left(value) {
|
|
17
|
+
var _a;
|
|
18
|
+
return _a = {},
|
|
19
|
+
_a[exports.lid] = value,
|
|
20
|
+
_a;
|
|
21
|
+
}
|
|
22
|
+
exports.default = left;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Either Operators
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var bifoldl_1 = require("./bifoldl");
|
|
7
|
+
var bifoldr_1 = require("./bifoldr");
|
|
8
|
+
/**
|
|
9
|
+
* Unwraps either the left or the right value of the provided `monad`.
|
|
10
|
+
*/
|
|
11
|
+
function bifold(monad) {
|
|
12
|
+
var _a;
|
|
13
|
+
return (_a = bifoldl_1.default(monad)) !== null && _a !== void 0 ? _a : bifoldr_1.default(monad);
|
|
14
|
+
}
|
|
15
|
+
exports.default = bifold;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Either Operators
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var guards_1 = require("../guards");
|
|
7
|
+
var left_1 = require("../../left");
|
|
8
|
+
/**
|
|
9
|
+
* Returns the left value of the provided `monad`.
|
|
10
|
+
* If the `monad` is `Right`, returns `undefined`.
|
|
11
|
+
*/
|
|
12
|
+
function bifoldl(monad) {
|
|
13
|
+
return guards_1.isLeft(monad)
|
|
14
|
+
? monad[left_1.lid]
|
|
15
|
+
: undefined;
|
|
16
|
+
}
|
|
17
|
+
exports.default = bifoldl;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Either Operators
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var guards_1 = require("../guards");
|
|
7
|
+
var right_1 = require("../../right");
|
|
8
|
+
/**
|
|
9
|
+
* Returns the right value of the provided `monad`.
|
|
10
|
+
* If the `monad` is `Left`, returns `undefined`.
|
|
11
|
+
*/
|
|
12
|
+
function bifoldr(monad) {
|
|
13
|
+
return guards_1.isRight(monad)
|
|
14
|
+
? monad[right_1.rid]
|
|
15
|
+
: undefined;
|
|
16
|
+
}
|
|
17
|
+
exports.default = bifoldr;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bifoldr = exports.bifoldl = exports.default = void 0;
|
|
4
|
+
var bifold_1 = require("./bifold");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return bifold_1.default; } });
|
|
6
|
+
var bifoldl_1 = require("./bifoldl");
|
|
7
|
+
Object.defineProperty(exports, "bifoldl", { enumerable: true, get: function () { return bifoldl_1.default; } });
|
|
8
|
+
var bifoldr_1 = require("./bifoldr");
|
|
9
|
+
Object.defineProperty(exports, "bifoldr", { enumerable: true, get: function () { return bifoldr_1.default; } });
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Either Operators
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var compose_1 = require("../../compose");
|
|
7
|
+
var ternary_1 = require("../../ternary");
|
|
8
|
+
var permutation_3_1 = require("../../permutation/permutation-3");
|
|
9
|
+
var guards_1 = require("./guards");
|
|
10
|
+
var bifold_1 = require("./bifold");
|
|
11
|
+
function bifoldMap() {
|
|
12
|
+
var args = [];
|
|
13
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
14
|
+
args[_i] = arguments[_i];
|
|
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);
|
|
18
|
+
}).apply(void 0, args);
|
|
19
|
+
}
|
|
20
|
+
exports.default = bifoldMap;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Either Operators
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var guards_1 = require("../guards");
|
|
7
|
+
var ternary_1 = require("../../../ternary");
|
|
8
|
+
var permutation_3_1 = require("../../../permutation/permutation-3");
|
|
9
|
+
var first_1 = require("./first");
|
|
10
|
+
var second_1 = require("./second");
|
|
11
|
+
function bimap() {
|
|
12
|
+
var args = [];
|
|
13
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
14
|
+
args[_i] = arguments[_i];
|
|
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);
|
|
18
|
+
}).apply(void 0, args);
|
|
19
|
+
}
|
|
20
|
+
exports.default = bimap;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Either Operators
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var guards_1 = require("../guards");
|
|
7
|
+
var bifold_1 = require("../bifold");
|
|
8
|
+
var compose_1 = require("../../../compose");
|
|
9
|
+
var left_1 = require("../../left");
|
|
10
|
+
var identity_1 = require("../../../identity");
|
|
11
|
+
var ternary_1 = require("../../../ternary");
|
|
12
|
+
var permutation_2_1 = require("../../../permutation/permutation-2");
|
|
13
|
+
function first() {
|
|
14
|
+
var args = [];
|
|
15
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
16
|
+
args[_i] = arguments[_i];
|
|
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);
|
|
20
|
+
}).apply(void 0, args);
|
|
21
|
+
}
|
|
22
|
+
exports.default = first;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.second = exports.first = exports.default = void 0;
|
|
4
|
+
var bimap_1 = require("./bimap");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return bimap_1.default; } });
|
|
6
|
+
var first_1 = require("./first");
|
|
7
|
+
Object.defineProperty(exports, "first", { enumerable: true, get: function () { return first_1.default; } });
|
|
8
|
+
var second_1 = require("./second");
|
|
9
|
+
Object.defineProperty(exports, "second", { enumerable: true, get: function () { return second_1.default; } });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Either Operators
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var bifold_1 = require("../bifold");
|
|
7
|
+
var guards_1 = require("../guards");
|
|
8
|
+
var compose_1 = require("../../../compose");
|
|
9
|
+
var identity_1 = require("../../../identity");
|
|
10
|
+
var right_1 = require("../../right");
|
|
11
|
+
var ternary_1 = require("../../../ternary");
|
|
12
|
+
var permutation_2_1 = require("../../../permutation/permutation-2");
|
|
13
|
+
function second() {
|
|
14
|
+
var args = [];
|
|
15
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
16
|
+
args[_i] = arguments[_i];
|
|
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);
|
|
20
|
+
}).apply(void 0, args);
|
|
21
|
+
}
|
|
22
|
+
exports.default = second;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Either Operators
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isRight = exports.isLeft = void 0;
|
|
7
|
+
var left_1 = require("../left");
|
|
8
|
+
var right_1 = require("../right");
|
|
9
|
+
/**
|
|
10
|
+
* Type guard function to tell if the provided `monad` is `Left`.
|
|
11
|
+
*/
|
|
12
|
+
function isLeft(monad) {
|
|
13
|
+
return Object.prototype.hasOwnProperty.call(monad, left_1.lid);
|
|
14
|
+
}
|
|
15
|
+
exports.isLeft = isLeft;
|
|
16
|
+
/**
|
|
17
|
+
* Type guard function to tell if the provided `monad` is `Right`.
|
|
18
|
+
*/
|
|
19
|
+
function isRight(monad) {
|
|
20
|
+
return Object.prototype.hasOwnProperty.call(monad, right_1.rid);
|
|
21
|
+
}
|
|
22
|
+
exports.isRight = isRight;
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.second = exports.first = exports.bimap = exports.bifoldMap = exports.bifold = exports.bifoldr = exports.bifoldl = void 0;
|
|
14
|
+
var bifold_1 = require("./bifold");
|
|
15
|
+
Object.defineProperty(exports, "bifoldl", { enumerable: true, get: function () { return bifold_1.bifoldl; } });
|
|
16
|
+
Object.defineProperty(exports, "bifoldr", { enumerable: true, get: function () { return bifold_1.bifoldr; } });
|
|
17
|
+
Object.defineProperty(exports, "bifold", { enumerable: true, get: function () { return bifold_1.default; } });
|
|
18
|
+
__exportStar(require("./guards"), exports);
|
|
19
|
+
var bifold_map_1 = require("./bifold-map");
|
|
20
|
+
Object.defineProperty(exports, "bifoldMap", { enumerable: true, get: function () { return bifold_map_1.default; } });
|
|
21
|
+
var bimap_1 = require("./bimap");
|
|
22
|
+
Object.defineProperty(exports, "bimap", { enumerable: true, get: function () { return bimap_1.default; } });
|
|
23
|
+
Object.defineProperty(exports, "first", { enumerable: true, get: function () { return bimap_1.first; } });
|
|
24
|
+
Object.defineProperty(exports, "second", { enumerable: true, get: function () { return bimap_1.second; } });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Either
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.rid = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Internal unique identifier for `Right`.
|
|
9
|
+
*/
|
|
10
|
+
exports.rid = Symbol.for('@@functional/right');
|
|
11
|
+
/**
|
|
12
|
+
* Constructor function for `Right`.
|
|
13
|
+
* Creates the special object with one property, represented as unique symbol
|
|
14
|
+
* key, holding the provided value.
|
|
15
|
+
*/
|
|
16
|
+
function right(value) {
|
|
17
|
+
var _a;
|
|
18
|
+
return _a = {},
|
|
19
|
+
_a[exports.rid] = value,
|
|
20
|
+
_a;
|
|
21
|
+
}
|
|
22
|
+
exports.default = right;
|
package/cjs/guard.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Guard
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/**
|
|
7
|
+
* A function which accepts the pairs of guards:
|
|
8
|
+
* the first one is the `validator`, expected to return a boolean value.
|
|
9
|
+
*
|
|
10
|
+
* If the value is `true`, it's `executor` should run with the provided `args`
|
|
11
|
+
* and return from the `guards` function.
|
|
12
|
+
* If the value is `false`, the process continues to the next `validator`.
|
|
13
|
+
*
|
|
14
|
+
* When no `validator` succeeds, the default executor is run.
|
|
15
|
+
*/
|
|
16
|
+
function guard() {
|
|
17
|
+
var qualifiers = [];
|
|
18
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
19
|
+
qualifiers[_i] = arguments[_i];
|
|
20
|
+
}
|
|
21
|
+
return function () {
|
|
22
|
+
var args = [];
|
|
23
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
24
|
+
args[_i] = arguments[_i];
|
|
25
|
+
}
|
|
26
|
+
var length = qualifiers.length - 1;
|
|
27
|
+
var defaultExpression = qualifiers[length];
|
|
28
|
+
for (var index = 0; index < length; index += 1) {
|
|
29
|
+
var _a = qualifiers[index], validator = _a[0], expression = _a[1];
|
|
30
|
+
if (validator.apply(void 0, args)) {
|
|
31
|
+
return expression.apply(void 0, args);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return defaultExpression.apply(void 0, args);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
exports.default = guard;
|
package/cjs/identity.js
ADDED
package/cjs/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.identity = exports.ternary = exports.rethrow = exports.compose = exports.inject = exports.match = exports.curry = exports.pipe = exports.tap = void 0;
|
|
4
|
+
var tap_1 = require("./tap");
|
|
5
|
+
Object.defineProperty(exports, "tap", { enumerable: true, get: function () { return tap_1.default; } });
|
|
6
|
+
var pipe_1 = require("./pipe");
|
|
7
|
+
Object.defineProperty(exports, "pipe", { enumerable: true, get: function () { return pipe_1.default; } });
|
|
8
|
+
var curry_1 = require("./curry");
|
|
9
|
+
Object.defineProperty(exports, "curry", { enumerable: true, get: function () { return curry_1.default; } });
|
|
10
|
+
var guard_1 = require("./guard");
|
|
11
|
+
Object.defineProperty(exports, "match", { enumerable: true, get: function () { return guard_1.default; } });
|
|
12
|
+
var inject_1 = require("./inject");
|
|
13
|
+
Object.defineProperty(exports, "inject", { enumerable: true, get: function () { return inject_1.default; } });
|
|
14
|
+
var compose_1 = require("./compose");
|
|
15
|
+
Object.defineProperty(exports, "compose", { enumerable: true, get: function () { return compose_1.default; } });
|
|
16
|
+
var rethrow_1 = require("./rethrow");
|
|
17
|
+
Object.defineProperty(exports, "rethrow", { enumerable: true, get: function () { return rethrow_1.default; } });
|
|
18
|
+
var ternary_1 = require("./ternary");
|
|
19
|
+
Object.defineProperty(exports, "ternary", { enumerable: true, get: function () { return ternary_1.default; } });
|
|
20
|
+
var identity_1 = require("./identity");
|
|
21
|
+
Object.defineProperty(exports, "identity", { enumerable: true, get: function () { return identity_1.default; } });
|
package/cjs/inject.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Side Effects
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var permutation_2_1 = require("./permutation/permutation-2");
|
|
7
|
+
function inject() {
|
|
8
|
+
var args = [];
|
|
9
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
10
|
+
args[_i] = arguments[_i];
|
|
11
|
+
}
|
|
12
|
+
return permutation_2_1.default(function (fn, effect) {
|
|
13
|
+
return (function () {
|
|
14
|
+
var args = [];
|
|
15
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
16
|
+
args[_i] = arguments[_i];
|
|
17
|
+
}
|
|
18
|
+
effect.apply(void 0, args);
|
|
19
|
+
return fn.apply(void 0, args);
|
|
20
|
+
});
|
|
21
|
+
}).apply(void 0, args);
|
|
22
|
+
}
|
|
23
|
+
exports.default = inject;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nothing = exports.just = exports.default = void 0;
|
|
4
|
+
var maybe_1 = require("./maybe");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return maybe_1.default; } });
|
|
6
|
+
var just_1 = require("./just");
|
|
7
|
+
Object.defineProperty(exports, "just", { enumerable: true, get: function () { return just_1.default; } });
|
|
8
|
+
var nothing_1 = require("./nothing");
|
|
9
|
+
Object.defineProperty(exports, "nothing", { enumerable: true, get: function () { return nothing_1.default; } });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jid = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module Maybe
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Internal unique identifier for `Just`.
|
|
9
|
+
*/
|
|
10
|
+
exports.jid = Symbol.for('@@functional/just');
|
|
11
|
+
/**
|
|
12
|
+
* Constructor function for `Just`.
|
|
13
|
+
* Creates the special object with one property, represented as unique symbol
|
|
14
|
+
* key, holding the provided value.
|
|
15
|
+
*/
|
|
16
|
+
function just(value) {
|
|
17
|
+
var _a;
|
|
18
|
+
return _a = {},
|
|
19
|
+
_a[exports.jid] = value,
|
|
20
|
+
_a;
|
|
21
|
+
}
|
|
22
|
+
exports.default = just;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Maybe
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var just_1 = require("./just");
|
|
7
|
+
var nothing_1 = require("./nothing");
|
|
8
|
+
/**
|
|
9
|
+
* Constructor function for `Maybe`.
|
|
10
|
+
* Creates either `just` of a provided value, or `nothing`.
|
|
11
|
+
*/
|
|
12
|
+
function maybe(value) {
|
|
13
|
+
return value === null || value === undefined
|
|
14
|
+
? nothing_1.default()
|
|
15
|
+
: just_1.default(value);
|
|
16
|
+
}
|
|
17
|
+
exports.default = maybe;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Maybe
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.nid = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Internal unique identifier for `Nothing`.
|
|
9
|
+
*/
|
|
10
|
+
exports.nid = Symbol.for('@@functional/nothing');
|
|
11
|
+
/**
|
|
12
|
+
* Constructor function for `Nothing`.
|
|
13
|
+
* Creates the special object with one property, represented as unique symbol
|
|
14
|
+
* key, holding the `null` value.
|
|
15
|
+
*/
|
|
16
|
+
function nothing() {
|
|
17
|
+
var _a;
|
|
18
|
+
return _a = {},
|
|
19
|
+
_a[exports.nid] = null,
|
|
20
|
+
_a;
|
|
21
|
+
}
|
|
22
|
+
exports.default = nothing;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Maybe Operators
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var compose_1 = require("../../compose");
|
|
7
|
+
var ternary_1 = require("../../ternary");
|
|
8
|
+
var identity_1 = require("../../identity");
|
|
9
|
+
var permutation_2_1 = require("../../permutation/permutation-2");
|
|
10
|
+
var fold_1 = require("./fold");
|
|
11
|
+
var guards_1 = require("./guards");
|
|
12
|
+
function bind() {
|
|
13
|
+
var args = [];
|
|
14
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
15
|
+
args[_i] = arguments[_i];
|
|
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);
|
|
19
|
+
}).apply(void 0, args);
|
|
20
|
+
}
|
|
21
|
+
exports.default = bind;
|