fnts 1.2.0 → 1.3.3
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/compose.d.ts +9 -9
- package/compose.js +24 -1
- package/curry.d.ts +8 -5
- package/curry.js +37 -1
- package/either/either-sync.d.ts +4 -2
- package/either/either-sync.js +21 -1
- package/either/either.d.ts +4 -2
- package/either/either.js +18 -1
- package/either/index.d.ts +3 -3
- package/either/index.js +11 -1
- package/either/left.d.ts +4 -2
- package/either/left.js +22 -1
- package/either/operators/bifold/bifold.d.ts +4 -2
- package/either/operators/bifold/bifold.js +15 -1
- package/either/operators/bifold/bifoldl.d.ts +4 -2
- package/either/operators/bifold/bifoldl.js +17 -1
- package/either/operators/bifold/bifoldr.d.ts +4 -2
- package/either/operators/bifold/bifoldr.js +17 -1
- package/either/operators/bifold/index.d.ts +3 -3
- package/either/operators/bifold/index.js +9 -1
- package/either/operators/bifold-map.d.ts +6 -4
- package/either/operators/bifold-map.js +20 -1
- package/either/operators/bimap/bimap.d.ts +6 -4
- package/either/operators/bimap/bimap.js +20 -1
- package/either/operators/bimap/first.d.ts +6 -4
- package/either/operators/bimap/first.js +22 -1
- package/either/operators/bimap/index.d.ts +3 -3
- package/either/operators/bimap/index.js +9 -1
- package/either/operators/bimap/second.d.ts +6 -4
- package/either/operators/bimap/second.js +22 -1
- package/either/operators/guards.d.ts +3 -0
- package/either/operators/guards.js +22 -1
- package/either/operators/index.d.ts +3 -3
- package/either/operators/index.js +24 -1
- package/either/right.d.ts +4 -2
- package/either/right.js +22 -1
- package/guard.d.ts +6 -3
- package/guard.js +36 -1
- package/identity.d.ts +4 -2
- package/identity.js +12 -1
- package/index.d.ts +9 -5
- package/index.js +21 -1
- package/inject.d.ts +7 -4
- package/inject.js +23 -1
- package/maybe/index.d.ts +2 -2
- package/maybe/index.js +9 -1
- package/maybe/just.d.ts +4 -2
- package/maybe/just.js +22 -1
- package/maybe/maybe.d.ts +4 -2
- package/maybe/maybe.js +17 -1
- package/maybe/nothing.d.ts +4 -2
- package/maybe/nothing.js +22 -1
- package/maybe/operators/bind.d.ts +6 -4
- package/maybe/operators/bind.js +21 -1
- package/maybe/operators/fmap.d.ts +6 -4
- package/maybe/operators/fmap.js +22 -1
- package/maybe/operators/fold-map.d.ts +6 -24
- package/maybe/operators/fold-map.js +20 -1
- package/maybe/operators/fold.d.ts +4 -2
- package/maybe/operators/fold.js +17 -1
- package/maybe/operators/guards.d.ts +3 -0
- package/maybe/operators/guards.js +22 -1
- package/maybe/operators/index.d.ts +4 -4
- package/maybe/operators/index.js +14 -1
- package/package.json +10 -4
- package/permutation/index.d.ts +2 -0
- package/permutation/index.js +7 -0
- package/permutation/permutation-2.d.ts +8 -0
- package/permutation/permutation-2.js +18 -0
- package/permutation/permutation-3.d.ts +8 -0
- package/permutation/permutation-3.js +18 -0
- package/pipe.d.ts +9 -9
- package/pipe.js +24 -1
- package/rethrow.d.ts +9 -0
- package/rethrow.js +16 -0
- package/tap.d.ts +6 -3
- package/tap.js +15 -1
- package/ternary.d.ts +10 -0
- package/ternary.js +16 -0
- package/tsconfig.json +1 -1
- package/types/effect.d.ts +11 -0
- package/types/function.d.ts +13 -0
- package/types/gradual.d.ts +17 -0
- package/types/index.d.ts +7 -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/effect.d.ts +0 -2
- 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/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/compose.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module Composition
|
|
3
|
+
*/
|
|
4
|
+
import type { Last } from './types/last';
|
|
5
|
+
import type { UnaryFunction } from './types/function';
|
|
2
6
|
/**
|
|
3
7
|
* Creates a `Composition` type which parses all of the provided functions' types.
|
|
4
8
|
* Any function with either an incorrect argument or a return type will not fit
|
|
@@ -6,16 +10,12 @@ import type { Last } from './.internal/last';
|
|
|
6
10
|
* type matches the return type of the next function and its return type
|
|
7
11
|
* matches the type of the previous function's argument.
|
|
8
12
|
*/
|
|
9
|
-
export declare type Composition<Functions extends
|
|
10
|
-
...Composition<[
|
|
11
|
-
...Rest,
|
|
12
|
-
(arg: ReturnType<Last>) => ReturnType<Penultimate>
|
|
13
|
-
]>,
|
|
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>,
|
|
14
15
|
Last
|
|
15
|
-
] :
|
|
16
|
+
] : Functions;
|
|
16
17
|
/**
|
|
17
18
|
* Applies all of the provided `functions` one-by-one in right-to-left order
|
|
18
19
|
* starting from the `argument`.
|
|
19
20
|
*/
|
|
20
|
-
export
|
|
21
|
-
export default compose;
|
|
21
|
+
export default function compose<Functions extends UnaryFunction[]>(...functions: Composition<Functions>): (arg: Parameters<Last<Functions>>[0]) => ReturnType<Functions[0]>;
|
package/compose.js
CHANGED
|
@@ -1 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
+
composition = functions[index](composition);
|
|
20
|
+
}
|
|
21
|
+
return composition;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.default = compose;
|
package/curry.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module Curry
|
|
3
|
+
*/
|
|
4
|
+
import type { Slice } from './types/slice';
|
|
5
|
+
import type { Gradual } from './types/gradual';
|
|
6
|
+
import type { VariadicFunction } from './types/function';
|
|
3
7
|
/**
|
|
4
8
|
* Creates a type for an auto-curried function.
|
|
5
9
|
*/
|
|
6
|
-
export declare type Currying<Function extends
|
|
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>>;
|
|
7
11
|
/**
|
|
8
12
|
* Creates an auto-curried function from the one provided.
|
|
9
13
|
* Until the curried function receives an expected number of arguments,
|
|
@@ -12,5 +16,4 @@ export declare type Currying<Function extends (...args: any[]) => any, Length ex
|
|
|
12
16
|
* of arguments.
|
|
13
17
|
* Any excess arguments will not be applied.
|
|
14
18
|
*/
|
|
15
|
-
export
|
|
16
|
-
export default curry;
|
|
19
|
+
export default function curry<Function extends VariadicFunction, Length extends number = Parameters<Function>['length']>(fn: Function, length?: Length): Currying<Function, Length>;
|
package/curry.js
CHANGED
|
@@ -1 +1,37 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
package/either/either-sync.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either
|
|
3
|
+
*/
|
|
1
4
|
import type { Either } from './either';
|
|
2
5
|
/**
|
|
3
6
|
* Type constructor for `Either`.
|
|
4
7
|
* Creates either `Right` of the value provided,
|
|
5
8
|
* or `Left` of the thrown error.
|
|
6
9
|
*/
|
|
7
|
-
export
|
|
8
|
-
export default eitherSync;
|
|
10
|
+
export default function eitherSync<LeftValue, RightValue>(value: () => RightValue): Either<LeftValue, RightValue>;
|
package/either/either-sync.js
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
package/either/either.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either
|
|
3
|
+
*/
|
|
1
4
|
import { Left } from './left';
|
|
2
5
|
import { Right } from './right';
|
|
3
6
|
/**
|
|
@@ -11,5 +14,4 @@ export declare type Either<LeftValue, RightValue> = Left<LeftValue> | Right<Righ
|
|
|
11
14
|
* Creates either `Right` of the value provided,
|
|
12
15
|
* or `Left` of the error thrown.
|
|
13
16
|
*/
|
|
14
|
-
export
|
|
15
|
-
export default either;
|
|
17
|
+
export default function either<LeftValue, RightValue>(value: () => Promise<RightValue>): Promise<Either<LeftValue, RightValue>>;
|
package/either/either.js
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
package/either/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { left, Left } from './left';
|
|
2
|
-
export { right, Right } from './right';
|
|
3
|
-
export { eitherSync } from './either-sync';
|
|
4
1
|
export { default, Either } from './either';
|
|
2
|
+
export { default as left, Left } from './left';
|
|
3
|
+
export { default as right, Right } from './right';
|
|
4
|
+
export { default as eitherSync } from './either-sync';
|
package/either/index.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
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; } });
|
package/either/left.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either
|
|
3
|
+
*/
|
|
1
4
|
/**
|
|
2
5
|
* Internal unique identifier for `Left`.
|
|
3
6
|
*/
|
|
@@ -15,5 +18,4 @@ export declare type Left<Value> = {
|
|
|
15
18
|
* Creates the special object with one property, represented as unique symbol
|
|
16
19
|
* key, holding the provided value.
|
|
17
20
|
*/
|
|
18
|
-
export
|
|
19
|
-
export default left;
|
|
21
|
+
export default function left<Value>(value: Value): Left<Value>;
|
package/either/left.js
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
1
4
|
import type { Left } from '../../left';
|
|
2
5
|
import type { Right } from '../../right';
|
|
3
6
|
import type { Either } from '../../either';
|
|
@@ -9,5 +12,4 @@ export declare type Bifold<Monad extends Either<any, any>> = Monad extends Left<
|
|
|
9
12
|
/**
|
|
10
13
|
* Unwraps either the left or the right value of the provided `monad`.
|
|
11
14
|
*/
|
|
12
|
-
export
|
|
13
|
-
export default bifold;
|
|
15
|
+
export default function bifold<Monad extends Either<any, any>>(monad: Monad): Bifold<Monad>;
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
1
4
|
import { Left } from '../../left';
|
|
2
5
|
import type { Either } from '../../either';
|
|
3
6
|
/**
|
|
@@ -9,5 +12,4 @@ export declare type Bifoldl<Monad extends Either<any, any>> = Monad extends Left
|
|
|
9
12
|
* Returns the left value of the provided `monad`.
|
|
10
13
|
* If the `monad` is `Right`, returns `undefined`.
|
|
11
14
|
*/
|
|
12
|
-
export
|
|
13
|
-
export default bifoldl;
|
|
15
|
+
export default function bifoldl<Monad extends Either<any, any>>(monad: Monad): Bifoldl<Monad>;
|
|
@@ -1 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
1
4
|
import { Right } from '../../right';
|
|
2
5
|
import type { Either } from '../../either';
|
|
3
6
|
/**
|
|
@@ -9,5 +12,4 @@ export declare type Bifoldr<Monad extends Either<any, any>> = Monad extends Righ
|
|
|
9
12
|
* Returns the right value of the provided `monad`.
|
|
10
13
|
* If the `monad` is `Left`, returns `undefined`.
|
|
11
14
|
*/
|
|
12
|
-
export
|
|
13
|
-
export default bifoldr;
|
|
15
|
+
export default function bifoldr<Monad extends Either<any, any>>(monad: Monad): Bifoldr<Monad>;
|
|
@@ -1 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export { default
|
|
1
|
+
export { default, Bifold } from './bifold';
|
|
2
|
+
export { default as bifoldl, Bifoldl } from './bifoldl';
|
|
3
|
+
export { default as bifoldr, Bifoldr } from './bifoldr';
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
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; } });
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
1
4
|
import type { Either } from '../either';
|
|
2
|
-
import type { Map } from '
|
|
5
|
+
import type { Map } from '../../types/map';
|
|
3
6
|
/**
|
|
4
7
|
* Maps left and right values of the provided `monad` to a value,
|
|
5
8
|
* then returns it.
|
|
6
9
|
*/
|
|
7
|
-
export
|
|
10
|
+
export default function bifoldMap<LeftValue, RightValue, MappedValue>(mapLeft: Map<LeftValue, MappedValue>, mapRight: Map<RightValue, MappedValue>): (monad: Either<LeftValue, RightValue>) => MappedValue;
|
|
8
11
|
/**
|
|
9
12
|
* Maps left and right values of the provided `monad` to a value,
|
|
10
13
|
* then returns it.
|
|
11
14
|
*/
|
|
12
|
-
export
|
|
13
|
-
export default bifoldMap;
|
|
15
|
+
export default function bifoldMap<LeftValue, RightValue, MappedValue>(monad: Either<LeftValue, RightValue>, mapLeft: Map<LeftValue, MappedValue>, mapRight: Map<RightValue, MappedValue>): MappedValue;
|
|
@@ -1 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
1
4
|
import type { Either } from '../../either';
|
|
2
|
-
import type { Map } from '
|
|
5
|
+
import type { Map } from '../../../types/map';
|
|
3
6
|
/**
|
|
4
7
|
* Maps left and right values of the provided `monad` to a new `Either` monad.
|
|
5
8
|
*/
|
|
6
|
-
export
|
|
9
|
+
export default function bimap<LeftValue, RightValue, NextLeftValue, NextRightValue>(mapLeft: Map<LeftValue, NextLeftValue>, mapRight: Map<RightValue, NextRightValue>): (monad: Either<LeftValue, RightValue>) => Either<NextLeftValue, NextRightValue>;
|
|
7
10
|
/**
|
|
8
11
|
* Maps left and right values of the provided `monad` to a new `Either` monad.
|
|
9
12
|
*/
|
|
10
|
-
export
|
|
11
|
-
export default bimap;
|
|
13
|
+
export default function bimap<LeftValue, RightValue, NextLeftValue, NextRightValue>(monad: Either<LeftValue, RightValue>, mapLeft: Map<LeftValue, NextLeftValue>, mapRight: Map<RightValue, NextRightValue>): Either<NextLeftValue, NextRightValue>;
|
|
@@ -1 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
1
4
|
import type { Either } from '../../either';
|
|
2
|
-
import type { Map } from '
|
|
5
|
+
import type { Map } from '../../../types/map';
|
|
3
6
|
/**
|
|
4
7
|
* Maps the left value of the provided `monad` to a new `Either` monad
|
|
5
8
|
* with the same right value.
|
|
6
9
|
*/
|
|
7
|
-
export
|
|
10
|
+
export default function first<LeftValue, RightValue, NextLeftValue>(mapLeft: Map<LeftValue, NextLeftValue>): (monad: Either<LeftValue, RightValue>) => Either<NextLeftValue, RightValue>;
|
|
8
11
|
/**
|
|
9
12
|
* Maps the left value of the provided `monad` to a new `Either` monad
|
|
10
13
|
* with the same right value.
|
|
11
14
|
*/
|
|
12
|
-
export
|
|
13
|
-
export default first;
|
|
15
|
+
export default function first<LeftValue, RightValue, NextLeftValue>(monad: Either<LeftValue, RightValue>, mapLeft: Map<LeftValue, NextLeftValue>): Either<NextLeftValue, RightValue>;
|
|
@@ -1 +1,22 @@
|
|
|
1
|
-
"use strict";
|
|
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 ternary_1 = require("../../../ternary");
|
|
10
|
+
var left_1 = require("../../left");
|
|
11
|
+
var identity_1 = require("../../../identity");
|
|
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;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export { default
|
|
1
|
+
export { default } from './bimap';
|
|
2
|
+
export { default as first } from './first';
|
|
3
|
+
export { default as second } from './second';
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
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; } });
|