mirror of
https://github.com/swc-project/swc.git
synced 2024-12-20 20:22:26 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
// Loaded from https://deno.land/x/ramda@v0.27.2/source/either.js
|
|
|
|
|
|
import _curry2 from './internal/_curry2.js';
|
|
import _isFunction from './internal/_isFunction.js';
|
|
import lift from './lift.js';
|
|
import or from './or.js';
|
|
|
|
|
|
/**
|
|
* A function wrapping calls to the two functions in an `||` operation,
|
|
* returning the result of the first function if it is truth-y and the result
|
|
* of the second function otherwise. Note that this is short-circuited,
|
|
* meaning that the second function will not be invoked if the first returns a
|
|
* truth-y value.
|
|
*
|
|
* In addition to functions, `R.either` also accepts any fantasy-land compatible
|
|
* applicative functor.
|
|
*
|
|
* @func
|
|
* @memberOf R
|
|
* @since v0.12.0
|
|
* @category Logic
|
|
* @sig (*... -> Boolean) -> (*... -> Boolean) -> (*... -> Boolean)
|
|
* @param {Function} f a predicate
|
|
* @param {Function} g another predicate
|
|
* @return {Function} a function that applies its arguments to `f` and `g` and `||`s their outputs together.
|
|
* @see R.both, R.or
|
|
* @example
|
|
*
|
|
* const gt10 = x => x > 10;
|
|
* const even = x => x % 2 === 0;
|
|
* const f = R.either(gt10, even);
|
|
* f(101); //=> true
|
|
* f(8); //=> true
|
|
*
|
|
* R.either(Maybe.Just(false), Maybe.Just(55)); // => Maybe.Just(55)
|
|
* R.either([false, false, 'a'], [11]) // => [11, 11, "a"]
|
|
*/
|
|
var either = _curry2(function either(f, g) {
|
|
return _isFunction(f) ?
|
|
function _either() {
|
|
return f.apply(this, arguments) || g.apply(this, arguments);
|
|
} :
|
|
lift(or)(f, g);
|
|
});
|
|
export default either;
|