Innovenergy_trunk/frontend/node_modules/fp-ts/lib/boolean.js

168 lines
4.4 KiB
JavaScript
Raw Permalink Normal View History

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Show = exports.Ord = exports.MonoidAny = exports.MonoidAll = exports.SemigroupAny = exports.SemigroupAll = exports.BooleanAlgebra = exports.Eq = exports.fold = exports.match = exports.foldW = exports.matchW = exports.isBoolean = void 0;
// -------------------------------------------------------------------------------------
// refinements
// -------------------------------------------------------------------------------------
/**
* @category refinements
* @since 2.11.0
*/
var isBoolean = function (u) { return typeof u === 'boolean'; };
exports.isBoolean = isBoolean;
/**
* Less strict version of [`match`](#match).
*
* The `W` suffix (short for **W**idening) means that the handler return types will be merged.
*
* @category pattern matching
* @since 2.10.0
*/
var matchW = function (onFalse, onTrue) {
return function (value) {
return value ? onTrue() : onFalse();
};
};
exports.matchW = matchW;
/**
* Alias of [`matchW`](#matchw).
*
* @category pattern matching
* @since 2.10.0
*/
exports.foldW = exports.matchW;
/**
* Defines the fold over a boolean value.
* Takes two thunks `onTrue`, `onFalse` and a `boolean` value.
* If `value` is false, `onFalse()` is returned, otherwise `onTrue()`.
*
* @example
* import { some, map } from 'fp-ts/Option'
* import { pipe } from 'fp-ts/function'
* import { match } from 'fp-ts/boolean'
*
* assert.deepStrictEqual(
* pipe(
* some(true),
* map(match(() => 'false', () => 'true'))
* ),
* some('true')
* )
*
* @category pattern matching
* @since 2.10.0
*/
exports.match = exports.foldW;
/**
* Alias of [`match`](#match).
*
* @category pattern matching
* @since 2.2.0
*/
exports.fold = exports.match;
// -------------------------------------------------------------------------------------
// instances
// -------------------------------------------------------------------------------------
/**
* @category instances
* @since 2.10.0
*/
exports.Eq = {
equals: function (first, second) { return first === second; }
};
/**
* @category instances
* @since 2.10.0
*/
exports.BooleanAlgebra = {
meet: function (first, second) { return first && second; },
join: function (first, second) { return first || second; },
zero: false,
one: true,
implies: function (first, second) { return !first || second; },
not: function (b) { return !b; }
};
/**
* `boolean` semigroup under conjunction.
*
* @example
* import { SemigroupAll } from 'fp-ts/boolean'
*
* assert.deepStrictEqual(SemigroupAll.concat(true, true), true)
* assert.deepStrictEqual(SemigroupAll.concat(true, false), false)
*
* @category instances
* @since 2.10.0
*/
exports.SemigroupAll = {
concat: function (first, second) { return first && second; }
};
/**
* `boolean` semigroup under disjunction.
*
* @example
* import { SemigroupAny } from 'fp-ts/boolean'
*
* assert.deepStrictEqual(SemigroupAny.concat(true, true), true)
* assert.deepStrictEqual(SemigroupAny.concat(true, false), true)
* assert.deepStrictEqual(SemigroupAny.concat(false, false), false)
*
* @category instances
* @since 2.10.0
*/
exports.SemigroupAny = {
concat: function (first, second) { return first || second; }
};
/**
* `boolean` monoid under conjunction.
*
* The `empty` value is `true`.
*
* @example
* import { MonoidAll } from 'fp-ts/boolean'
*
* assert.deepStrictEqual(MonoidAll.concat(true, true), true)
* assert.deepStrictEqual(MonoidAll.concat(true, false), false)
*
* @category instances
* @since 2.10.0
*/
exports.MonoidAll = {
concat: exports.SemigroupAll.concat,
empty: true
};
/**
* `boolean` monoid under disjunction.
*
* The `empty` value is `false`.
*
* @example
* import { MonoidAny } from 'fp-ts/boolean'
*
* assert.deepStrictEqual(MonoidAny.concat(true, true), true)
* assert.deepStrictEqual(MonoidAny.concat(true, false), true)
* assert.deepStrictEqual(MonoidAny.concat(false, false), false)
*
* @category instances
* @since 2.10.0
*/
exports.MonoidAny = {
concat: exports.SemigroupAny.concat,
empty: false
};
/**
* @category instances
* @since 2.10.0
*/
exports.Ord = {
equals: exports.Eq.equals,
compare: function (first, second) { return (first < second ? -1 : first > second ? 1 : 0); }
};
/**
* @category instances
* @since 2.10.0
*/
exports.Show = {
show: function (b) { return JSON.stringify(b); }
};