effect
Version:
The missing standard library for TypeScript, for writing production-grade software.
84 lines (83 loc) • 3.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.union = exports.size = exports.min = exports.max = exports.make = exports.lessThan = exports.isNonEmpty = exports.isEmpty = exports.intersect = exports.empty = exports.before = exports.after = exports.IntervalTypeId = void 0;
var Duration = _interopRequireWildcard(require("../../Duration.js"));
var _Function = require("../../Function.js");
var Option = _interopRequireWildcard(require("../../Option.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; }
/** @internal */
const IntervalSymbolKey = "effect/ScheduleInterval";
/** @internal */
const IntervalTypeId = exports.IntervalTypeId = /*#__PURE__*/Symbol.for(IntervalSymbolKey);
/** @internal */
const empty = exports.empty = {
[IntervalTypeId]: IntervalTypeId,
startMillis: 0,
endMillis: 0
};
/** @internal */
const make = (startMillis, endMillis) => {
if (startMillis > endMillis) {
return empty;
}
return {
[IntervalTypeId]: IntervalTypeId,
startMillis,
endMillis
};
};
/** @internal */
exports.make = make;
const lessThan = exports.lessThan = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => min(self, that) === self);
/** @internal */
const min = exports.min = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => {
if (self.endMillis <= that.startMillis) return self;
if (that.endMillis <= self.startMillis) return that;
if (self.startMillis < that.startMillis) return self;
if (that.startMillis < self.startMillis) return that;
if (self.endMillis <= that.endMillis) return self;
return that;
});
/** @internal */
const max = exports.max = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => min(self, that) === self ? that : self);
/** @internal */
const isEmpty = self => {
return self.startMillis >= self.endMillis;
};
/** @internal */
exports.isEmpty = isEmpty;
const isNonEmpty = self => {
return !isEmpty(self);
};
/** @internal */
exports.isNonEmpty = isNonEmpty;
const intersect = exports.intersect = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => {
const start = Math.max(self.startMillis, that.startMillis);
const end = Math.min(self.endMillis, that.endMillis);
return make(start, end);
});
/** @internal */
const size = self => {
return Duration.millis(self.endMillis - self.startMillis);
};
/** @internal */
exports.size = size;
const union = exports.union = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => {
const start = Math.max(self.startMillis, that.startMillis);
const end = Math.min(self.endMillis, that.endMillis);
return start < end ? Option.none() : Option.some(make(start, end));
});
/** @internal */
const after = startMilliseconds => {
return make(startMilliseconds, Number.POSITIVE_INFINITY);
};
/** @internal */
exports.after = after;
const before = endMilliseconds => {
return make(Number.NEGATIVE_INFINITY, endMilliseconds);
};
exports.before = before;
//# sourceMappingURL=interval.js.map