"use strict";
/*!
  Copyright 2018 Ron Buckton (rbuckton@chronicles.org)

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
 */
/** @module "iterable-query/fn" */
Object.defineProperty(exports, "__esModule", { value: true });
require("../compat");
const lazy_1 = require("../lazy");
const equatable_1 = require("equatable");
/** A function that returns the provided value. */
function identity(value) {
    return value;
}
exports.identity = identity;
/** Creates a function that always returns the provided value. */
function thunk(value) {
    return () => value;
}
exports.thunk = thunk;
function property(key) {
    return (value) => value[key];
}
exports.property = property;
function noop() {
}
exports.noop = noop;
/** Creates a function that produces monotonically increasing number values. */
function incrementer(start = 0) {
    return () => start++;
}
exports.incrementer = incrementer;
/** Creates a function that produces monotonically decreasing number values. */
function decrementer(start = 0) {
    return () => start--;
}
exports.decrementer = decrementer;
/** Equate two values. */
function equate(x, y) {
    return equatable_1.Equaler.defaultEqualer.equals(x, y);
}
exports.equate = equate;
/** Compares two values. */
function compare(x, y) {
    return equatable_1.Comparer.defaultComparer.compare(x, y);
}
exports.compare = compare;
/** Compose one function with another (i.e. `compose(g, f)` is `x => g(f(x))`) */
function compose(g, f) {
    return x => g(f(x));
}
exports.compose = compose;
/** Create a lazy-initialized value. */
function lazy(factory, ...args) {
    return lazy_1.Lazy.from(factory, ...args);
}
exports.lazy = lazy;
/** Makes a tuple from the provided arguments */
function tuple(...args) {
    return args;
}
exports.tuple = tuple;
/** Always returns `true` */
function T() { return true; }
exports.T = T;
/** Always returns `false` */
function F() { return false; }
exports.F = F;
/** Various shorthand operator functions */
var Op;
(function (Op) {
    /** Add */
    function add(x, y) { return x + y; }
    Op.add = add;
    /** Subtract */
    function sub(x, y) { return x - y; }
    Op.sub = sub;
    /** Multiply */
    function mul(x, y) { return x * y; }
    Op.mul = mul;
    /** Exponentiate */
    function pow(x, y) { return x ** y; }
    Op.pow = pow;
    /** Divide */
    function div(x, y) { return x / y; }
    Op.div = div;
    /** Modulo */
    function mod(x, y) { return x % y; }
    Op.mod = mod;
    /** Left shift */
    function shl(x, n) { return x << n; }
    Op.shl = shl;
    /** Right shift */
    function shr(x, n) { return x >> n; }
    Op.shr = shr;
    /** Unsigned right shift */
    function sru(x, n) { return x >>> n; }
    Op.sru = sru;
    /** Negate */
    function neg(x) { return -x; }
    Op.neg = neg;
    /** Bitwise AND */
    function band(x, y) { return x & y; }
    Op.band = band;
    /** Bitwise OR */
    function bor(x, y) { return x | y; }
    Op.bor = bor;
    /** Bitwise XOR */
    function bxor(x, y) { return x ^ y; }
    Op.bxor = bxor;
    /** Bitwise NOT */
    function bnot(x) { return ~x; }
    Op.bnot = bnot;
    /** Logical AND */
    function and(x, y) { return x && y; }
    Op.and = and;
    /** Logical OR */
    function or(x, y) { return x || y; }
    Op.or = or;
    /** Logical XOR */
    function xor(x, y) { return !!(+x ^ +y); }
    Op.xor = xor;
    /** Logical NOT */
    function not(x) { return !x; }
    Op.not = not;
    /** Relational greater-than */
    function gt(x, y) { return compare(x, y) > 0; }
    Op.gt = gt;
    /** Relational greater-than-equals */
    function ge(x, y) { return compare(x, y) >= 0; }
    Op.ge = ge;
    /** Relational less-than */
    function lt(x, y) { return compare(x, y) < 0; }
    Op.lt = lt;
    /** Relational less-than-equals */
    function le(x, y) { return compare(x, y) <= 0; }
    Op.le = le;
    /** Relational equals */
    function eq(x, y) { return compare(x, y) === 0; }
    Op.eq = eq;
    /** Relational not-equals */
    function ne(x, y) { return compare(x, y) !== 0; }
    Op.ne = ne;
    /** Relational minimum */
    function min(x, y) { return compare(x, y) <= 0 ? x : y; }
    Op.min = min;
    /** Relational maximum */
    function max(x, y) { return compare(x, y) >= 0 ? x : y; }
    Op.max = max;
})(Op = exports.Op || (exports.Op = {}));
//# sourceMappingURL=common.js.map