veffect
Version:
powerful TypeScript validation library built on the robust foundation of Effect combining exceptional type safety, high performance, and developer experience. Taking inspiration from Effect's functional principles, VEffect delivers a balanced approach tha
191 lines (186 loc) • 5.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.swap = exports.mapSecond = exports.mapFirst = exports.mapBoth = exports.make = exports.getSecond = exports.getOrder = exports.getFirst = exports.getEquivalence = exports.appendElement = void 0;
var Equivalence = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./Equivalence.js"));
var _Function = /*#__PURE__*/require("./Function.js");
var order = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./Order.js"));
function _getRequireWildcardCache(e) {
if ("function" != typeof WeakMap) return null;
var r = new WeakMap(),
t = new WeakMap();
return (_getRequireWildcardCache = function (e) {
return e ? t : r;
})(e);
}
function _interopRequireWildcard(e, r) {
if (!r && e && e.__esModule) return e;
if (null === e || "object" != typeof e && "function" != typeof e) return {
default: e
};
var t = _getRequireWildcardCache(r);
if (t && t.has(e)) return t.get(e);
var n = {
__proto__: null
},
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
}
return n.default = e, t && t.set(e, n), n;
}
/**
* This module provides utility functions for working with tuples in TypeScript.
*
* @since 2.0.0
*/
/**
* Constructs a new tuple from the provided values.
*
* @param elements - The list of elements to create the tuple from.
*
* @example
* import { make } from "effect/Tuple"
*
* assert.deepStrictEqual(make(1, 'hello', true), [1, 'hello', true])
*
* @category constructors
* @since 2.0.0
*/
const make = (...elements) => elements;
/**
* Return the first element of a tuple.
*
* @param self - A tuple of length `2`.
*
* @example
* import { getFirst } from "effect/Tuple"
*
* assert.deepStrictEqual(getFirst(["hello", 42]), "hello")
*
* @category getters
* @since 2.0.0
*/
exports.make = make;
const getFirst = self => self[0];
/**
* Return the second element of a tuple.
*
* @param self - A tuple of length `2`.
*
* @example
* import { getSecond } from "effect/Tuple"
*
* assert.deepStrictEqual(getSecond(["hello", 42]), 42)
*
* @category getters
* @since 2.0.0
*/
exports.getFirst = getFirst;
const getSecond = self => self[1];
/**
* Transforms both elements of a tuple using the given functions.
*
* @param self - A tuple of length `2`.
* @param f - The function to transform the first element of the tuple.
* @param g - The function to transform the second element of the tuple.
*
* @example
* import { mapBoth } from "effect/Tuple"
*
* assert.deepStrictEqual(
* mapBoth(["hello", 42], { onFirst: s => s.toUpperCase(), onSecond: n => n.toString() }),
* ["HELLO", "42"]
* )
*
* @category mapping
* @since 2.0.0
*/
exports.getSecond = getSecond;
const mapBoth = exports.mapBoth = /*#__PURE__*/(0, _Function.dual)(2, (self, {
onFirst,
onSecond
}) => [onFirst(self[0]), onSecond(self[1])]);
/**
* Transforms the first component of a tuple using a given function.
*
* @param self - A tuple of length `2`.
* @param f - The function to transform the first element of the tuple.
*
* @example
* import { mapFirst } from "effect/Tuple"
*
* assert.deepStrictEqual(
* mapFirst(["hello", 42], s => s.toUpperCase()),
* ["HELLO", 42]
* )
*
* @category mapping
* @since 2.0.0
*/
const mapFirst = exports.mapFirst = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => [f(self[0]), self[1]]);
/**
* Transforms the second component of a tuple using a given function.
*
* @param self - A tuple of length `2`.
* @param f - The function to transform the second element of the tuple.
*
* @example
* import { mapSecond } from "effect/Tuple"
*
* assert.deepStrictEqual(
* mapSecond(["hello", 42], n => n.toString()),
* ["hello", "42"]
* )
*
* @category mapping
* @since 2.0.0
*/
const mapSecond = exports.mapSecond = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => [self[0], f(self[1])]);
/**
* Swaps the two elements of a tuple.
*
* @param self - A tuple of length `2`.
*
* @example
* import { swap } from "effect/Tuple"
*
* assert.deepStrictEqual(swap(["hello", 42]), [42, "hello"])
*
* @since 2.0.0
*/
const swap = self => [self[1], self[0]];
/**
* Given a tuple of `Equivalence`s returns a new `Equivalence` that compares values of a tuple
* by applying each `Equivalence` to the corresponding element of the tuple.
*
* @category combinators
* @since 2.0.0
*/
exports.swap = swap;
const getEquivalence = exports.getEquivalence = Equivalence.tuple;
/**
* This function creates and returns a new `Order` for a tuple of values based on the given `Order`s for each element in the tuple.
* The returned `Order` compares two tuples of the same type by applying the corresponding `Order` to each element in the tuple.
* It is useful when you need to compare two tuples of the same type and you have a specific way of comparing each element
* of the tuple.
*
* @category combinators
* @since 2.0.0
*/
const getOrder = exports.getOrder = order.tuple;
/**
* Appends an element to the end of a tuple.
*
* @category concatenating
* @since 2.0.0
*/
const appendElement = exports.appendElement = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => [...self, that]);
/*
TODO:
- at
- swap
*/
//# sourceMappingURL=Tuple.js.map