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

163 lines
4.0 KiB
JavaScript
Raw Normal View History

// -------------------------------------------------------------------------------------
// refinements
// -------------------------------------------------------------------------------------
/**
* @category refinements
* @since 2.11.0
*/
export var isBoolean = function (u) { return typeof u === 'boolean'; };
/**
* 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
*/
export var matchW = function (onFalse, onTrue) {
return function (value) {
return value ? onTrue() : onFalse();
};
};
/**
* Alias of [`matchW`](#matchw).
*
* @category pattern matching
* @since 2.10.0
*/
export var foldW = 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
*/
export var match = foldW;
/**
* Alias of [`match`](#match).
*
* @category pattern matching
* @since 2.2.0
*/
export var fold = match;
// -------------------------------------------------------------------------------------
// instances
// -------------------------------------------------------------------------------------
/**
* @category instances
* @since 2.10.0
*/
export var Eq = {
equals: function (first, second) { return first === second; }
};
/**
* @category instances
* @since 2.10.0
*/
export var 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
*/
export var 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
*/
export var 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
*/
export var MonoidAll = {
concat: 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
*/
export var MonoidAny = {
concat: SemigroupAny.concat,
empty: false
};
/**
* @category instances
* @since 2.10.0
*/
export var Ord = {
equals: Eq.equals,
compare: function (first, second) { return (first < second ? -1 : first > second ? 1 : 0); }
};
/**
* @category instances
* @since 2.10.0
*/
export var Show = {
show: function (b) { return JSON.stringify(b); }
};