fnts 1.3.0 → 1.3.1
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/{cjs/compose.js → compose.js} +0 -0
- package/{cjs/curry.js → curry.js} +0 -0
- package/{cjs/either → either}/either-sync.js +0 -0
- package/{cjs/either → either}/either.js +0 -0
- package/{cjs/either → either}/index.js +0 -0
- package/{cjs/either → either}/left.js +0 -0
- package/{cjs/either → either}/operators/bifold/bifold.js +0 -0
- package/{cjs/either → either}/operators/bifold/bifoldl.js +0 -0
- package/{cjs/either → either}/operators/bifold/bifoldr.js +0 -0
- package/{cjs/either → either}/operators/bifold/index.js +0 -0
- package/{cjs/either → either}/operators/bifold-map.js +0 -0
- package/{cjs/either → either}/operators/bimap/bimap.js +0 -0
- package/{cjs/either → either}/operators/bimap/first.js +0 -0
- package/{cjs/either → either}/operators/bimap/index.js +0 -0
- package/{cjs/either → either}/operators/bimap/second.js +0 -0
- package/{cjs/either → either}/operators/guards.js +0 -0
- package/{cjs/either → either}/operators/index.js +0 -0
- package/{cjs/either → either}/right.js +0 -0
- package/{cjs/guard.js → guard.js} +0 -0
- package/{cjs/identity.js → identity.js} +0 -0
- package/{cjs/index.js → index.js} +0 -0
- package/{cjs/inject.js → inject.js} +0 -0
- package/{cjs/maybe → maybe}/index.js +0 -0
- package/{cjs/maybe → maybe}/just.js +0 -0
- package/{cjs/maybe → maybe}/maybe.js +0 -0
- package/{cjs/maybe → maybe}/nothing.js +0 -0
- package/{cjs/maybe → maybe}/operators/bind.js +0 -0
- package/{cjs/maybe → maybe}/operators/fmap.js +0 -0
- package/{cjs/maybe → maybe}/operators/fold-map.js +0 -0
- package/{cjs/maybe → maybe}/operators/fold.js +0 -0
- package/{cjs/maybe → maybe}/operators/guards.js +0 -0
- package/{cjs/maybe → maybe}/operators/index.js +0 -0
- package/package.json +2 -3
- package/{cjs/permutation → permutation}/index.js +0 -0
- package/{cjs/permutation → permutation}/permutation-2.js +0 -0
- package/{cjs/permutation → permutation}/permutation-3.js +0 -0
- package/{cjs/pipe.js → pipe.js} +0 -0
- package/{cjs/rethrow.js → rethrow.js} +0 -0
- package/{cjs/tap.js → tap.js} +0 -0
- package/{cjs/ternary.js → ternary.js} +0 -0
- package/esm/compose.js +0 -18
- package/esm/curry.js +0 -23
- package/esm/either/either-sync.js +0 -18
- package/esm/either/either.js +0 -15
- package/esm/either/index.js +0 -4
- package/esm/either/left.js +0 -17
- package/esm/either/operators/bifold/bifold.js +0 -12
- package/esm/either/operators/bifold/bifoldl.js +0 -14
- package/esm/either/operators/bifold/bifoldr.js +0 -14
- package/esm/either/operators/bifold/index.js +0 -3
- package/esm/either/operators/bifold-map.js +0 -13
- package/esm/either/operators/bimap/bimap.js +0 -13
- package/esm/either/operators/bimap/first.js +0 -15
- package/esm/either/operators/bimap/index.js +0 -3
- package/esm/either/operators/bimap/second.js +0 -15
- package/esm/either/operators/guards.js +0 -17
- package/esm/either/operators/index.js +0 -4
- package/esm/either/right.js +0 -17
- package/esm/guard.js +0 -26
- package/esm/identity.js +0 -9
- package/esm/index.js +0 -9
- package/esm/inject.js +0 -12
- package/esm/maybe/index.js +0 -3
- package/esm/maybe/just.js +0 -17
- package/esm/maybe/maybe.js +0 -14
- package/esm/maybe/nothing.js +0 -17
- package/esm/maybe/operators/bind.js +0 -14
- package/esm/maybe/operators/fmap.js +0 -15
- package/esm/maybe/operators/fold-map.js +0 -13
- package/esm/maybe/operators/fold.js +0 -14
- package/esm/maybe/operators/guards.js +0 -17
- package/esm/maybe/operators/index.js +0 -5
- package/esm/permutation/index.js +0 -2
- package/esm/permutation/permutation-2.js +0 -11
- package/esm/permutation/permutation-3.js +0 -11
- package/esm/pipe.js +0 -18
- package/esm/rethrow.js +0 -13
- package/esm/tap.js +0 -12
- package/esm/ternary.js +0 -13
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fnts",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Dmytro Vasylkivskyi",
|
|
6
6
|
"description": "TypeScript / JavaScript FP utilities",
|
|
@@ -22,6 +22,5 @@
|
|
|
22
22
|
"optional": true
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
|
-
"main": "
|
|
26
|
-
"module": "esm/index.js"
|
|
25
|
+
"main": "index.js"
|
|
27
26
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/{cjs/pipe.js → pipe.js}
RENAMED
|
File without changes
|
|
File without changes
|
package/{cjs/tap.js → tap.js}
RENAMED
|
File without changes
|
|
File without changes
|
package/esm/compose.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module Composition
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Applies all of the provided `functions` one-by-one in right-to-left order
|
|
6
|
-
* starting from the `argument`.
|
|
7
|
-
*/
|
|
8
|
-
export default function compose(...functions) {
|
|
9
|
-
return (arg) => {
|
|
10
|
-
const length = functions.length;
|
|
11
|
-
let composition = arg;
|
|
12
|
-
for (let index = length - 1; index >= 0; index -= 1) {
|
|
13
|
-
const current = functions[index];
|
|
14
|
-
composition = current(composition);
|
|
15
|
-
}
|
|
16
|
-
return composition;
|
|
17
|
-
};
|
|
18
|
-
}
|
package/esm/curry.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module Curry
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Creates an auto-curried function from the one provided.
|
|
6
|
-
* Until the curried function receives an expected number of arguments,
|
|
7
|
-
* defined by either its `length` property or the `length` argument of `curry`,
|
|
8
|
-
* it will return new function which receives from one to the remaining amount
|
|
9
|
-
* of arguments.
|
|
10
|
-
* Any excess arguments will not be applied.
|
|
11
|
-
*/
|
|
12
|
-
export default function curry(fn, length = fn.length) {
|
|
13
|
-
return (...args) => {
|
|
14
|
-
const argsLength = args.length;
|
|
15
|
-
if (argsLength === length) {
|
|
16
|
-
return fn(...args);
|
|
17
|
-
}
|
|
18
|
-
if (argsLength > length) {
|
|
19
|
-
return fn(...args.slice(0, length));
|
|
20
|
-
}
|
|
21
|
-
return curry((...nextArgs) => fn(...args.concat(nextArgs)), length - argsLength);
|
|
22
|
-
};
|
|
23
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module Either
|
|
3
|
-
*/
|
|
4
|
-
import left from './left';
|
|
5
|
-
import right from './right';
|
|
6
|
-
/**
|
|
7
|
-
* Type constructor for `Either`.
|
|
8
|
-
* Creates either `Right` of the value provided,
|
|
9
|
-
* or `Left` of the thrown error.
|
|
10
|
-
*/
|
|
11
|
-
export default function eitherSync(value) {
|
|
12
|
-
try {
|
|
13
|
-
return right(value());
|
|
14
|
-
}
|
|
15
|
-
catch (error) {
|
|
16
|
-
return left(error);
|
|
17
|
-
}
|
|
18
|
-
}
|
package/esm/either/either.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module Either
|
|
3
|
-
*/
|
|
4
|
-
import left from './left';
|
|
5
|
-
import right from './right';
|
|
6
|
-
/**
|
|
7
|
-
* Type constructor for `Either`.
|
|
8
|
-
* Creates either `Right` of the value provided,
|
|
9
|
-
* or `Left` of the error thrown.
|
|
10
|
-
*/
|
|
11
|
-
export default function either(value) {
|
|
12
|
-
return value()
|
|
13
|
-
.then(right)
|
|
14
|
-
.catch(left);
|
|
15
|
-
}
|
package/esm/either/index.js
DELETED
package/esm/either/left.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module Either
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Internal unique identifier for `Left`.
|
|
6
|
-
*/
|
|
7
|
-
export const lid = Symbol.for('@@functional/left');
|
|
8
|
-
/**
|
|
9
|
-
* Constructor function for `Left`.
|
|
10
|
-
* Creates the special object with one property, represented as unique symbol
|
|
11
|
-
* key, holding the provided value.
|
|
12
|
-
*/
|
|
13
|
-
export default function left(value) {
|
|
14
|
-
return {
|
|
15
|
-
[lid]: value
|
|
16
|
-
};
|
|
17
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
}
|
package/esm/either/right.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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
DELETED
package/esm/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
}
|
package/esm/maybe/index.js
DELETED
package/esm/maybe/just.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
}
|
package/esm/maybe/maybe.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
}
|
package/esm/maybe/nothing.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
}
|
package/esm/permutation/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|