fnts 1.0.2 → 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 +10 -0
- package/either/either.d.ts +8 -40
- package/either/index.d.ts +4 -1
- package/either/left.d.ts +21 -0
- package/either/operators/bifold/bifold.d.ts +15 -0
- package/either/operators/bifold/bifoldl.d.ts +15 -0
- package/either/operators/bifold/bifoldr.d.ts +15 -0
- package/either/operators/bifold/index.d.ts +3 -0
- package/either/operators/bifold-map.d.ts +10 -7
- package/either/operators/bimap/bimap.d.ts +13 -0
- package/either/operators/bimap/first.d.ts +15 -0
- package/either/operators/bimap/index.d.ts +3 -0
- package/either/operators/bimap/second.d.ts +15 -0
- package/either/operators/guards.d.ts +8 -3
- package/either/operators/index.d.ts +3 -3
- package/either/right.d.ts +21 -0
- 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 -7
- package/inject.d.ts +14 -0
- package/maybe/index.d.ts +3 -1
- package/maybe/just.d.ts +21 -0
- package/maybe/maybe.d.ts +6 -38
- package/maybe/nothing.d.ts +21 -0
- package/maybe/operators/bind.d.ts +10 -7
- package/maybe/operators/fmap.d.ts +10 -7
- package/maybe/operators/fold-map.d.ts +37 -12
- package/maybe/operators/fold.d.ts +7 -3
- package/maybe/operators/guards.d.ts +8 -3
- package/maybe/operators/index.d.ts +5 -5
- package/package.json +12 -5
- 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 +11 -0
- package/ternary.d.ts +10 -0
- package/tsconfig.json +1 -1
- package/types/effect.d.ts +9 -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.js +0 -1
- package/either/index.js +0 -1
- package/either/operators/bifold-map.js +0 -1
- package/either/operators/bifold.d.ts +0 -31
- package/either/operators/bifold.js +0 -1
- package/either/operators/bimap.d.ts +0 -29
- package/either/operators/bimap.js +0 -1
- package/either/operators/guards.js +0 -1
- package/either/operators/index.js +0 -1
- package/guard.js +0 -1
- package/identity.js +0 -1
- package/index.js +0 -1
- package/maybe/index.js +0 -1
- package/maybe/maybe.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
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
4
|
+
import bifoldl from './bifoldl';
|
|
5
|
+
import bifoldr from './bifoldr';
|
|
6
|
+
/**
|
|
7
|
+
* Unwraps either the left or the right value of the provided `monad`.
|
|
8
|
+
*/
|
|
9
|
+
export default function bifold(monad) {
|
|
10
|
+
var _a;
|
|
11
|
+
return (_a = bifoldl(monad)) !== null && _a !== void 0 ? _a : bifoldr(monad);
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
4
|
+
import { isLeft } from '../guards';
|
|
5
|
+
import { lid } from '../../left';
|
|
6
|
+
/**
|
|
7
|
+
* Returns the left value of the provided `monad`.
|
|
8
|
+
* If the `monad` is `Right`, returns `undefined`.
|
|
9
|
+
*/
|
|
10
|
+
export default function bifoldl(monad) {
|
|
11
|
+
return isLeft(monad)
|
|
12
|
+
? monad[lid]
|
|
13
|
+
: undefined;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
4
|
+
import { isRight } from '../guards';
|
|
5
|
+
import { rid } from '../../right';
|
|
6
|
+
/**
|
|
7
|
+
* Returns the right value of the provided `monad`.
|
|
8
|
+
* If the `monad` is `Left`, returns `undefined`.
|
|
9
|
+
*/
|
|
10
|
+
export default function bifoldr(monad) {
|
|
11
|
+
return isRight(monad)
|
|
12
|
+
? monad[rid]
|
|
13
|
+
: undefined;
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
4
|
+
import compose from '../../compose';
|
|
5
|
+
import ternary from '../../ternary';
|
|
6
|
+
import permutation3 from '../../permutation/permutation-3';
|
|
7
|
+
import { isLeft } from './guards';
|
|
8
|
+
import { bifoldl, bifoldr } from './bifold';
|
|
9
|
+
export default function bifoldMap(...args) {
|
|
10
|
+
return permutation3((monad, mapLeft, mapRight) => {
|
|
11
|
+
return ternary(isLeft, compose(mapLeft, bifoldl), compose(mapRight, bifoldr))(monad);
|
|
12
|
+
})(...args);
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
4
|
+
import { isLeft } from '../guards';
|
|
5
|
+
import ternary from '../../../ternary';
|
|
6
|
+
import permutation3 from '../../../permutation/permutation-3';
|
|
7
|
+
import first from './first';
|
|
8
|
+
import second from './second';
|
|
9
|
+
export default function bimap(...args) {
|
|
10
|
+
return permutation3((monad, mapLeft, mapRight) => {
|
|
11
|
+
return ternary(isLeft, first(mapLeft), second(mapRight))(monad);
|
|
12
|
+
})(...args);
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
4
|
+
import { isLeft } from '../guards';
|
|
5
|
+
import { bifoldl } from '../bifold';
|
|
6
|
+
import compose from '../../../compose';
|
|
7
|
+
import left from '../../left';
|
|
8
|
+
import identity from '../../../identity';
|
|
9
|
+
import ternary from '../../../ternary';
|
|
10
|
+
import permutation2 from '../../../permutation/permutation-2';
|
|
11
|
+
export default function first(...args) {
|
|
12
|
+
return permutation2((monad, mapLeft) => {
|
|
13
|
+
return ternary(isLeft, compose(left, mapLeft, bifoldl), identity)(monad);
|
|
14
|
+
})(...args);
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
4
|
+
import { bifoldr } from '../bifold';
|
|
5
|
+
import { isRight } from '../guards';
|
|
6
|
+
import compose from '../../../compose';
|
|
7
|
+
import identity from '../../../identity';
|
|
8
|
+
import right from '../../right';
|
|
9
|
+
import ternary from '../../../ternary';
|
|
10
|
+
import permutation2 from '../../../permutation/permutation-2';
|
|
11
|
+
export default function second(...args) {
|
|
12
|
+
return permutation2((monad, mapRight) => {
|
|
13
|
+
return ternary(isRight, compose(right, mapRight, bifoldr), identity)(monad);
|
|
14
|
+
})(...args);
|
|
15
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either Operators
|
|
3
|
+
*/
|
|
4
|
+
import { lid } from '../left';
|
|
5
|
+
import { rid } from '../right';
|
|
6
|
+
/**
|
|
7
|
+
* Type guard function to tell if the provided `monad` is `Left`.
|
|
8
|
+
*/
|
|
9
|
+
export function isLeft(monad) {
|
|
10
|
+
return Object.prototype.hasOwnProperty.call(monad, lid);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Type guard function to tell if the provided `monad` is `Right`.
|
|
14
|
+
*/
|
|
15
|
+
export function isRight(monad) {
|
|
16
|
+
return Object.prototype.hasOwnProperty.call(monad, rid);
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Either
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Internal unique identifier for `Right`.
|
|
6
|
+
*/
|
|
7
|
+
export const rid = Symbol.for('@@functional/right');
|
|
8
|
+
/**
|
|
9
|
+
* Constructor function for `Right`.
|
|
10
|
+
* Creates the special object with one property, represented as unique symbol
|
|
11
|
+
* key, holding the provided value.
|
|
12
|
+
*/
|
|
13
|
+
export default function right(value) {
|
|
14
|
+
return {
|
|
15
|
+
[rid]: value
|
|
16
|
+
};
|
|
17
|
+
}
|
package/esm/guard.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Guard
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* A function which accepts the pairs of guards:
|
|
6
|
+
* the first one is the `validator`, expected to return a boolean value.
|
|
7
|
+
*
|
|
8
|
+
* If the value is `true`, it's `executor` should run with the provided `args`
|
|
9
|
+
* and return from the `guards` function.
|
|
10
|
+
* If the value is `false`, the process continues to the next `validator`.
|
|
11
|
+
*
|
|
12
|
+
* When no `validator` succeeds, the default executor is run.
|
|
13
|
+
*/
|
|
14
|
+
export default function guard(...qualifiers) {
|
|
15
|
+
return (...args) => {
|
|
16
|
+
const length = qualifiers.length - 1;
|
|
17
|
+
const defaultExpression = qualifiers[length];
|
|
18
|
+
for (let index = 0; index < length; index += 1) {
|
|
19
|
+
const [validator, expression] = qualifiers[index];
|
|
20
|
+
if (validator(...args)) {
|
|
21
|
+
return expression(...args);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return defaultExpression(...args);
|
|
25
|
+
};
|
|
26
|
+
}
|
package/esm/identity.js
ADDED
package/esm/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { default as tap } from './tap';
|
|
2
|
+
export { default as pipe } from './pipe';
|
|
3
|
+
export { default as curry } from './curry';
|
|
4
|
+
export { default as match } from './guard';
|
|
5
|
+
export { default as inject } from './inject';
|
|
6
|
+
export { default as compose } from './compose';
|
|
7
|
+
export { default as rethrow } from './rethrow';
|
|
8
|
+
export { default as ternary } from './ternary';
|
|
9
|
+
export { default as identity } from './identity';
|
package/esm/inject.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Side Effects
|
|
3
|
+
*/
|
|
4
|
+
import permutation2 from './permutation/permutation-2';
|
|
5
|
+
export default function inject(...args) {
|
|
6
|
+
return permutation2((fn, effect) => {
|
|
7
|
+
return ((...args) => {
|
|
8
|
+
effect(...args);
|
|
9
|
+
return fn(...args);
|
|
10
|
+
});
|
|
11
|
+
})(...args);
|
|
12
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Maybe
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Internal unique identifier for `Just`.
|
|
6
|
+
*/
|
|
7
|
+
export const jid = Symbol.for('@@functional/just');
|
|
8
|
+
/**
|
|
9
|
+
* Constructor function for `Just`.
|
|
10
|
+
* Creates the special object with one property, represented as unique symbol
|
|
11
|
+
* key, holding the provided value.
|
|
12
|
+
*/
|
|
13
|
+
export default function just(value) {
|
|
14
|
+
return {
|
|
15
|
+
[jid]: value
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Maybe
|
|
3
|
+
*/
|
|
4
|
+
import just from './just';
|
|
5
|
+
import nothing from './nothing';
|
|
6
|
+
/**
|
|
7
|
+
* Constructor function for `Maybe`.
|
|
8
|
+
* Creates either `just` of a provided value, or `nothing`.
|
|
9
|
+
*/
|
|
10
|
+
export default function maybe(value) {
|
|
11
|
+
return value === null || value === undefined
|
|
12
|
+
? nothing()
|
|
13
|
+
: just(value);
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Maybe
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Internal unique identifier for `Nothing`.
|
|
6
|
+
*/
|
|
7
|
+
export const nid = Symbol.for('@@functional/nothing');
|
|
8
|
+
/**
|
|
9
|
+
* Constructor function for `Nothing`.
|
|
10
|
+
* Creates the special object with one property, represented as unique symbol
|
|
11
|
+
* key, holding the `null` value.
|
|
12
|
+
*/
|
|
13
|
+
export default function nothing() {
|
|
14
|
+
return {
|
|
15
|
+
[nid]: null
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Maybe Operators
|
|
3
|
+
*/
|
|
4
|
+
import compose from '../../compose';
|
|
5
|
+
import ternary from '../../ternary';
|
|
6
|
+
import identity from '../../identity';
|
|
7
|
+
import permutation2 from '../../permutation/permutation-2';
|
|
8
|
+
import fold from './fold';
|
|
9
|
+
import { isJust } from './guards';
|
|
10
|
+
export default function bind(...args) {
|
|
11
|
+
return permutation2((monad, transition) => {
|
|
12
|
+
return ternary(isJust, compose(transition, fold), identity)(monad);
|
|
13
|
+
})(...args);
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Maybe Operators
|
|
3
|
+
*/
|
|
4
|
+
import compose from '../../compose';
|
|
5
|
+
import identity from '../../identity';
|
|
6
|
+
import maybe from '../maybe';
|
|
7
|
+
import permutation2 from '../../permutation/permutation-2';
|
|
8
|
+
import fold from './fold';
|
|
9
|
+
import { isJust } from './guards';
|
|
10
|
+
import ternary from '../../ternary';
|
|
11
|
+
export default function fmap(...args) {
|
|
12
|
+
return permutation2((monad, transition) => {
|
|
13
|
+
return ternary(isJust, compose(maybe, transition, fold), identity)(monad);
|
|
14
|
+
})(...args);
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Maybe Operators
|
|
3
|
+
*/
|
|
4
|
+
import compose from '../../compose';
|
|
5
|
+
import ternary from '../../ternary';
|
|
6
|
+
import permutation2 from '../../permutation/permutation-2';
|
|
7
|
+
import fold from './fold';
|
|
8
|
+
import { isJust } from './guards';
|
|
9
|
+
export default function foldMap(...args) {
|
|
10
|
+
return permutation2((monad, transition) => {
|
|
11
|
+
return ternary(isJust, compose(transition, fold), () => null)(monad);
|
|
12
|
+
})(...args);
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Maybe Operators
|
|
3
|
+
*/
|
|
4
|
+
import { jid } from '../just';
|
|
5
|
+
import { nid } from '../nothing';
|
|
6
|
+
import { isJust } from './guards';
|
|
7
|
+
/**
|
|
8
|
+
* Returns the value of the provided `monad`.
|
|
9
|
+
*/
|
|
10
|
+
export default function fold(monad) {
|
|
11
|
+
return isJust(monad)
|
|
12
|
+
? monad[jid]
|
|
13
|
+
: monad[nid];
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Maybe Operators
|
|
3
|
+
*/
|
|
4
|
+
import { jid } from '../just';
|
|
5
|
+
import { nid } from '../nothing';
|
|
6
|
+
/**
|
|
7
|
+
* Type guard function to tell if the provided `monad` is `Just`.
|
|
8
|
+
*/
|
|
9
|
+
export function isJust(monad) {
|
|
10
|
+
return Object.prototype.hasOwnProperty.call(monad, jid);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Type guard function to tell if the provided `monad` is `Nothing`.
|
|
14
|
+
*/
|
|
15
|
+
export function isNothing(monad) {
|
|
16
|
+
return Object.prototype.hasOwnProperty.call(monad, nid);
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Permutation
|
|
3
|
+
*/
|
|
4
|
+
export default function permutation2(fn, shouldCurry) {
|
|
5
|
+
return (...args) => {
|
|
6
|
+
const [a1, b] = args;
|
|
7
|
+
return (shouldCurry === null || shouldCurry === void 0 ? void 0 : shouldCurry(a1, b)) || args.length < fn.length
|
|
8
|
+
? (a2) => fn(a2, a1)
|
|
9
|
+
: fn(a1, b);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Permutation
|
|
3
|
+
*/
|
|
4
|
+
export default function permutation3(fn, shouldCurry) {
|
|
5
|
+
return (...args) => {
|
|
6
|
+
const [a1, b, c] = args;
|
|
7
|
+
return (shouldCurry === null || shouldCurry === void 0 ? void 0 : shouldCurry(a1, b, c)) || args.length < fn.length
|
|
8
|
+
? (a2) => fn(a2, a1, b)
|
|
9
|
+
: fn(a1, b, c);
|
|
10
|
+
};
|
|
11
|
+
}
|
package/esm/pipe.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Composition
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Applies all of the provided `functions` one-by-one in left-to-right order
|
|
6
|
+
* starting from the `argument`.
|
|
7
|
+
*/
|
|
8
|
+
export default function pipe(...functions) {
|
|
9
|
+
return (arg) => {
|
|
10
|
+
const length = functions.length;
|
|
11
|
+
let pipeline = arg;
|
|
12
|
+
for (let index = 0; index < length; index += 1) {
|
|
13
|
+
const current = functions[index];
|
|
14
|
+
pipeline = current(pipeline);
|
|
15
|
+
}
|
|
16
|
+
return pipeline;
|
|
17
|
+
};
|
|
18
|
+
}
|
package/esm/rethrow.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Side Effects
|
|
3
|
+
*/
|
|
4
|
+
import inject from './inject';
|
|
5
|
+
/**
|
|
6
|
+
* Rethrows a received error
|
|
7
|
+
* performing an optional side effect.
|
|
8
|
+
*/
|
|
9
|
+
export default function rethrow(effect) {
|
|
10
|
+
return inject((error) => {
|
|
11
|
+
throw error;
|
|
12
|
+
}, effect);
|
|
13
|
+
}
|
package/esm/tap.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Side Effects
|
|
3
|
+
*/
|
|
4
|
+
import inject from './inject';
|
|
5
|
+
import identity from './identity';
|
|
6
|
+
/**
|
|
7
|
+
* Performs a side effect
|
|
8
|
+
* passing the received argument through itself.
|
|
9
|
+
*/
|
|
10
|
+
export default function tap(effect) {
|
|
11
|
+
return inject(identity, effect);
|
|
12
|
+
}
|
package/esm/ternary.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Ternary
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Functional alternative to the ternary operator.
|
|
6
|
+
* Enforces the same return type for both branches,
|
|
7
|
+
* the result is evaluated lazily.
|
|
8
|
+
*/
|
|
9
|
+
export default function ternary(predicate, left, right) {
|
|
10
|
+
return (value) => {
|
|
11
|
+
return predicate(value) ? left(value) : right(value);
|
|
12
|
+
};
|
|
13
|
+
}
|
package/guard.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module Guard
|
|
3
|
+
*/
|
|
4
|
+
export declare type GuardQualifier<Function extends (...args: any[]) => any> = [
|
|
2
5
|
validator: <Result extends boolean>(...args: Parameters<Function>) => Result,
|
|
3
6
|
executor: Function
|
|
4
7
|
];
|
|
@@ -12,5 +15,4 @@ export declare type Guard<Function extends (...args: any[]) => any> = [
|
|
|
12
15
|
*
|
|
13
16
|
* When no `validator` succeeds, the default executor is run.
|
|
14
17
|
*/
|
|
15
|
-
export
|
|
16
|
-
export default guard;
|
|
18
|
+
export default function guard<Function extends (...args: any[]) => any>(...qualifiers: [...GuardQualifier<Function>[], Function]): (...args: Parameters<Function>) => ReturnType<Function>;
|
package/identity.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Identity
|
|
3
|
+
*/
|
|
1
4
|
/**
|
|
2
5
|
* A type describing the `identity` function.
|
|
3
6
|
*/
|
|
@@ -5,5 +8,4 @@ export declare type Identity<T> = (x: T) => T;
|
|
|
5
8
|
/**
|
|
6
9
|
* A function which returns the provided value.
|
|
7
10
|
*/
|
|
8
|
-
export
|
|
9
|
-
export default identity;
|
|
11
|
+
export default function identity<T>(x: T): T;
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
1
|
+
export { default as tap } from './tap';
|
|
2
|
+
export { default as pipe } from './pipe';
|
|
3
|
+
export { default as curry } from './curry';
|
|
4
|
+
export { default as match } from './guard';
|
|
5
|
+
export { default as inject } from './inject';
|
|
6
|
+
export { default as compose } from './compose';
|
|
7
|
+
export { default as rethrow } from './rethrow';
|
|
8
|
+
export { default as ternary } from './ternary';
|
|
9
|
+
export { default as identity } from './identity';
|
package/inject.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Side Effects
|
|
3
|
+
*/
|
|
4
|
+
import type { Effect } from './types/effect';
|
|
5
|
+
/**
|
|
6
|
+
* Injects a function with a side effect.
|
|
7
|
+
* Returns the copy of the original function.
|
|
8
|
+
*/
|
|
9
|
+
export default function inject<Function extends (...args: any[]) => any>(effect: Effect<Function>): (fn: Function) => Function;
|
|
10
|
+
/**
|
|
11
|
+
* Injects a function with a side effect.
|
|
12
|
+
* Returns the copy of the original function.
|
|
13
|
+
*/
|
|
14
|
+
export default function inject<Function extends (...args: any[]) => any>(fn: Function, effect: Effect<Function>): Function;
|
package/maybe/index.d.ts
CHANGED
package/maybe/just.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Maybe
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Internal unique identifier for `Just`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const jid: unique symbol;
|
|
8
|
+
/**
|
|
9
|
+
* Type constructor for `Just`.
|
|
10
|
+
* Describes the special object with one property, represented as unique symbol
|
|
11
|
+
* key, holding the provided value type.
|
|
12
|
+
*/
|
|
13
|
+
export declare type Just<Value> = {
|
|
14
|
+
[jid]: Exclude<Value, null | undefined>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Constructor function for `Just`.
|
|
18
|
+
* Creates the special object with one property, represented as unique symbol
|
|
19
|
+
* key, holding the provided value.
|
|
20
|
+
*/
|
|
21
|
+
export default function just<Value>(value: Value): Just<Value>;
|
package/maybe/maybe.d.ts
CHANGED
|
@@ -1,47 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @module Maybe
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Type constructor for `Just`.
|
|
7
|
-
* Describes the special object with one property, represented as unique symbol
|
|
8
|
-
* key, holding the provided value type.
|
|
9
|
-
*/
|
|
10
|
-
export declare type Just<Value> = {
|
|
11
|
-
[jid]: Exclude<Value, null | undefined>;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Constructor function for `Just`.
|
|
15
|
-
* Creates the special object with one property, represented as unique symbol
|
|
16
|
-
* key, holding the provided value.
|
|
17
|
-
*/
|
|
18
|
-
export declare const just: <Value>(value: Value) => Just<Value>;
|
|
19
|
-
/**
|
|
20
|
-
* Internal unique identifier for `Nothing`.
|
|
21
|
-
*/
|
|
22
|
-
export declare const nid: unique symbol;
|
|
23
|
-
/**
|
|
24
|
-
* Type constructor for `Nothing`.
|
|
25
|
-
* Describes the special object with one property, represented as unique symbol
|
|
26
|
-
* key, holding the `null` value type.
|
|
27
|
-
*/
|
|
28
|
-
export declare type Nothing = {
|
|
29
|
-
[nid]: null;
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Constructor function for `Nothing`.
|
|
33
|
-
* Creates the special object with one property, represented as unique symbol
|
|
34
|
-
* key, holding the `null` value.
|
|
35
|
-
*/
|
|
36
|
-
export declare const nothing: () => Nothing;
|
|
4
|
+
import { Just } from './just';
|
|
5
|
+
import { Nothing } from './nothing';
|
|
37
6
|
/**
|
|
38
7
|
* Type constructor for `Maybe`.
|
|
39
|
-
*
|
|
8
|
+
* Can be either `Just` of a provided value type, or `Nothing`.
|
|
40
9
|
*/
|
|
41
10
|
export declare type Maybe<Value> = Just<Value> | Nothing;
|
|
42
11
|
/**
|
|
43
12
|
* Constructor function for `Maybe`.
|
|
44
|
-
*
|
|
13
|
+
* Creates either `just` of a provided value, or `nothing`.
|
|
45
14
|
*/
|
|
46
|
-
export
|
|
47
|
-
export default maybe;
|
|
15
|
+
export default function maybe<Value>(value: Value | null | undefined): Maybe<Value>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Maybe
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Internal unique identifier for `Nothing`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const nid: unique symbol;
|
|
8
|
+
/**
|
|
9
|
+
* Type constructor for `Nothing`.
|
|
10
|
+
* Describes the special object with one property, represented as unique symbol
|
|
11
|
+
* key, holding the `null` value type.
|
|
12
|
+
*/
|
|
13
|
+
export declare type Nothing = {
|
|
14
|
+
[nid]: null;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Constructor function for `Nothing`.
|
|
18
|
+
* Creates the special object with one property, represented as unique symbol
|
|
19
|
+
* key, holding the `null` value.
|
|
20
|
+
*/
|
|
21
|
+
export default function nothing(): Nothing;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Maybe Operators
|
|
3
|
+
*/
|
|
1
4
|
import type { Maybe } from '../maybe';
|
|
2
|
-
import type { Map } from '
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import type { Map } from '../../types/map';
|
|
6
|
+
/**
|
|
7
|
+
* Binds the value of the `monad` to new monad created
|
|
8
|
+
* by the `transition` function.
|
|
9
|
+
*/
|
|
10
|
+
export default function bind<Value, NextValue>(transition: Map<Value, Maybe<NextValue>>): (monad: Maybe<Value>) => Maybe<NextValue>;
|
|
7
11
|
/**
|
|
8
12
|
* Binds the value of the `monad` to new monad created
|
|
9
13
|
* by the `transition` function.
|
|
10
14
|
*/
|
|
11
|
-
export
|
|
12
|
-
export default bind;
|
|
15
|
+
export default function bind<Value, NextValue>(monad: Maybe<Value>, transition: Map<Value, Maybe<NextValue>>): Maybe<NextValue>;
|