fable-core
Advanced tools
Comparing version 0.7.20 to 0.7.21
@@ -23,3 +23,2 @@ export function addRangeInPlace(range, xs) { | ||
export function permute(f, xs) { | ||
// Keep the type of the array | ||
var ys = xs.map(function () { return null; }); | ||
@@ -26,0 +25,0 @@ var checkFlags = new Array(xs.length); |
@@ -8,3 +8,2 @@ import { Trampoline } from "./AsyncBuilder"; | ||
import { map } from "./Seq"; | ||
// Implemented just for type references | ||
var Async = (function () { | ||
@@ -17,3 +16,2 @@ function Async() { | ||
function emptyContinuation(x) { | ||
// NOP | ||
} | ||
@@ -20,0 +18,0 @@ export function awaitPromise(p) { |
58
Date.js
@@ -12,6 +12,6 @@ import { create as timeSpanCreate } from "./TimeSpan"; | ||
if (kind == null) { | ||
kind = typeof v == "string" && v.slice(-1) == "Z" ? 1 /* UTC */ : 2 /* Local */; | ||
kind = typeof v == "string" && v.slice(-1) == "Z" ? 1 : 2; | ||
} | ||
var date = (v == null) ? new Date() : new Date(v); | ||
if (kind === 2 /* Local */) { | ||
if (kind === 2) { | ||
date.kind = kind; | ||
@@ -37,5 +37,5 @@ } | ||
if (ms === void 0) { ms = 0; } | ||
if (kind === void 0) { kind = 2 /* Local */; } | ||
if (kind === void 0) { kind = 2; } | ||
var date; | ||
if (kind === 2 /* Local */) { | ||
if (kind === 2) { | ||
date = new Date(year, month - 1, day, h, m, s, ms); | ||
@@ -70,6 +70,6 @@ date.kind = kind; | ||
export function toUniversalTime(d) { | ||
return d.kind === 2 /* Local */ ? new Date(d.getTime()) : d; | ||
return d.kind === 2 ? new Date(d.getTime()) : d; | ||
} | ||
export function toLocalTime(d) { | ||
if (d.kind === 2 /* Local */) { | ||
if (d.kind === 2) { | ||
return d; | ||
@@ -79,3 +79,3 @@ } | ||
var d2 = new Date(d.getTime()); | ||
d2.kind = 2 /* Local */; | ||
d2.kind = 2; | ||
return d2; | ||
@@ -88,35 +88,35 @@ } | ||
export function date(d) { | ||
return create(year(d), month(d), day(d), 0, 0, 0, 0, d.kind || 1 /* UTC */); | ||
return create(year(d), month(d), day(d), 0, 0, 0, 0, d.kind || 1); | ||
} | ||
export function kind(d) { | ||
return d.kind || 1 /* UTC */; | ||
return d.kind || 1; | ||
} | ||
export function day(d) { | ||
return d.kind === 2 /* Local */ ? d.getDate() : d.getUTCDate(); | ||
return d.kind === 2 ? d.getDate() : d.getUTCDate(); | ||
} | ||
export function hour(d) { | ||
return d.kind === 2 /* Local */ ? d.getHours() : d.getUTCHours(); | ||
return d.kind === 2 ? d.getHours() : d.getUTCHours(); | ||
} | ||
export function millisecond(d) { | ||
return d.kind === 2 /* Local */ ? d.getMilliseconds() : d.getUTCMilliseconds(); | ||
return d.kind === 2 ? d.getMilliseconds() : d.getUTCMilliseconds(); | ||
} | ||
export function minute(d) { | ||
return d.kind === 2 /* Local */ ? d.getMinutes() : d.getUTCMinutes(); | ||
return d.kind === 2 ? d.getMinutes() : d.getUTCMinutes(); | ||
} | ||
export function month(d) { | ||
return (d.kind === 2 /* Local */ ? d.getMonth() : d.getUTCMonth()) + 1; | ||
return (d.kind === 2 ? d.getMonth() : d.getUTCMonth()) + 1; | ||
} | ||
export function second(d) { | ||
return d.kind === 2 /* Local */ ? d.getSeconds() : d.getUTCSeconds(); | ||
return d.kind === 2 ? d.getSeconds() : d.getUTCSeconds(); | ||
} | ||
export function year(d) { | ||
return d.kind === 2 /* Local */ ? d.getFullYear() : d.getUTCFullYear(); | ||
return d.kind === 2 ? d.getFullYear() : d.getUTCFullYear(); | ||
} | ||
export function dayOfWeek(d) { | ||
return d.kind === 2 /* Local */ ? d.getDay() : d.getUTCDay(); | ||
return d.kind === 2 ? d.getDay() : d.getUTCDay(); | ||
} | ||
export function ticks(d) { | ||
return Long.fromNumber(d.getTime()) | ||
.add(62135596800000) // UnixEpochMilliseconds | ||
.sub(d.kind == 2 /* Local */ ? d.getTimezoneOffset() * 60 * 1000 : 0) | ||
.add(62135596800000) | ||
.sub(d.kind == 2 ? d.getTimezoneOffset() * 60 * 1000 : 0) | ||
.mul(10000); | ||
@@ -136,21 +136,21 @@ } | ||
export function add(d, ts) { | ||
return parse(d.getTime() + ts, d.kind || 1 /* UTC */); | ||
return parse(d.getTime() + ts, d.kind || 1); | ||
} | ||
export function addDays(d, v) { | ||
return parse(d.getTime() + v * 86400000, d.kind || 1 /* UTC */); | ||
return parse(d.getTime() + v * 86400000, d.kind || 1); | ||
} | ||
export function addHours(d, v) { | ||
return parse(d.getTime() + v * 3600000, d.kind || 1 /* UTC */); | ||
return parse(d.getTime() + v * 3600000, d.kind || 1); | ||
} | ||
export function addMinutes(d, v) { | ||
return parse(d.getTime() + v * 60000, d.kind || 1 /* UTC */); | ||
return parse(d.getTime() + v * 60000, d.kind || 1); | ||
} | ||
export function addSeconds(d, v) { | ||
return parse(d.getTime() + v * 1000, d.kind || 1 /* UTC */); | ||
return parse(d.getTime() + v * 1000, d.kind || 1); | ||
} | ||
export function addMilliseconds(d, v) { | ||
return parse(d.getTime() + v, d.kind || 1 /* UTC */); | ||
return parse(d.getTime() + v, d.kind || 1); | ||
} | ||
export function addTicks(d, t) { | ||
return parse(Long.fromNumber(d.getTime()).add(t.div(10000)).toNumber(), d.kind || 1 /* UTC */); | ||
return parse(Long.fromNumber(d.getTime()).add(t.div(10000)).toNumber(), d.kind || 1); | ||
} | ||
@@ -162,3 +162,3 @@ export function addYears(d, v) { | ||
var newDay = Math.min(_daysInMonth, day(d)); | ||
return create(newYear, newMonth, newDay, hour(d), minute(d), second(d), millisecond(d), d.kind || 1 /* UTC */); | ||
return create(newYear, newMonth, newDay, hour(d), minute(d), second(d), millisecond(d), d.kind || 1); | ||
} | ||
@@ -182,7 +182,7 @@ export function addMonths(d, v) { | ||
var newDay = Math.min(_daysInMonth, day(d)); | ||
return create(newYear, newMonth, newDay, hour(d), minute(d), second(d), millisecond(d), d.kind || 1 /* UTC */); | ||
return create(newYear, newMonth, newDay, hour(d), minute(d), second(d), millisecond(d), d.kind || 1); | ||
} | ||
export function subtract(d, that) { | ||
return typeof that == "number" | ||
? parse(d.getTime() - that, d.kind || 1 /* UTC */) | ||
? parse(d.getTime() - that, d.kind || 1) | ||
: d.getTime() - that.getTime(); | ||
@@ -189,0 +189,0 @@ } |
@@ -14,3 +14,2 @@ import { createDisposable } from "./Util"; | ||
Object.defineProperty(Event.prototype, "Publish", { | ||
// IEvent<T> methods | ||
get: function () { | ||
@@ -25,3 +24,2 @@ return this; | ||
}; | ||
// IDelegateEvent<T> methods | ||
Event.prototype._addHandler = function (f) { | ||
@@ -52,3 +50,2 @@ this.delegates.push(f); | ||
}; | ||
// IObservable<T> methods | ||
Event.prototype._subscribeFromObserver = function (observer) { | ||
@@ -55,0 +52,0 @@ var _this = this; |
@@ -22,3 +22,2 @@ import List from "./ListClass"; | ||
} | ||
// TODO: should be xs: Iterable<List<T>> | ||
export function concat(xs) { | ||
@@ -69,3 +68,2 @@ return collect(function (x) { return x; }, xs); | ||
} | ||
/* ToDo: instance unzip() */ | ||
export function unzip(xs) { | ||
@@ -76,3 +74,2 @@ return seqFoldBack(function (xy, acc) { | ||
} | ||
/* ToDo: instance unzip3() */ | ||
export function unzip3(xs) { | ||
@@ -79,0 +76,0 @@ return seqFoldBack(function (xyz, acc) { |
@@ -5,3 +5,2 @@ import FSymbol from "./Symbol"; | ||
import { compare } from "./Util"; | ||
// This module is split from List.ts to prevent cyclic dependencies | ||
export function ofArray(args, base) { | ||
@@ -23,3 +22,2 @@ var acc = base || new List(); | ||
List.prototype.Equals = function (x) { | ||
// Optimization if they are referencially equal | ||
if (this === x) { | ||
@@ -42,3 +40,2 @@ return true; | ||
List.prototype.CompareTo = function (x) { | ||
// Optimization if they are referencially equal | ||
if (this === x) { | ||
@@ -86,32 +83,2 @@ return 0; | ||
}; | ||
// append(ys: List<T>): List<T> { | ||
// return append(this, ys); | ||
// } | ||
// choose<U>(f: (x: T) => U, xs: List<T>): List<U> { | ||
// return choose(f, this); | ||
// } | ||
// collect<U>(f: (x: T) => List<U>): List<U> { | ||
// return collect(f, this); | ||
// } | ||
// filter(f: (x: T) => boolean): List<T> { | ||
// return filter(f, this); | ||
// } | ||
// where(f: (x: T) => boolean): List<T> { | ||
// return filter(f, this); | ||
// } | ||
// map<U>(f: (x: T) => U): List<U> { | ||
// return map(f, this); | ||
// } | ||
// mapIndexed<U>(f: (i: number, x: T) => U): List<U> { | ||
// return mapIndexed(f, this); | ||
// } | ||
// partition(f: (x: T) => boolean): [List<T>, List<T>] { | ||
// return partition(f, this) as [List<T>, List<T>]; | ||
// } | ||
// reverse(): List<T> { | ||
// return reverse(this); | ||
// } | ||
// slice(lower: number, upper: number): List<T> { | ||
// return slice(lower, upper, this); | ||
// } | ||
List.prototype[FSymbol.reflection] = function () { | ||
@@ -118,0 +85,0 @@ return { |
418
Long.js
@@ -1,128 +0,22 @@ | ||
// Source: https://github.com/dcodeIO/long.js/blob/master/LICENSE | ||
// The internal representation of a long is the two given signed, 32-bit values. | ||
// We use 32-bit pieces because these are the size of integers on which | ||
// Javascript performs bit-operations. For operations like addition and | ||
// multiplication, we split each number into 16 bit pieces, which can easily be | ||
// multiplied within Javascript's floating-point representation without overflow | ||
// or change in sign. | ||
// | ||
// In the algorithms below, we frequently reduce the negative case to the | ||
// positive case by negating the input(s) and then post-processing the result. | ||
// Note that we must ALWAYS check specially whether those values are MIN_VALUE | ||
// (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as | ||
// a positive number, it overflows back into a negative). Not handling this | ||
// case would often result in infinite recursion. | ||
// | ||
// Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from* | ||
// methods on which they depend. | ||
/** | ||
* @class A Long class for representing a 64 bit two's-complement integer value. | ||
*/ | ||
var Long = (function () { | ||
/** | ||
* Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers. | ||
* See the from* functions below for more convenient ways of constructing Longs. | ||
* @param {number} low The low (signed) 32 bits of the long | ||
* @param {number} high The high (signed) 32 bits of the long | ||
* @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed | ||
*/ | ||
function Long(low, high, unsigned) { | ||
/** | ||
* Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
this.eq = this.equals; | ||
/** | ||
* Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
this.neq = this.notEquals; | ||
/** | ||
* Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
this.lt = this.lessThan; | ||
/** | ||
* Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
this.lte = this.lessThanOrEqual; | ||
/** | ||
* Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
this.gt = this.greaterThan; | ||
/** | ||
* Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
this.gte = this.greaterThanOrEqual; | ||
/** | ||
* Compares this Long's value with the specified's. This is an alias of {@link Long#compare}. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {number} 0 if they are the same, 1 if the this is greater and -1 | ||
* if the given one is greater | ||
*/ | ||
this.comp = this.compare; | ||
/** | ||
* Negates this Long's value. This is an alias of {@link Long#negate}. | ||
* @returns {!Long} Negated Long | ||
*/ | ||
this.neg = this.negate; | ||
/** | ||
* Returns this Long's absolute value. This is an alias of {@link Long#absolute}. | ||
* @returns {!Long} Absolute Long | ||
*/ | ||
this.abs = this.absolute; | ||
/** | ||
* Returns the difference of this and the specified This is an alias of {@link Long#subtract}. | ||
* @param {!Long|number|string} subtrahend Subtrahend | ||
* @returns {!Long} Difference | ||
*/ | ||
this.sub = this.subtract; | ||
/** | ||
* Returns the product of this and the specified This is an alias of {@link Long#multiply}. | ||
* @param {!Long|number|string} multiplier Multiplier | ||
* @returns {!Long} Product | ||
*/ | ||
this.mul = this.multiply; | ||
/** | ||
* Returns this Long divided by the specified. This is an alias of {@link Long#divide}. | ||
* @param {!Long|number|string} divisor Divisor | ||
* @returns {!Long} Quotient | ||
*/ | ||
this.div = this.divide; | ||
/** | ||
* Returns this Long modulo the specified. This is an alias of {@link Long#modulo}. | ||
* @param {!Long|number|string} divisor Divisor | ||
* @returns {!Long} Remainder | ||
*/ | ||
this.mod = this.modulo; | ||
/** | ||
* Returns this Long with bits shifted to the left by the given amount. This is an alias of {@link Long#shiftLeft}. | ||
* @param {number|!Long} numBits Number of bits | ||
* @returns {!Long} Shifted Long | ||
*/ | ||
this.shl = this.shiftLeft; | ||
/** | ||
* Returns this Long with bits arithmetically shifted to the right by the given amount. This is an alias of {@link Long#shiftRight}. | ||
* @param {number|!Long} numBits Number of bits | ||
* @returns {!Long} Shifted Long | ||
*/ | ||
this.shr = this.shiftRight; | ||
/** | ||
* Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}. | ||
* @param {number|!Long} numBits Number of bits | ||
* @returns {!Long} Shifted Long | ||
*/ | ||
this.shru = this.shiftRightUnsigned; | ||
// Aliases for compatibility with Fable | ||
this.Equals = this.equals; | ||
this.CompareTo = this.compare; | ||
this.ToString = this.toString; | ||
this.low = low | 0; | ||
@@ -132,13 +26,5 @@ this.high = high | 0; | ||
} | ||
/** | ||
* Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. | ||
* @returns {number} | ||
*/ | ||
Long.prototype.toInt = function () { | ||
return this.unsigned ? this.low >>> 0 : this.low; | ||
}; | ||
/** | ||
* Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). | ||
* @returns {number} | ||
*/ | ||
Long.prototype.toNumber = function () { | ||
@@ -149,9 +35,2 @@ if (this.unsigned) | ||
}; | ||
/** | ||
* Converts the Long to a string written in the specified radix. | ||
* @param {number=} radix Radix (2-36), defaults to 10 | ||
* @returns {string} | ||
* @override | ||
* @throws {RangeError} If `radix` is out of range | ||
*/ | ||
Long.prototype.toString = function (radix) { | ||
@@ -166,4 +45,2 @@ if (radix === void 0) { radix = 10; } | ||
if (this.eq(MIN_VALUE)) { | ||
// We need to change the Long value before it can be negated, so we remove | ||
// the bottom-most digit in this base and then recurse to do the rest. | ||
var radixLong = fromNumber(radix), div = this.div(radixLong), rem1 = div.mul(radixLong).sub(this); | ||
@@ -175,4 +52,2 @@ return div.toString(radix) + rem1.toInt().toString(radix); | ||
} | ||
// Do several (6) digits each time through the loop, so as to | ||
// minimize the calls to the very expensive emulated div. | ||
var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned), rem = this; | ||
@@ -192,34 +67,14 @@ var result = ''; | ||
}; | ||
/** | ||
* Gets the high 32 bits as a signed integer. | ||
* @returns {number} Signed high bits | ||
*/ | ||
Long.prototype.getHighBits = function () { | ||
return this.high; | ||
}; | ||
/** | ||
* Gets the high 32 bits as an unsigned integer. | ||
* @returns {number} Unsigned high bits | ||
*/ | ||
Long.prototype.getHighBitsUnsigned = function () { | ||
return this.high >>> 0; | ||
}; | ||
/** | ||
* Gets the low 32 bits as a signed integer. | ||
* @returns {number} Signed low bits | ||
*/ | ||
Long.prototype.getLowBits = function () { | ||
return this.low; | ||
}; | ||
/** | ||
* Gets the low 32 bits as an unsigned integer. | ||
* @returns {number} Unsigned low bits | ||
*/ | ||
Long.prototype.getLowBitsUnsigned = function () { | ||
return this.low >>> 0; | ||
}; | ||
/** | ||
* Gets the number of bits needed to represent the absolute value of this | ||
* @returns {number} | ||
*/ | ||
Long.prototype.getNumBitsAbs = function () { | ||
@@ -234,42 +89,17 @@ if (this.isNegative()) | ||
}; | ||
/** | ||
* Tests if this Long's value equals zero. | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.isZero = function () { | ||
return this.high === 0 && this.low === 0; | ||
}; | ||
/** | ||
* Tests if this Long's value is negative. | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.isNegative = function () { | ||
return !this.unsigned && this.high < 0; | ||
}; | ||
/** | ||
* Tests if this Long's value is positive. | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.isPositive = function () { | ||
return this.unsigned || this.high >= 0; | ||
}; | ||
/** | ||
* Tests if this Long's value is odd. | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.isOdd = function () { | ||
return (this.low & 1) === 1; | ||
}; | ||
/** | ||
* Tests if this Long's value is even. | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.isEven = function () { | ||
return (this.low & 1) === 0; | ||
}; | ||
/** | ||
* Tests if this Long's value equals the specified's. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.equals = function (other) { | ||
@@ -282,48 +112,17 @@ if (!isLong(other)) | ||
}; | ||
/** | ||
* Tests if this Long's value differs from the specified's. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.notEquals = function (other) { | ||
return !this.eq(/* validates */ other); | ||
return !this.eq(other); | ||
}; | ||
/** | ||
* Tests if this Long's value is less than the specified's. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.lessThan = function (other) { | ||
return this.comp(/* validates */ other) < 0; | ||
return this.comp(other) < 0; | ||
}; | ||
/** | ||
* Tests if this Long's value is less than or equal the specified's. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.lessThanOrEqual = function (other) { | ||
return this.comp(/* validates */ other) <= 0; | ||
return this.comp(other) <= 0; | ||
}; | ||
/** | ||
* Tests if this Long's value is greater than the specified's. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.greaterThan = function (other) { | ||
return this.comp(/* validates */ other) > 0; | ||
return this.comp(other) > 0; | ||
}; | ||
/** | ||
* Tests if this Long's value is greater than or equal the specified's. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.greaterThanOrEqual = function (other) { | ||
return this.comp(/* validates */ other) >= 0; | ||
return this.comp(other) >= 0; | ||
}; | ||
/** | ||
* Compares this Long's value with the specified's. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {number} 0 if they are the same, 1 if the this is greater and -1 | ||
* if the given one is greater | ||
*/ | ||
Long.prototype.compare = function (other) { | ||
@@ -339,12 +138,6 @@ if (!isLong(other)) | ||
return 1; | ||
// At this point the sign bits are the same | ||
if (!this.unsigned) | ||
return this.sub(other).isNegative() ? -1 : 1; | ||
// Both are positive if at least one is unsigned | ||
return (other.high >>> 0) > (this.high >>> 0) || (other.high === this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1; | ||
}; | ||
/** | ||
* Negates this Long's value. | ||
* @returns {!Long} Negated Long | ||
*/ | ||
Long.prototype.negate = function () { | ||
@@ -355,6 +148,2 @@ if (!this.unsigned && this.eq(MIN_VALUE)) | ||
}; | ||
/** | ||
* Returns this Long's absolute value. | ||
* @returns {!Long} Absolute Long | ||
*/ | ||
Long.prototype.absolute = function () { | ||
@@ -366,11 +155,5 @@ if (!this.unsigned && this.isNegative()) | ||
}; | ||
/** | ||
* Returns the sum of this and the specified | ||
* @param {!Long|number|string} addend Addend | ||
* @returns {!Long} Sum | ||
*/ | ||
Long.prototype.add = function (addend) { | ||
if (!isLong(addend)) | ||
addend = fromValue(addend); | ||
// Divide each number into 4 chunks of 16 bits, and then sum the chunks. | ||
var a48 = this.high >>> 16; | ||
@@ -398,7 +181,2 @@ var a32 = this.high & 0xFFFF; | ||
}; | ||
/** | ||
* Returns the difference of this and the specified | ||
* @param {!Long|number|string} subtrahend Subtrahend | ||
* @returns {!Long} Difference | ||
*/ | ||
Long.prototype.subtract = function (subtrahend) { | ||
@@ -409,7 +187,2 @@ if (!isLong(subtrahend)) | ||
}; | ||
/** | ||
* Returns the product of this and the specified | ||
* @param {!Long|number|string} multiplier Multiplier | ||
* @returns {!Long} Product | ||
*/ | ||
Long.prototype.multiply = function (multiplier) { | ||
@@ -434,7 +207,4 @@ if (this.isZero()) | ||
return this.mul(multiplier.neg()).neg(); | ||
// If both longs are small, use float multiplication | ||
if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24)) | ||
return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned); | ||
// Divide each long into 4 chunks of 16 bits, and then add up 4x4 products. | ||
// We can skip products that would overflow. | ||
var a48 = this.high >>> 16; | ||
@@ -471,8 +241,2 @@ var a32 = this.high & 0xFFFF; | ||
}; | ||
/** | ||
* Returns this Long divided by the specified. The result is signed if this Long is signed or | ||
* unsigned if this Long is unsigned. | ||
* @param {!Long|number|string} divisor Divisor | ||
* @returns {!Long} Quotient | ||
*/ | ||
Long.prototype.divide = function (divisor) { | ||
@@ -487,11 +251,8 @@ if (!isLong(divisor)) | ||
if (!this.unsigned) { | ||
// This section is only relevant for signed longs and is derived from the | ||
// closure library as a whole. | ||
if (this.eq(MIN_VALUE)) { | ||
if (divisor.eq(ONE) || divisor.eq(NEG_ONE)) | ||
return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE | ||
return MIN_VALUE; | ||
else if (divisor.eq(MIN_VALUE)) | ||
return ONE; | ||
else { | ||
// At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|. | ||
var halfThis = this.shr(1); | ||
@@ -521,4 +282,2 @@ var approx_1 = halfThis.div(divisor).shl(1); | ||
else { | ||
// The algorithm below has not been made for unsigned longs. It's therefore | ||
// required to take special care of the MSB prior to running it. | ||
if (!divisor.unsigned) | ||
@@ -532,18 +291,6 @@ divisor = divisor.toUnsigned(); | ||
} | ||
// Repeat the following until the remainder is less than other: find a | ||
// floating-point that approximates remainder / other *from below*, add this | ||
// into the result, and subtract it from the remainder. It is critical that | ||
// the approximate value is less than or equal to the real value so that the | ||
// remainder never becomes negative. | ||
rem = this; | ||
while (rem.gte(divisor)) { | ||
// Approximate the result of division. This may be a little greater or | ||
// smaller than the actual value. | ||
approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber())); | ||
// We will tweak the approximate result by changing it in the 48-th digit or | ||
// the smallest non-fractional digit, whichever is larger. | ||
var log2 = Math.ceil(Math.log(approx) / Math.LN2), delta = (log2 <= 48) ? 1 : pow_dbl(2, log2 - 48), | ||
// Decrease the approximation until it is smaller than the remainder. Note | ||
// that if it is too large, the product overflows and is negative. | ||
approxRes = fromNumber(approx), approxRem = approxRes.mul(divisor); | ||
var log2 = Math.ceil(Math.log(approx) / Math.LN2), delta = (log2 <= 48) ? 1 : pow_dbl(2, log2 - 48), approxRes = fromNumber(approx), approxRem = approxRes.mul(divisor); | ||
while (approxRem.isNegative() || approxRem.gt(rem)) { | ||
@@ -554,4 +301,2 @@ approx -= delta; | ||
} | ||
// We know the answer can't be zero... and actually, zero would cause | ||
// infinite recursion since we would make no progress. | ||
if (approxRes.isZero()) | ||
@@ -564,7 +309,2 @@ approxRes = ONE; | ||
}; | ||
/** | ||
* Returns this Long modulo the specified. | ||
* @param {!Long|number|string} divisor Divisor | ||
* @returns {!Long} Remainder | ||
*/ | ||
Long.prototype.modulo = function (divisor) { | ||
@@ -576,6 +316,2 @@ if (!isLong(divisor)) | ||
; | ||
/** | ||
* Returns the bitwise NOT of this | ||
* @returns {!Long} | ||
*/ | ||
Long.prototype.not = function () { | ||
@@ -585,7 +321,2 @@ return fromBits(~this.low, ~this.high, this.unsigned); | ||
; | ||
/** | ||
* Returns the bitwise AND of this Long and the specified. | ||
* @param {!Long|number|string} other Other Long | ||
* @returns {!Long} | ||
*/ | ||
Long.prototype.and = function (other) { | ||
@@ -596,7 +327,2 @@ if (!isLong(other)) | ||
}; | ||
/** | ||
* Returns the bitwise OR of this Long and the specified. | ||
* @param {!Long|number|string} other Other Long | ||
* @returns {!Long} | ||
*/ | ||
Long.prototype.or = function (other) { | ||
@@ -607,7 +333,2 @@ if (!isLong(other)) | ||
}; | ||
/** | ||
* Returns the bitwise XOR of this Long and the given one. | ||
* @param {!Long|number|string} other Other Long | ||
* @returns {!Long} | ||
*/ | ||
Long.prototype.xor = function (other) { | ||
@@ -618,7 +339,2 @@ if (!isLong(other)) | ||
}; | ||
/** | ||
* Returns this Long with bits shifted to the left by the given amount. | ||
* @param {number|!Long} numBits Number of bits | ||
* @returns {!Long} Shifted Long | ||
*/ | ||
Long.prototype.shiftLeft = function (numBits) { | ||
@@ -635,7 +351,2 @@ if (isLong(numBits)) | ||
}; | ||
/** | ||
* Returns this Long with bits arithmetically shifted to the right by the given amount. | ||
* @param {number|!Long} numBits Number of bits | ||
* @returns {!Long} Shifted Long | ||
*/ | ||
Long.prototype.shiftRight = function (numBits) { | ||
@@ -652,7 +363,2 @@ if (isLong(numBits)) | ||
}; | ||
/** | ||
* Returns this Long with bits logically shifted to the right by the given amount. | ||
* @param {number|!Long} numBits Number of bits | ||
* @returns {!Long} Shifted Long | ||
*/ | ||
Long.prototype.shiftRightUnsigned = function (numBits) { | ||
@@ -676,6 +382,2 @@ if (isLong(numBits)) | ||
}; | ||
/** | ||
* Converts this Long to signed. | ||
* @returns {!Long} Signed long | ||
*/ | ||
Long.prototype.toSigned = function () { | ||
@@ -686,6 +388,2 @@ if (!this.unsigned) | ||
}; | ||
/** | ||
* Converts this Long to unsigned. | ||
* @returns {!Long} Unsigned long | ||
*/ | ||
Long.prototype.toUnsigned = function () { | ||
@@ -696,14 +394,5 @@ if (this.unsigned) | ||
}; | ||
/** | ||
* Converts this Long to its byte representation. | ||
* @param {boolean=} le Whether little or big endian, defaults to big endian | ||
* @returns {!Array.<number>} Byte representation | ||
*/ | ||
Long.prototype.toBytes = function (le) { | ||
return le ? this.toBytesLE() : this.toBytesBE(); | ||
}; | ||
/** | ||
* Converts this Long to its little endian byte representation. | ||
* @returns {!Array.<number>} Little endian byte representation | ||
*/ | ||
Long.prototype.toBytesLE = function () { | ||
@@ -722,6 +411,2 @@ var hi = this.high, lo = this.low; | ||
}; | ||
/** | ||
* Converts this Long to its big endian byte representation. | ||
* @returns {!Array.<number>} Big endian byte representation | ||
*/ | ||
Long.prototype.toBytesBE = function () { | ||
@@ -743,20 +428,7 @@ var hi = this.high, lo = this.low; | ||
export { Long }; | ||
// A cache of the Long representations of small integer values. | ||
var INT_CACHE = {}; | ||
// A cache of the Long representations of small unsigned integer values. | ||
var UINT_CACHE = {}; | ||
/** | ||
* Tests if the specified object is a | ||
* @param {*} obj Object | ||
* @returns {boolean} | ||
*/ | ||
export function isLong(obj) { | ||
return (obj && obj instanceof Long); | ||
} | ||
/** | ||
* Returns a Long representing the given 32 bit integer value. | ||
* @param {number} value The 32 bit integer in question | ||
* @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed | ||
* @returns {!Long} The corresponding Long value | ||
*/ | ||
export function fromInt(value, unsigned) { | ||
@@ -790,8 +462,2 @@ if (unsigned === void 0) { unsigned = false; } | ||
} | ||
/** | ||
* Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned. | ||
* @param {number} value The number in question | ||
* @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed | ||
* @returns {!Long} The corresponding Long value | ||
*/ | ||
export function fromNumber(value, unsigned) { | ||
@@ -817,27 +483,6 @@ if (unsigned === void 0) { unsigned = false; } | ||
} | ||
/** | ||
* Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is | ||
* assumed to use 32 bits. | ||
* @param {number} lowBits The low 32 bits | ||
* @param {number} highBits The high 32 bits | ||
* @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed | ||
* @returns {!Long} The corresponding Long value | ||
*/ | ||
export function fromBits(lowBits, highBits, unsigned) { | ||
return new Long(lowBits, highBits, unsigned); | ||
} | ||
/** | ||
* @param {number} base | ||
* @param {number} exponent | ||
* @returns {number} | ||
*/ | ||
var pow_dbl = Math.pow; // Used 4 times (4*8 to 15+4) | ||
/** | ||
* Returns a Long representation of the given string, written using the specified radix. | ||
* @param {string} str The textual representation of the Long | ||
* @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to `false` for signed | ||
* @param {number=} radix The radix in which the text is written (2-36), defaults to 10 | ||
* @returns {!Long} The corresponding Long value | ||
*/ | ||
// Used 4 times (4*8 to 15+4) | ||
var pow_dbl = Math.pow; | ||
export function fromString(str, unsigned, radix) { | ||
@@ -851,3 +496,2 @@ if (unsigned === void 0) { unsigned = false; } | ||
if (typeof unsigned === 'number') { | ||
// For goog.math.long compatibility | ||
radix = unsigned, | ||
@@ -868,4 +512,2 @@ unsigned = false; | ||
} | ||
// Do several (8) digits each time through the loop, so as to | ||
// minimize the calls to the very expensive emulated div. | ||
var radixToPower = fromNumber(pow_dbl(radix, 8)); | ||
@@ -887,9 +529,4 @@ var result = ZERO; | ||
} | ||
/** | ||
* Converts the specified value to a | ||
* @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value | ||
* @returns {!Long} | ||
*/ | ||
export function fromValue(val) { | ||
if (val /* is compatible */ instanceof Long) | ||
if (val instanceof Long) | ||
return val; | ||
@@ -900,7 +537,4 @@ if (typeof val === 'number') | ||
return fromString(val); | ||
// Throws for non-objects, converts non-instanceof Long: | ||
return fromBits(val.low, val.high, val.unsigned); | ||
} | ||
// NOTE: the compiler should inline these constant values below and then remove these variables, so there should be | ||
// no runtime penalty for these. | ||
var TWO_PWR_16_DBL = 1 << 16; | ||
@@ -912,41 +546,9 @@ var TWO_PWR_24_DBL = 1 << 24; | ||
var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL); | ||
/** | ||
* Signed zero. | ||
* @type {!Long} | ||
*/ | ||
export var ZERO = fromInt(0); | ||
/** | ||
* Unsigned zero. | ||
* @type {!Long} | ||
*/ | ||
export var UZERO = fromInt(0, true); | ||
/** | ||
* Signed one. | ||
* @type {!Long} | ||
*/ | ||
export var ONE = fromInt(1); | ||
/** | ||
* Unsigned one. | ||
* @type {!Long} | ||
*/ | ||
export var UONE = fromInt(1, true); | ||
/** | ||
* Signed negative one. | ||
* @type {!Long} | ||
*/ | ||
export var NEG_ONE = fromInt(-1); | ||
/** | ||
* Maximum signed value. | ||
* @type {!Long} | ||
*/ | ||
export var MAX_VALUE = fromBits(0xFFFFFFFF | 0, 0x7FFFFFFF | 0, false); | ||
/** | ||
* Maximum unsigned value. | ||
* @type {!Long} | ||
*/ | ||
export var MAX_UNSIGNED_VALUE = fromBits(0xFFFFFFFF | 0, 0xFFFFFFFF | 0, true); | ||
/** | ||
* Minimum signed value. | ||
* @type {!Long} | ||
*/ | ||
export var MIN_VALUE = fromBits(0, 0x80000000 | 0, false); |
146
Map.js
@@ -13,5 +13,2 @@ import List from "./ListClass"; | ||
import { compareWith as seqCompareWith } from "./Seq"; | ||
// ---------------------------------------------- | ||
// These functions belong to Seq.ts but are | ||
// implemented here to prevent cyclic dependencies | ||
export function groupBy(f, xs) { | ||
@@ -201,7 +198,3 @@ var keys = [], iter = xs[Symbol.iterator](); | ||
function tree_filterAux(comparer, f, s, acc) { | ||
return s.Case === "MapOne" ? tree_filter1(comparer, f, s.Fields[0], s.Fields[1], acc) : s.Case === "MapNode" ? (function () { | ||
var acc_1 = tree_filterAux(comparer, f, s.Fields[2], acc); | ||
var acc_2 = tree_filter1(comparer, f, s.Fields[0], s.Fields[1], acc_1); | ||
return tree_filterAux(comparer, f, s.Fields[3], acc_2); | ||
})() : acc; | ||
return s.Case === "MapOne" ? tree_filter1(comparer, f, s.Fields[0], s.Fields[1], acc) : s.Case === "MapNode" ? tree_filterAux(comparer, f, s.Fields[3], tree_filter1(comparer, f, s.Fields[0], s.Fields[1], tree_filterAux(comparer, f, s.Fields[2], acc))) : acc; | ||
} | ||
@@ -270,3 +263,6 @@ function tree_filter(comparer, f, s) { | ||
function tree_mem(comparer, k, m) { | ||
return m.Case === "MapOne" ? comparer.Compare(k, m.Fields[0]) === 0 : m.Case === "MapNode" ? (function () { | ||
if (m.Case === "MapOne") { | ||
return comparer.Compare(k, m.Fields[0]) === 0; | ||
} | ||
else if (m.Case === "MapNode") { | ||
var c = comparer.Compare(k, m.Fields[0]); | ||
@@ -284,3 +280,6 @@ if (c < 0) { | ||
} | ||
})() : false; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
@@ -298,3 +297,6 @@ function tree_iter(f, m) { | ||
function tree_tryPick(f, m) { | ||
return m.Case === "MapOne" ? f(m.Fields[0], m.Fields[1]) : m.Case === "MapNode" ? (function () { | ||
if (m.Case === "MapOne") { | ||
return f(m.Fields[0], m.Fields[1]); | ||
} | ||
else if (m.Case === "MapNode") { | ||
var matchValue = tree_tryPick(f, m.Fields[2]); | ||
@@ -315,3 +317,6 @@ if (matchValue == null) { | ||
} | ||
})() : null; | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
@@ -324,70 +329,11 @@ function tree_exists(f, m) { | ||
} | ||
// function tree_map(f: (v:any) => any, m: MapTree): MapTree { | ||
// return m.Case === "MapOne" ? new MapTree("MapOne", [m.Fields[0], f(m.Fields[1])]) : m.Case === "MapNode" ? (() => { | ||
// var l2 = tree_map(f, m.Fields[2]); | ||
// var v2 = f(m.Fields[1]); | ||
// var r2 = tree_map(f, m.Fields[3]); | ||
// return new MapTree("MapNode", [m.Fields[0], v2, l2, r2, m.Fields[4]]); | ||
// })() : tree_empty(); | ||
// } | ||
function tree_mapi(f, m) { | ||
return m.Case === "MapOne" ? new MapTree("MapOne", [m.Fields[0], f(m.Fields[0], m.Fields[1])]) : m.Case === "MapNode" ? (function () { | ||
var l2 = tree_mapi(f, m.Fields[2]); | ||
var v2 = f(m.Fields[0], m.Fields[1]); | ||
var r2 = tree_mapi(f, m.Fields[3]); | ||
return new MapTree("MapNode", [m.Fields[0], v2, l2, r2, m.Fields[4]]); | ||
})() : tree_empty(); | ||
return m.Case === "MapOne" ? new MapTree("MapOne", [m.Fields[0], f(m.Fields[0], m.Fields[1])]) : m.Case === "MapNode" ? new MapTree("MapNode", [m.Fields[0], f(m.Fields[0], m.Fields[1]), tree_mapi(f, m.Fields[2]), tree_mapi(f, m.Fields[3]), m.Fields[4]]) : tree_empty(); | ||
} | ||
function tree_foldBack(f, m, x) { | ||
return m.Case === "MapOne" ? f(m.Fields[0], m.Fields[1], x) : m.Case === "MapNode" ? (function () { | ||
var x_1 = tree_foldBack(f, m.Fields[3], x); | ||
var x_2 = f(m.Fields[0], m.Fields[1], x_1); | ||
return tree_foldBack(f, m.Fields[2], x_2); | ||
})() : x; | ||
return m.Case === "MapOne" ? f(m.Fields[0], m.Fields[1], x) : m.Case === "MapNode" ? tree_foldBack(f, m.Fields[2], f(m.Fields[0], m.Fields[1], tree_foldBack(f, m.Fields[3], x))) : x; | ||
} | ||
function tree_fold(f, x, m) { | ||
return m.Case === "MapOne" ? f(x, m.Fields[0], m.Fields[1]) : m.Case === "MapNode" ? (function () { | ||
var x_1 = tree_fold(f, x, m.Fields[2]); | ||
var x_2 = f(x_1, m.Fields[0], m.Fields[1]); | ||
return tree_fold(f, x_2, m.Fields[3]); | ||
})() : x; | ||
return m.Case === "MapOne" ? f(x, m.Fields[0], m.Fields[1]) : m.Case === "MapNode" ? tree_fold(f, f(tree_fold(f, x, m.Fields[2]), m.Fields[0], m.Fields[1]), m.Fields[3]) : x; | ||
} | ||
// function tree_foldFromTo(comparer: IComparer<any>, lo: any, hi: any, f: (k:any, v:any, acc: any) => any, m: MapTree, x: any): any { | ||
// if (m.Case === "MapOne") { | ||
// var cLoKey = comparer.Compare(lo, m.Fields[0]); | ||
// var cKeyHi = comparer.Compare(m.Fields[0], hi); | ||
// var x_1 = (cLoKey <= 0 ? cKeyHi <= 0 : false) ? f(m.Fields[0], m.Fields[1], x) : x; | ||
// return x_1; | ||
// } | ||
// else if (m.Case === "MapNode") { | ||
// var cLoKey = comparer.Compare(lo, m.Fields[0]); | ||
// var cKeyHi = comparer.Compare(m.Fields[0], hi); | ||
// var x_1 = cLoKey < 0 ? tree_foldFromTo(comparer, lo, hi, f, m.Fields[2], x) : x; | ||
// var x_2 = (cLoKey <= 0 ? cKeyHi <= 0 : false) ? f(m.Fields[0], m.Fields[1], x_1) : x_1; | ||
// var x_3 = cKeyHi < 0 ? tree_foldFromTo(comparer, lo, hi, f, m.Fields[3], x_2) : x_2; | ||
// return x_3; | ||
// } | ||
// return x; | ||
// } | ||
// function tree_foldSection(comparer: IComparer<any>, lo: any, hi: any, f: (k:any, v:any, acc: any) => any, m: MapTree, x: any) { | ||
// return comparer.Compare(lo, hi) === 1 ? x : tree_foldFromTo(comparer, lo, hi, f, m, x); | ||
// } | ||
// function tree_loop(m: MapTree, acc: any): List<[any,any]> { | ||
// return m.Case === "MapOne" | ||
// ? new List([m.Fields[0], m.Fields[1]], acc) | ||
// : m.Case === "MapNode" | ||
// ? tree_loop(m.Fields[2], new List([m.Fields[0], m.Fields[1]], tree_loop(m.Fields[3], acc))) | ||
// : acc; | ||
// } | ||
// function tree_toList(m: MapTree) { | ||
// return tree_loop(m, new List()); | ||
// } | ||
// function tree_toArray(m: MapTree) { | ||
// return Array.from(tree_toList(m)); | ||
// } | ||
// function tree_ofList(comparer: IComparer<any>, l: List<[any,any]>) { | ||
// return Seq.fold((acc: MapTree, tupledArg: [any, any]) => { | ||
// return tree_add(comparer, tupledArg[0], tupledArg[1], acc); | ||
// }, tree_empty(), l); | ||
// } | ||
function tree_mkFromEnumerator(comparer, acc, e) { | ||
@@ -401,9 +347,2 @@ var cur = e.next(); | ||
} | ||
// function tree_ofArray(comparer: IComparer<any>, arr: ArrayLike<[any,any]>) { | ||
// var res = tree_empty(); | ||
// for (var i = 0; i <= arr.length - 1; i++) { | ||
// res = tree_add(comparer, arr[i][0], arr[i][1], res); | ||
// } | ||
// return res; | ||
// } | ||
function tree_ofSeq(comparer, c) { | ||
@@ -413,5 +352,2 @@ var ie = c[Symbol.iterator](); | ||
} | ||
// function tree_copyToArray(s: MapTree, arr: ArrayLike<any>, i: number) { | ||
// tree_iter((x, y) => { arr[i++] = [x, y]; }, s); | ||
// } | ||
function tree_collapseLHS(stack) { | ||
@@ -476,13 +412,12 @@ if (stack.tail != null) { | ||
} | ||
var FMap = (function () { | ||
/** Do not call, use Map.create instead. */ | ||
function FMap() { | ||
var FableMap = (function () { | ||
function FableMap() { | ||
} | ||
FMap.prototype.ToString = function () { | ||
FableMap.prototype.ToString = function () { | ||
return "map [" + Array.from(this).map(toString).join("; ") + "]"; | ||
}; | ||
FMap.prototype.Equals = function (m2) { | ||
FableMap.prototype.Equals = function (m2) { | ||
return this.CompareTo(m2) === 0; | ||
}; | ||
FMap.prototype.CompareTo = function (m2) { | ||
FableMap.prototype.CompareTo = function (m2) { | ||
var _this = this; | ||
@@ -494,3 +429,3 @@ return this === m2 ? 0 : seqCompareWith(function (kvp1, kvp2) { | ||
}; | ||
FMap.prototype[Symbol.iterator] = function () { | ||
FableMap.prototype[Symbol.iterator] = function () { | ||
var i = tree_mkIterator(this.tree); | ||
@@ -501,30 +436,27 @@ return { | ||
}; | ||
FMap.prototype.entries = function () { | ||
FableMap.prototype.entries = function () { | ||
return this[Symbol.iterator](); | ||
}; | ||
FMap.prototype.keys = function () { | ||
FableMap.prototype.keys = function () { | ||
return seqMap(function (kv) { return kv[0]; }, this); | ||
}; | ||
FMap.prototype.values = function () { | ||
FableMap.prototype.values = function () { | ||
return seqMap(function (kv) { return kv[1]; }, this); | ||
}; | ||
FMap.prototype.get = function (k) { | ||
FableMap.prototype.get = function (k) { | ||
return tree_find(this.comparer, k, this.tree); | ||
}; | ||
FMap.prototype.has = function (k) { | ||
FableMap.prototype.has = function (k) { | ||
return tree_mem(this.comparer, k, this.tree); | ||
}; | ||
/** Not supported */ | ||
FMap.prototype.set = function (k, v) { | ||
FableMap.prototype.set = function (k, v) { | ||
throw new Error("not supported"); | ||
}; | ||
/** Not supported */ | ||
FMap.prototype.delete = function (k) { | ||
FableMap.prototype.delete = function (k) { | ||
throw new Error("not supported"); | ||
}; | ||
/** Not supported */ | ||
FMap.prototype.clear = function () { | ||
FableMap.prototype.clear = function () { | ||
throw new Error("not supported"); | ||
}; | ||
Object.defineProperty(FMap.prototype, "size", { | ||
Object.defineProperty(FableMap.prototype, "size", { | ||
get: function () { | ||
@@ -536,3 +468,3 @@ return tree_size(this.tree); | ||
}); | ||
FMap.prototype[FSymbol.reflection] = function () { | ||
FableMap.prototype[FSymbol.reflection] = function () { | ||
return { | ||
@@ -543,7 +475,7 @@ type: "Microsoft.FSharp.Collections.FSharpMap", | ||
}; | ||
return FMap; | ||
return FableMap; | ||
}()); | ||
export default FMap; | ||
export default FableMap; | ||
function from(comparer, tree) { | ||
var map = new FMap(); | ||
var map = new FableMap(); | ||
map.tree = tree; | ||
@@ -550,0 +482,0 @@ map.comparer = comparer || new GenericComparer(); |
{ | ||
"name": "fable-core", | ||
"version": "0.7.20", | ||
"version": "0.7.21", | ||
"description": "Fable core lib & bindings for native JS objects, browser and node APIs", | ||
@@ -5,0 +5,0 @@ "main": "Main.js", |
@@ -41,3 +41,2 @@ import { NonDeclaredType } from "./Util"; | ||
} | ||
// TODO: This needs improvement, check namespace for non-custom types? | ||
export function getTypeFullName(typ, option) { | ||
@@ -80,3 +79,2 @@ function trim(fullName, option) { | ||
else { | ||
// Attention: this doesn't work with Object.getPrototypeOf | ||
var proto = typ.prototype; | ||
@@ -83,0 +81,0 @@ return trim(typeof proto[FSymbol.reflection] === "function" |
@@ -7,3 +7,2 @@ export function create(pattern, options) { | ||
} | ||
// From http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex | ||
export function escape(str) { | ||
@@ -35,3 +34,3 @@ return str.replace(/[\-\[\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); | ||
if (!reg.global) | ||
throw new Error("Non-global RegExp"); // Prevent infinite loop | ||
throw new Error("Non-global RegExp"); | ||
var m; | ||
@@ -44,3 +43,3 @@ var matches = []; | ||
export function options(reg) { | ||
var options = 256; // ECMAScript | ||
var options = 256; | ||
options |= reg.ignoreCase ? 1 : 0; | ||
@@ -47,0 +46,0 @@ options |= reg.multiline ? 2 : 0; |
@@ -359,3 +359,2 @@ import { equals } from "./Util"; | ||
} | ||
// A export function 'length' method causes problems in JavaScript -- https://github.com/Microsoft/TypeScript/issues/442 | ||
export function count(xs) { | ||
@@ -362,0 +361,0 @@ return Array.isArray(xs) || ArrayBuffer.isView(xs) |
@@ -1,7 +0,7 @@ | ||
import FSymbol from "./Symbol"; | ||
import FableSymbol from "./Symbol"; | ||
import { getType } from "./Symbol"; | ||
import List from "./List"; | ||
import { ofArray as listOfArray } from "./List"; | ||
import FSet from "./Set"; | ||
import FMap from "./Map"; | ||
import FableSet from "./Set"; | ||
import FableMap from "./Map"; | ||
import { create as mapCreate } from "./Map"; | ||
@@ -22,7 +22,7 @@ import { create as setCreate } from "./Set"; | ||
else if (v != null && typeof v === "object") { | ||
var properties = typeof v[FSymbol.reflection] === "function" ? v[FSymbol.reflection]().properties : null; | ||
if (v instanceof List || v instanceof FSet || v instanceof Set) { | ||
var properties = typeof v[FableSymbol.reflection] === "function" ? v[FableSymbol.reflection]().properties : null; | ||
if (v instanceof List || v instanceof FableSet || v instanceof Set) { | ||
return Array.from(v); | ||
} | ||
else if (v instanceof FMap || v instanceof Map) { | ||
else if (v instanceof FableMap || v instanceof Map) { | ||
return fold(function (o, kv) { | ||
@@ -42,3 +42,2 @@ return o[toJson(kv[0])] = kv[1], o; | ||
else if (v.Fields.length === 1) { | ||
// Prevent undefined assignment from removing case property; see #611: | ||
var fieldValue = typeof v.Fields[0] === 'undefined' ? null : v.Fields[0]; | ||
@@ -69,4 +68,4 @@ return _a = {}, _a[v.Case] = fieldValue, _a; | ||
else { | ||
var info = typeof typ.prototype[FSymbol.reflection] === "function" | ||
? typ.prototype[FSymbol.reflection]() : null; | ||
var info = typeof typ.prototype[FableSymbol.reflection] === "function" | ||
? typ.prototype[FableSymbol.reflection]() : null; | ||
return info ? info.nullable : true; | ||
@@ -87,3 +86,3 @@ } | ||
case "Array": | ||
return needsInflate(new List(typ.generics, enclosing)); | ||
return typ.definition != null || needsInflate(new List(typ.generics, enclosing)); | ||
case "Tuple": | ||
@@ -107,3 +106,2 @@ return typ.generics.some(function (x) { | ||
} | ||
// TODO: Validate non-inflated elements | ||
return needsInflate(enclosing) | ||
@@ -164,3 +162,8 @@ ? arr.map(function (x, i) { return inflate(x, enclosing, combine(path, i)); }) | ||
case "Array": | ||
return inflateArray(val, new List(typ.generics, enclosing), path); | ||
if (typ.definition != null) { | ||
return new typ.definition(val); | ||
} | ||
else { | ||
return inflateArray(val, new List(typ.generics, enclosing), path); | ||
} | ||
case "Tuple": | ||
@@ -179,4 +182,3 @@ return typ.generics.map(function (x, i) { | ||
} | ||
// TODO: Should we try to inflate also sets and maps serialized with `JSON.stringify`? | ||
if (def === FSet) { | ||
if (def === FableSet) { | ||
return setCreate(inflateArray(val, resolveGeneric(0, enclosing), path)); | ||
@@ -187,3 +189,3 @@ } | ||
} | ||
if (def === FMap) { | ||
if (def === FableMap) { | ||
return mapCreate(inflateMap(val, resolveGeneric(0, enclosing), resolveGeneric(1, enclosing), path)); | ||
@@ -203,7 +205,5 @@ } | ||
} | ||
var info = typeof typ.prototype[FSymbol.reflection] === "function" ? typ.prototype[FSymbol.reflection]() : {}; | ||
// Union types | ||
var info = typeof typ.prototype[FableSymbol.reflection] === "function" ? typ.prototype[FableSymbol.reflection]() : {}; | ||
if (info.cases) { | ||
var uCase = void 0, uFields = []; | ||
// Cases withouth fields are serialized as strings by `toJson` | ||
if (typeof val === "string") { | ||
@@ -228,3 +228,2 @@ uCase = val; | ||
} | ||
// Validate | ||
if (uCase in info.cases === false) { | ||
@@ -236,3 +235,3 @@ invalidate(val, typ, path); | ||
if (info.properties) { | ||
var temp = {}; | ||
var newObj = new typ(); | ||
var properties = info.properties; | ||
@@ -242,5 +241,5 @@ var ks = Object.getOwnPropertyNames(properties); | ||
var k = ks[i]; | ||
temp[k] = inflate(val[k], new List(properties[k], enclosing), combine(path, k)); | ||
newObj[k] = inflate(val[k], new List(properties[k], enclosing), combine(path, k)); | ||
} | ||
return Object.assign(new typ(), temp); | ||
return newObj; | ||
} | ||
@@ -264,4 +263,4 @@ return val; | ||
else if (v != null && typeof v === "object") { | ||
var typeName = typeof v[FSymbol.reflection] === "function" ? v[FSymbol.reflection]().type : null; | ||
if (v instanceof List || v instanceof FSet || v instanceof Set) { | ||
var typeName = typeof v[FableSymbol.reflection] === "function" ? v[FableSymbol.reflection]().type : null; | ||
if (v instanceof List || v instanceof FableSet || v instanceof Set) { | ||
return { | ||
@@ -272,3 +271,3 @@ $type: typeName || "System.Collections.Generic.HashSet", | ||
} | ||
else if (v instanceof FMap || v instanceof Map) { | ||
else if (v instanceof FableMap || v instanceof Map) { | ||
return fold(function (o, kv) { o[kv[0]] = kv[1]; return o; }, { $type: typeName || "System.Collections.Generic.Dictionary" }, v); | ||
@@ -299,3 +298,2 @@ } | ||
else if (typeof v === "object" && typeof v.$type === "string") { | ||
// Remove generic args and assembly info added by Newtonsoft.Json | ||
var type = v.$type.replace('+', '.'), i = type.indexOf('`'); | ||
@@ -302,0 +300,0 @@ if (i > -1) { |
265
Set.js
@@ -13,5 +13,2 @@ import List from "./List"; | ||
import { scan as seqScan } from "./Seq"; | ||
// ---------------------------------------------- | ||
// These functions belong to Seq.ts but are | ||
// implemented here to prevent cyclic dependencies | ||
export function distinctBy(f, xs) { | ||
@@ -117,3 +114,3 @@ return seqChoose(function (tup) { return tup[0]; }, seqScan(function (tup, x) { | ||
function tree_add(comparer, k, t) { | ||
return t.Case === "SetOne" ? (function () { | ||
if (t.Case === "SetOne") { | ||
var c = comparer.Compare(k, t.Fields[0]); | ||
@@ -123,11 +120,13 @@ if (c < 0) { | ||
} | ||
else if (c === 0) { | ||
return t; | ||
} | ||
else { | ||
if (c === 0) { | ||
return t; | ||
} | ||
else { | ||
return tree_SetNode(k, t, new SetTree("SetEmpty", []), 2); | ||
} | ||
return tree_SetNode(k, t, new SetTree("SetEmpty", []), 2); | ||
} | ||
})() : t.Case === "SetEmpty" ? tree_SetOne(k) : (function () { | ||
} | ||
else if (t.Case === "SetEmpty") { | ||
return tree_SetOne(k); | ||
} | ||
else { | ||
var c = comparer.Compare(k, t.Fields[0]); | ||
@@ -137,11 +136,9 @@ if (c < 0) { | ||
} | ||
else if (c === 0) { | ||
return t; | ||
} | ||
else { | ||
if (c === 0) { | ||
return t; | ||
} | ||
else { | ||
return tree_rebalance(t.Fields[1], t.Fields[0], tree_add(comparer, k, t.Fields[2])); | ||
} | ||
return tree_rebalance(t.Fields[1], t.Fields[0], tree_add(comparer, k, t.Fields[2])); | ||
} | ||
})(); | ||
} | ||
} | ||
@@ -206,3 +203,3 @@ function tree_balance(comparer, t1, k, t2) { | ||
function tree_split(comparer, pivot, t) { | ||
return t.Case === "SetOne" ? (function () { | ||
if (t.Case === "SetOne") { | ||
var c = comparer.Compare(t.Fields[0], pivot); | ||
@@ -212,45 +209,46 @@ if (c < 0) { | ||
} | ||
else if (c === 0) { | ||
return [new SetTree("SetEmpty", []), true, new SetTree("SetEmpty", [])]; | ||
} | ||
else { | ||
if (c === 0) { | ||
return [new SetTree("SetEmpty", []), true, new SetTree("SetEmpty", [])]; | ||
} | ||
else { | ||
return [new SetTree("SetEmpty", []), false, t]; | ||
} | ||
return [new SetTree("SetEmpty", []), false, t]; | ||
} | ||
})() : t.Case === "SetEmpty" ? [new SetTree("SetEmpty", []), false, new SetTree("SetEmpty", [])] : (function () { | ||
} | ||
else if (t.Case === "SetEmpty") { | ||
return [new SetTree("SetEmpty", []), false, new SetTree("SetEmpty", [])]; | ||
} | ||
else { | ||
var c = comparer.Compare(pivot, t.Fields[0]); | ||
if (c < 0) { | ||
var patternInput = tree_split(comparer, pivot, t.Fields[1]); | ||
var t11Lo = patternInput[0]; | ||
var t11Hi = patternInput[2]; | ||
var havePivot = patternInput[1]; | ||
return [t11Lo, havePivot, tree_balance(comparer, t11Hi, t.Fields[0], t.Fields[2])]; | ||
return [patternInput[0], patternInput[1], tree_balance(comparer, patternInput[2], t.Fields[0], t.Fields[2])]; | ||
} | ||
else if (c === 0) { | ||
return [t.Fields[1], true, t.Fields[2]]; | ||
} | ||
else { | ||
if (c === 0) { | ||
return [t.Fields[1], true, t.Fields[2]]; | ||
} | ||
else { | ||
var patternInput = tree_split(comparer, pivot, t.Fields[2]); | ||
var t12Lo = patternInput[0]; | ||
var t12Hi = patternInput[2]; | ||
var havePivot = patternInput[1]; | ||
return [tree_balance(comparer, t.Fields[1], t.Fields[0], t12Lo), havePivot, t12Hi]; | ||
} | ||
var patternInput = tree_split(comparer, pivot, t.Fields[2]); | ||
return [tree_balance(comparer, t.Fields[1], t.Fields[0], patternInput[0]), patternInput[1], patternInput[2]]; | ||
} | ||
})(); | ||
} | ||
} | ||
function tree_spliceOutSuccessor(t) { | ||
return t.Case === "SetOne" ? [t.Fields[0], new SetTree("SetEmpty", [])] : t.Case === "SetNode" ? t.Fields[1].Case === "SetEmpty" ? [t.Fields[0], t.Fields[2]] : (function () { | ||
var patternInput = tree_spliceOutSuccessor(t.Fields[1]); | ||
var l_ = patternInput[1]; | ||
var k3 = patternInput[0]; | ||
return [k3, tree_mk(l_, t.Fields[0], t.Fields[2])]; | ||
})() : (function () { | ||
if (t.Case === "SetOne") { | ||
return [t.Fields[0], new SetTree("SetEmpty", [])]; | ||
} | ||
else if (t.Case === "SetNode") { | ||
if (t.Fields[1].Case === "SetEmpty") { | ||
return [t.Fields[0], t.Fields[2]]; | ||
} | ||
else { | ||
var patternInput = tree_spliceOutSuccessor(t.Fields[1]); | ||
return [patternInput[0], tree_mk(patternInput[1], t.Fields[0], t.Fields[2])]; | ||
} | ||
} | ||
else { | ||
throw new Error("internal error: Map.spliceOutSuccessor"); | ||
})(); | ||
} | ||
} | ||
function tree_remove(comparer, k, t) { | ||
return t.Case === "SetOne" ? (function () { | ||
if (t.Case === "SetOne") { | ||
var c = comparer.Compare(k, t.Fields[0]); | ||
@@ -263,3 +261,4 @@ if (c === 0) { | ||
} | ||
})() : t.Case === "SetNode" ? (function () { | ||
} | ||
else if (t.Case === "SetNode") { | ||
var c = comparer.Compare(k, t.Fields[0]); | ||
@@ -269,28 +268,31 @@ if (c < 0) { | ||
} | ||
else { | ||
if (c === 0) { | ||
var matchValue = [t.Fields[1], t.Fields[2]]; | ||
if (matchValue[0].Case === "SetEmpty") { | ||
return t.Fields[2]; | ||
} | ||
else { | ||
if (matchValue[1].Case === "SetEmpty") { | ||
return t.Fields[1]; | ||
} | ||
else { | ||
var patternInput = tree_spliceOutSuccessor(t.Fields[2]); | ||
var sk = patternInput[0]; | ||
var r_ = patternInput[1]; | ||
return tree_mk(t.Fields[1], sk, r_); | ||
} | ||
} | ||
else if (c === 0) { | ||
var matchValue = [t.Fields[1], t.Fields[2]]; | ||
if (matchValue[0].Case === "SetEmpty") { | ||
return t.Fields[2]; | ||
} | ||
else if (matchValue[1].Case === "SetEmpty") { | ||
return t.Fields[1]; | ||
} | ||
else { | ||
return tree_rebalance(t.Fields[1], t.Fields[0], tree_remove(comparer, k, t.Fields[2])); | ||
var patternInput = tree_spliceOutSuccessor(t.Fields[2]); | ||
return tree_mk(t.Fields[1], patternInput[0], patternInput[1]); | ||
} | ||
} | ||
})() : t; | ||
else { | ||
return tree_rebalance(t.Fields[1], t.Fields[0], tree_remove(comparer, k, t.Fields[2])); | ||
} | ||
} | ||
else { | ||
return t; | ||
} | ||
} | ||
function tree_mem(comparer, k, t) { | ||
return t.Case === "SetOne" ? comparer.Compare(k, t.Fields[0]) === 0 : t.Case === "SetEmpty" ? false : (function () { | ||
if (t.Case === "SetOne") { | ||
return comparer.Compare(k, t.Fields[0]) === 0; | ||
} | ||
else if (t.Case === "SetEmpty") { | ||
return false; | ||
} | ||
else { | ||
var c = comparer.Compare(k, t.Fields[0]); | ||
@@ -300,11 +302,9 @@ if (c < 0) { | ||
} | ||
else if (c === 0) { | ||
return true; | ||
} | ||
else { | ||
if (c === 0) { | ||
return true; | ||
} | ||
else { | ||
return tree_mem(comparer, k, t.Fields[2]); | ||
} | ||
return tree_mem(comparer, k, t.Fields[2]); | ||
} | ||
})(); | ||
} | ||
} | ||
@@ -328,7 +328,13 @@ function tree_iter(f, t) { | ||
function tree_fold(f, x, m) { | ||
return m.Case === "SetOne" ? f(x, m.Fields[0]) : m.Case === "SetEmpty" ? x : (function () { | ||
if (m.Case === "SetOne") { | ||
return f(x, m.Fields[0]); | ||
} | ||
else if (m.Case === "SetEmpty") { | ||
return x; | ||
} | ||
else { | ||
var x_1 = tree_fold(f, x, m.Fields[1]); | ||
var x_2 = f(x_1, m.Fields[0]); | ||
return tree_fold(f, x_2, m.Fields[2]); | ||
})(); | ||
} | ||
} | ||
@@ -351,6 +357,17 @@ function tree_forall(f, m) { | ||
function tree_filterAux(comparer, f, s, acc) { | ||
return s.Case === "SetOne" ? f(s.Fields[0]) ? tree_add(comparer, s.Fields[0], acc) : acc : s.Case === "SetEmpty" ? acc : (function () { | ||
if (s.Case === "SetOne") { | ||
if (f(s.Fields[0])) { | ||
return tree_add(comparer, s.Fields[0], acc); | ||
} | ||
else { | ||
return acc; | ||
} | ||
} | ||
else if (s.Case === "SetEmpty") { | ||
return acc; | ||
} | ||
else { | ||
var acc_1 = f(s.Fields[0]) ? tree_add(comparer, s.Fields[0], acc) : acc; | ||
return tree_filterAux(comparer, f, s.Fields[1], tree_filterAux(comparer, f, s.Fields[2], acc_1)); | ||
})(); | ||
} | ||
} | ||
@@ -425,7 +442,18 @@ function tree_filter(comparer, f, s) { | ||
function tree_intersectionAux(comparer, b, m, acc) { | ||
return m.Case === "SetOne" ? tree_mem(comparer, m.Fields[0], b) ? tree_add(comparer, m.Fields[0], acc) : acc : m.Case === "SetEmpty" ? acc : (function () { | ||
if (m.Case === "SetOne") { | ||
if (tree_mem(comparer, m.Fields[0], b)) { | ||
return tree_add(comparer, m.Fields[0], acc); | ||
} | ||
else { | ||
return acc; | ||
} | ||
} | ||
else if (m.Case === "SetEmpty") { | ||
return acc; | ||
} | ||
else { | ||
var acc_1 = tree_intersectionAux(comparer, b, m.Fields[2], acc); | ||
var acc_2 = tree_mem(comparer, m.Fields[0], b) ? tree_add(comparer, m.Fields[0], acc_1) : acc_1; | ||
return tree_intersectionAux(comparer, b, m.Fields[1], acc_2); | ||
})(); | ||
} | ||
} | ||
@@ -450,15 +478,5 @@ function tree_intersection(comparer, a, b) { | ||
else { | ||
var acc_2 = (function () { | ||
var arg30_ = acc[0]; | ||
var arg31_ = acc[1]; | ||
return tree_partitionAux(comparer, f, s.Fields[2], arg30_, arg31_); | ||
})(); | ||
var acc_3 = (function () { | ||
var acc1 = acc_2[0]; | ||
var acc2 = acc_2[1]; | ||
return tree_partition1(comparer, f, s.Fields[0], acc1, acc2); | ||
})(); | ||
var arg30_ = acc_3[0]; | ||
var arg31_ = acc_3[1]; | ||
return tree_partitionAux(comparer, f, s.Fields[1], arg30_, arg31_); | ||
var acc_2 = tree_partitionAux(comparer, f, s.Fields[2], acc[0], acc[1]); | ||
var acc_3 = tree_partition1(comparer, f, s.Fields[0], acc_2[0], acc_2[1]); | ||
return tree_partitionAux(comparer, f, s.Fields[1], acc_3[0], acc_3[1]); | ||
} | ||
@@ -473,5 +491,2 @@ } | ||
} | ||
// function tree_$MatchSetNode$MatchSetEmpty$(s: SetTree) { | ||
// return s.Case === "SetOne" ? new Choice("Choice1Of2", [[s.Fields[0], new SetTree("SetEmpty", []), new SetTree("SetEmpty", [])]]) : s.Case === "SetEmpty" ? new Choice("Choice2Of2", [null]) : new Choice("Choice1Of2", [[s.Fields[0], s.Fields[1], s.Fields[2]]]); | ||
// } | ||
function tree_minimumElementAux(s, n) { | ||
@@ -524,8 +539,2 @@ return s.Case === "SetOne" ? s.Fields[0] : s.Case === "SetEmpty" ? n : tree_minimumElementAux(s.Fields[1], s.Fields[0]); | ||
; | ||
// function tree_notStarted() { | ||
// throw new Error("Enumeration not started"); | ||
// }; | ||
// var alreadyFinished = $exports.alreadyFinished = function () { | ||
// throw new Error("Enumeration already started"); | ||
// }; | ||
function tree_moveNext(i) { | ||
@@ -708,16 +717,15 @@ function current(i) { | ||
} | ||
var FSet = (function () { | ||
/** Do not call, use Set.create instead. */ | ||
function FSet() { | ||
var FableSet = (function () { | ||
function FableSet() { | ||
} | ||
FSet.prototype.ToString = function () { | ||
FableSet.prototype.ToString = function () { | ||
return "set [" + Array.from(this).map(toString).join("; ") + "]"; | ||
}; | ||
FSet.prototype.Equals = function (s2) { | ||
FableSet.prototype.Equals = function (s2) { | ||
return this.CompareTo(s2) === 0; | ||
}; | ||
FSet.prototype.CompareTo = function (s2) { | ||
FableSet.prototype.CompareTo = function (s2) { | ||
return this === s2 ? 0 : tree_compare(this.comparer, this.tree, s2.tree); | ||
}; | ||
FSet.prototype[Symbol.iterator] = function () { | ||
FableSet.prototype[Symbol.iterator] = function () { | ||
var i = tree_mkIterator(this.tree); | ||
@@ -728,21 +736,18 @@ return { | ||
}; | ||
FSet.prototype.values = function () { | ||
FableSet.prototype.values = function () { | ||
return this[Symbol.iterator](); | ||
}; | ||
FSet.prototype.has = function (v) { | ||
FableSet.prototype.has = function (v) { | ||
return tree_mem(this.comparer, v, this.tree); | ||
}; | ||
/** Not supported */ | ||
FSet.prototype.add = function (v) { | ||
FableSet.prototype.add = function (v) { | ||
throw new Error("not supported"); | ||
}; | ||
/** Not supported */ | ||
FSet.prototype.delete = function (v) { | ||
FableSet.prototype.delete = function (v) { | ||
throw new Error("not supported"); | ||
}; | ||
/** Not supported */ | ||
FSet.prototype.clear = function () { | ||
FableSet.prototype.clear = function () { | ||
throw new Error("not supported"); | ||
}; | ||
Object.defineProperty(FSet.prototype, "size", { | ||
Object.defineProperty(FableSet.prototype, "size", { | ||
get: function () { | ||
@@ -754,3 +759,3 @@ return tree_count(this.tree); | ||
}); | ||
FSet.prototype[FSymbol.reflection] = function () { | ||
FableSet.prototype[FSymbol.reflection] = function () { | ||
return { | ||
@@ -761,7 +766,7 @@ type: "Microsoft.FSharp.Collections.FSharpSet", | ||
}; | ||
return FSet; | ||
return FableSet; | ||
}()); | ||
export default FSet; | ||
export default FableSet; | ||
function from(comparer, tree) { | ||
var s = new FSet(); | ||
var s = new FableSet(); | ||
s.tree = tree; | ||
@@ -801,4 +806,2 @@ s.comparer = comparer || new GenericComparer(); | ||
export function unionMany(sets) { | ||
// Pass args as union(s, acc) instead of union(acc, s) | ||
// to discard the comparer of the first empty set | ||
return seqFold(function (acc, s) { return union(s, acc); }, create(), sets); | ||
@@ -836,3 +839,3 @@ } | ||
export function isProperSubsetOf(set1, set2) { | ||
if (set1 instanceof FSet && set2 instanceof FSet) { | ||
if (set1 instanceof FableSet && set2 instanceof FableSet) { | ||
return tree_psubset(set1.comparer, set1.tree, set2.tree); | ||
@@ -849,3 +852,3 @@ } | ||
export function isSubsetOf(set1, set2) { | ||
if (set1 instanceof FSet && set2 instanceof FSet) { | ||
if (set1 instanceof FableSet && set2 instanceof FableSet) { | ||
return tree_subset(set1.comparer, set1.tree, set2.tree); | ||
@@ -862,3 +865,3 @@ } | ||
export function isProperSupersetOf(set1, set2) { | ||
if (set1 instanceof FSet && set2 instanceof FSet) { | ||
if (set1 instanceof FableSet && set2 instanceof FableSet) { | ||
return tree_psubset(set1.comparer, set2.tree, set1.tree); | ||
@@ -874,3 +877,3 @@ } | ||
export function isSupersetOf(set1, set2) { | ||
if (set1 instanceof FSet && set2 instanceof FSet) { | ||
if (set1 instanceof FableSet && set2 instanceof FableSet) { | ||
return tree_subset(set1.comparer, set2.tree, set1.tree); | ||
@@ -877,0 +880,0 @@ } |
@@ -34,3 +34,3 @@ import { toString } from "./Util"; | ||
if (y == null) | ||
return 1; // everything is bigger than null | ||
return 1; | ||
if (isOrdinal(ic)) { | ||
@@ -133,3 +133,2 @@ if (isIgnoreCase(ic)) { | ||
catch (err) { | ||
// Fallback for objects with circular references | ||
rep = "{" + Object.getOwnPropertyNames(rep).map(function (k) { return k + ": " + String(rep[k]); }).join(", ") + "}"; | ||
@@ -236,3 +235,3 @@ } | ||
case "O": | ||
if (rep.kind === 2 /* Local */) { | ||
if (rep.kind === 2) { | ||
var offset = rep.getTimezoneOffset() * -1; | ||
@@ -239,0 +238,0 @@ rep = format("{0:yyyy-MM-dd}T{0:HH:mm}:{1:00.000}{2}{3:00}:{4:00}", rep, second(rep), offset >= 0 ? "+" : "-", ~~(offset / 60), offset % 60); |
@@ -11,10 +11,7 @@ import { compare as utilCompare } from "./Util"; | ||
case 1: | ||
// ticks | ||
return fromTicks(arguments[0]); | ||
case 3: | ||
// h,m,s | ||
d = 0, h = arguments[0], m = arguments[1], s = arguments[2], ms = 0; | ||
break; | ||
default: | ||
// d,h,m,s,ms | ||
d = arguments[0], h = arguments[1], m = arguments[2], s = arguments[3], ms = arguments[4] || 0; | ||
@@ -21,0 +18,0 @@ break; |
@@ -35,3 +35,2 @@ (function (dependencies, factory) { | ||
function permute(f, xs) { | ||
// Keep the type of the array | ||
var ys = xs.map(function () { return null; }); | ||
@@ -38,0 +37,0 @@ var checkFlags = new Array(xs.length); |
@@ -17,3 +17,2 @@ (function (dependencies, factory) { | ||
var Seq_1 = require("./Seq"); | ||
// Implemented just for type references | ||
var Async = (function () { | ||
@@ -27,3 +26,2 @@ function Async() { | ||
function emptyContinuation(x) { | ||
// NOP | ||
} | ||
@@ -30,0 +28,0 @@ function awaitPromise(p) { |
@@ -23,6 +23,6 @@ (function (dependencies, factory) { | ||
if (kind == null) { | ||
kind = typeof v == "string" && v.slice(-1) == "Z" ? 1 /* UTC */ : 2 /* Local */; | ||
kind = typeof v == "string" && v.slice(-1) == "Z" ? 1 : 2; | ||
} | ||
var date = (v == null) ? new Date() : new Date(v); | ||
if (kind === 2 /* Local */) { | ||
if (kind === 2) { | ||
date.kind = kind; | ||
@@ -50,5 +50,5 @@ } | ||
if (ms === void 0) { ms = 0; } | ||
if (kind === void 0) { kind = 2 /* Local */; } | ||
if (kind === void 0) { kind = 2; } | ||
var date; | ||
if (kind === 2 /* Local */) { | ||
if (kind === 2) { | ||
date = new Date(year, month - 1, day, h, m, s, ms); | ||
@@ -89,7 +89,7 @@ date.kind = kind; | ||
function toUniversalTime(d) { | ||
return d.kind === 2 /* Local */ ? new Date(d.getTime()) : d; | ||
return d.kind === 2 ? new Date(d.getTime()) : d; | ||
} | ||
exports.toUniversalTime = toUniversalTime; | ||
function toLocalTime(d) { | ||
if (d.kind === 2 /* Local */) { | ||
if (d.kind === 2) { | ||
return d; | ||
@@ -99,3 +99,3 @@ } | ||
var d2 = new Date(d.getTime()); | ||
d2.kind = 2 /* Local */; | ||
d2.kind = 2; | ||
return d2; | ||
@@ -110,39 +110,39 @@ } | ||
function date(d) { | ||
return create(year(d), month(d), day(d), 0, 0, 0, 0, d.kind || 1 /* UTC */); | ||
return create(year(d), month(d), day(d), 0, 0, 0, 0, d.kind || 1); | ||
} | ||
exports.date = date; | ||
function kind(d) { | ||
return d.kind || 1 /* UTC */; | ||
return d.kind || 1; | ||
} | ||
exports.kind = kind; | ||
function day(d) { | ||
return d.kind === 2 /* Local */ ? d.getDate() : d.getUTCDate(); | ||
return d.kind === 2 ? d.getDate() : d.getUTCDate(); | ||
} | ||
exports.day = day; | ||
function hour(d) { | ||
return d.kind === 2 /* Local */ ? d.getHours() : d.getUTCHours(); | ||
return d.kind === 2 ? d.getHours() : d.getUTCHours(); | ||
} | ||
exports.hour = hour; | ||
function millisecond(d) { | ||
return d.kind === 2 /* Local */ ? d.getMilliseconds() : d.getUTCMilliseconds(); | ||
return d.kind === 2 ? d.getMilliseconds() : d.getUTCMilliseconds(); | ||
} | ||
exports.millisecond = millisecond; | ||
function minute(d) { | ||
return d.kind === 2 /* Local */ ? d.getMinutes() : d.getUTCMinutes(); | ||
return d.kind === 2 ? d.getMinutes() : d.getUTCMinutes(); | ||
} | ||
exports.minute = minute; | ||
function month(d) { | ||
return (d.kind === 2 /* Local */ ? d.getMonth() : d.getUTCMonth()) + 1; | ||
return (d.kind === 2 ? d.getMonth() : d.getUTCMonth()) + 1; | ||
} | ||
exports.month = month; | ||
function second(d) { | ||
return d.kind === 2 /* Local */ ? d.getSeconds() : d.getUTCSeconds(); | ||
return d.kind === 2 ? d.getSeconds() : d.getUTCSeconds(); | ||
} | ||
exports.second = second; | ||
function year(d) { | ||
return d.kind === 2 /* Local */ ? d.getFullYear() : d.getUTCFullYear(); | ||
return d.kind === 2 ? d.getFullYear() : d.getUTCFullYear(); | ||
} | ||
exports.year = year; | ||
function dayOfWeek(d) { | ||
return d.kind === 2 /* Local */ ? d.getDay() : d.getUTCDay(); | ||
return d.kind === 2 ? d.getDay() : d.getUTCDay(); | ||
} | ||
@@ -152,4 +152,4 @@ exports.dayOfWeek = dayOfWeek; | ||
return Long.fromNumber(d.getTime()) | ||
.add(62135596800000) // UnixEpochMilliseconds | ||
.sub(d.kind == 2 /* Local */ ? d.getTimezoneOffset() * 60 * 1000 : 0) | ||
.add(62135596800000) | ||
.sub(d.kind == 2 ? d.getTimezoneOffset() * 60 * 1000 : 0) | ||
.mul(10000); | ||
@@ -172,27 +172,27 @@ } | ||
function add(d, ts) { | ||
return parse(d.getTime() + ts, d.kind || 1 /* UTC */); | ||
return parse(d.getTime() + ts, d.kind || 1); | ||
} | ||
exports.add = add; | ||
function addDays(d, v) { | ||
return parse(d.getTime() + v * 86400000, d.kind || 1 /* UTC */); | ||
return parse(d.getTime() + v * 86400000, d.kind || 1); | ||
} | ||
exports.addDays = addDays; | ||
function addHours(d, v) { | ||
return parse(d.getTime() + v * 3600000, d.kind || 1 /* UTC */); | ||
return parse(d.getTime() + v * 3600000, d.kind || 1); | ||
} | ||
exports.addHours = addHours; | ||
function addMinutes(d, v) { | ||
return parse(d.getTime() + v * 60000, d.kind || 1 /* UTC */); | ||
return parse(d.getTime() + v * 60000, d.kind || 1); | ||
} | ||
exports.addMinutes = addMinutes; | ||
function addSeconds(d, v) { | ||
return parse(d.getTime() + v * 1000, d.kind || 1 /* UTC */); | ||
return parse(d.getTime() + v * 1000, d.kind || 1); | ||
} | ||
exports.addSeconds = addSeconds; | ||
function addMilliseconds(d, v) { | ||
return parse(d.getTime() + v, d.kind || 1 /* UTC */); | ||
return parse(d.getTime() + v, d.kind || 1); | ||
} | ||
exports.addMilliseconds = addMilliseconds; | ||
function addTicks(d, t) { | ||
return parse(Long.fromNumber(d.getTime()).add(t.div(10000)).toNumber(), d.kind || 1 /* UTC */); | ||
return parse(Long.fromNumber(d.getTime()).add(t.div(10000)).toNumber(), d.kind || 1); | ||
} | ||
@@ -205,3 +205,3 @@ exports.addTicks = addTicks; | ||
var newDay = Math.min(_daysInMonth, day(d)); | ||
return create(newYear, newMonth, newDay, hour(d), minute(d), second(d), millisecond(d), d.kind || 1 /* UTC */); | ||
return create(newYear, newMonth, newDay, hour(d), minute(d), second(d), millisecond(d), d.kind || 1); | ||
} | ||
@@ -226,3 +226,3 @@ exports.addYears = addYears; | ||
var newDay = Math.min(_daysInMonth, day(d)); | ||
return create(newYear, newMonth, newDay, hour(d), minute(d), second(d), millisecond(d), d.kind || 1 /* UTC */); | ||
return create(newYear, newMonth, newDay, hour(d), minute(d), second(d), millisecond(d), d.kind || 1); | ||
} | ||
@@ -232,3 +232,3 @@ exports.addMonths = addMonths; | ||
return typeof that == "number" | ||
? parse(d.getTime() - that, d.kind || 1 /* UTC */) | ||
? parse(d.getTime() - that, d.kind || 1) | ||
: d.getTime() - that.getTime(); | ||
@@ -235,0 +235,0 @@ } |
@@ -23,3 +23,2 @@ (function (dependencies, factory) { | ||
Object.defineProperty(Event.prototype, "Publish", { | ||
// IEvent<T> methods | ||
get: function () { | ||
@@ -34,3 +33,2 @@ return this; | ||
}; | ||
// IDelegateEvent<T> methods | ||
Event.prototype._addHandler = function (f) { | ||
@@ -61,3 +59,2 @@ this.delegates.push(f); | ||
}; | ||
// IObservable<T> methods | ||
Event.prototype._subscribeFromObserver = function (observer) { | ||
@@ -64,0 +61,0 @@ var _this = this; |
@@ -36,3 +36,2 @@ (function (dependencies, factory) { | ||
exports.collect = collect; | ||
// TODO: should be xs: Iterable<List<T>> | ||
function concat(xs) { | ||
@@ -94,3 +93,2 @@ return collect(function (x) { return x; }, xs); | ||
exports.slice = slice; | ||
/* ToDo: instance unzip() */ | ||
function unzip(xs) { | ||
@@ -102,3 +100,2 @@ return Seq_3.foldBack(function (xy, acc) { | ||
exports.unzip = unzip; | ||
/* ToDo: instance unzip3() */ | ||
function unzip3(xs) { | ||
@@ -105,0 +102,0 @@ return Seq_3.foldBack(function (xyz, acc) { |
@@ -14,3 +14,2 @@ (function (dependencies, factory) { | ||
var Util_3 = require("./Util"); | ||
// This module is split from List.ts to prevent cyclic dependencies | ||
function ofArray(args, base) { | ||
@@ -33,3 +32,2 @@ var acc = base || new List(); | ||
List.prototype.Equals = function (x) { | ||
// Optimization if they are referencially equal | ||
if (this === x) { | ||
@@ -52,3 +50,2 @@ return true; | ||
List.prototype.CompareTo = function (x) { | ||
// Optimization if they are referencially equal | ||
if (this === x) { | ||
@@ -96,32 +93,2 @@ return 0; | ||
}; | ||
// append(ys: List<T>): List<T> { | ||
// return append(this, ys); | ||
// } | ||
// choose<U>(f: (x: T) => U, xs: List<T>): List<U> { | ||
// return choose(f, this); | ||
// } | ||
// collect<U>(f: (x: T) => List<U>): List<U> { | ||
// return collect(f, this); | ||
// } | ||
// filter(f: (x: T) => boolean): List<T> { | ||
// return filter(f, this); | ||
// } | ||
// where(f: (x: T) => boolean): List<T> { | ||
// return filter(f, this); | ||
// } | ||
// map<U>(f: (x: T) => U): List<U> { | ||
// return map(f, this); | ||
// } | ||
// mapIndexed<U>(f: (i: number, x: T) => U): List<U> { | ||
// return mapIndexed(f, this); | ||
// } | ||
// partition(f: (x: T) => boolean): [List<T>, List<T>] { | ||
// return partition(f, this) as [List<T>, List<T>]; | ||
// } | ||
// reverse(): List<T> { | ||
// return reverse(this); | ||
// } | ||
// slice(lower: number, upper: number): List<T> { | ||
// return slice(lower, upper, this); | ||
// } | ||
List.prototype[Symbol_1.default.reflection] = function () { | ||
@@ -128,0 +95,0 @@ return { |
417
umd/Long.js
@@ -1,2 +0,1 @@ | ||
// Source: https://github.com/dcodeIO/long.js/blob/master/LICENSE | ||
(function (dependencies, factory) { | ||
@@ -11,128 +10,23 @@ if (typeof module === 'object' && typeof module.exports === 'object') { | ||
"use strict"; | ||
// The internal representation of a long is the two given signed, 32-bit values. | ||
// We use 32-bit pieces because these are the size of integers on which | ||
// Javascript performs bit-operations. For operations like addition and | ||
// multiplication, we split each number into 16 bit pieces, which can easily be | ||
// multiplied within Javascript's floating-point representation without overflow | ||
// or change in sign. | ||
// | ||
// In the algorithms below, we frequently reduce the negative case to the | ||
// positive case by negating the input(s) and then post-processing the result. | ||
// Note that we must ALWAYS check specially whether those values are MIN_VALUE | ||
// (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as | ||
// a positive number, it overflows back into a negative). Not handling this | ||
// case would often result in infinite recursion. | ||
// | ||
// Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from* | ||
// methods on which they depend. | ||
/** | ||
* @class A Long class for representing a 64 bit two's-complement integer value. | ||
*/ | ||
var Long = (function () { | ||
/** | ||
* Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers. | ||
* See the from* functions below for more convenient ways of constructing Longs. | ||
* @param {number} low The low (signed) 32 bits of the long | ||
* @param {number} high The high (signed) 32 bits of the long | ||
* @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed | ||
*/ | ||
function Long(low, high, unsigned) { | ||
/** | ||
* Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
this.eq = this.equals; | ||
/** | ||
* Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
this.neq = this.notEquals; | ||
/** | ||
* Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
this.lt = this.lessThan; | ||
/** | ||
* Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
this.lte = this.lessThanOrEqual; | ||
/** | ||
* Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
this.gt = this.greaterThan; | ||
/** | ||
* Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
this.gte = this.greaterThanOrEqual; | ||
/** | ||
* Compares this Long's value with the specified's. This is an alias of {@link Long#compare}. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {number} 0 if they are the same, 1 if the this is greater and -1 | ||
* if the given one is greater | ||
*/ | ||
this.comp = this.compare; | ||
/** | ||
* Negates this Long's value. This is an alias of {@link Long#negate}. | ||
* @returns {!Long} Negated Long | ||
*/ | ||
this.neg = this.negate; | ||
/** | ||
* Returns this Long's absolute value. This is an alias of {@link Long#absolute}. | ||
* @returns {!Long} Absolute Long | ||
*/ | ||
this.abs = this.absolute; | ||
/** | ||
* Returns the difference of this and the specified This is an alias of {@link Long#subtract}. | ||
* @param {!Long|number|string} subtrahend Subtrahend | ||
* @returns {!Long} Difference | ||
*/ | ||
this.sub = this.subtract; | ||
/** | ||
* Returns the product of this and the specified This is an alias of {@link Long#multiply}. | ||
* @param {!Long|number|string} multiplier Multiplier | ||
* @returns {!Long} Product | ||
*/ | ||
this.mul = this.multiply; | ||
/** | ||
* Returns this Long divided by the specified. This is an alias of {@link Long#divide}. | ||
* @param {!Long|number|string} divisor Divisor | ||
* @returns {!Long} Quotient | ||
*/ | ||
this.div = this.divide; | ||
/** | ||
* Returns this Long modulo the specified. This is an alias of {@link Long#modulo}. | ||
* @param {!Long|number|string} divisor Divisor | ||
* @returns {!Long} Remainder | ||
*/ | ||
this.mod = this.modulo; | ||
/** | ||
* Returns this Long with bits shifted to the left by the given amount. This is an alias of {@link Long#shiftLeft}. | ||
* @param {number|!Long} numBits Number of bits | ||
* @returns {!Long} Shifted Long | ||
*/ | ||
this.shl = this.shiftLeft; | ||
/** | ||
* Returns this Long with bits arithmetically shifted to the right by the given amount. This is an alias of {@link Long#shiftRight}. | ||
* @param {number|!Long} numBits Number of bits | ||
* @returns {!Long} Shifted Long | ||
*/ | ||
this.shr = this.shiftRight; | ||
/** | ||
* Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}. | ||
* @param {number|!Long} numBits Number of bits | ||
* @returns {!Long} Shifted Long | ||
*/ | ||
this.shru = this.shiftRightUnsigned; | ||
// Aliases for compatibility with Fable | ||
this.Equals = this.equals; | ||
this.CompareTo = this.compare; | ||
this.ToString = this.toString; | ||
this.low = low | 0; | ||
@@ -142,13 +36,5 @@ this.high = high | 0; | ||
} | ||
/** | ||
* Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. | ||
* @returns {number} | ||
*/ | ||
Long.prototype.toInt = function () { | ||
return this.unsigned ? this.low >>> 0 : this.low; | ||
}; | ||
/** | ||
* Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). | ||
* @returns {number} | ||
*/ | ||
Long.prototype.toNumber = function () { | ||
@@ -159,9 +45,2 @@ if (this.unsigned) | ||
}; | ||
/** | ||
* Converts the Long to a string written in the specified radix. | ||
* @param {number=} radix Radix (2-36), defaults to 10 | ||
* @returns {string} | ||
* @override | ||
* @throws {RangeError} If `radix` is out of range | ||
*/ | ||
Long.prototype.toString = function (radix) { | ||
@@ -176,4 +55,2 @@ if (radix === void 0) { radix = 10; } | ||
if (this.eq(exports.MIN_VALUE)) { | ||
// We need to change the Long value before it can be negated, so we remove | ||
// the bottom-most digit in this base and then recurse to do the rest. | ||
var radixLong = fromNumber(radix), div = this.div(radixLong), rem1 = div.mul(radixLong).sub(this); | ||
@@ -185,4 +62,2 @@ return div.toString(radix) + rem1.toInt().toString(radix); | ||
} | ||
// Do several (6) digits each time through the loop, so as to | ||
// minimize the calls to the very expensive emulated div. | ||
var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned), rem = this; | ||
@@ -202,34 +77,14 @@ var result = ''; | ||
}; | ||
/** | ||
* Gets the high 32 bits as a signed integer. | ||
* @returns {number} Signed high bits | ||
*/ | ||
Long.prototype.getHighBits = function () { | ||
return this.high; | ||
}; | ||
/** | ||
* Gets the high 32 bits as an unsigned integer. | ||
* @returns {number} Unsigned high bits | ||
*/ | ||
Long.prototype.getHighBitsUnsigned = function () { | ||
return this.high >>> 0; | ||
}; | ||
/** | ||
* Gets the low 32 bits as a signed integer. | ||
* @returns {number} Signed low bits | ||
*/ | ||
Long.prototype.getLowBits = function () { | ||
return this.low; | ||
}; | ||
/** | ||
* Gets the low 32 bits as an unsigned integer. | ||
* @returns {number} Unsigned low bits | ||
*/ | ||
Long.prototype.getLowBitsUnsigned = function () { | ||
return this.low >>> 0; | ||
}; | ||
/** | ||
* Gets the number of bits needed to represent the absolute value of this | ||
* @returns {number} | ||
*/ | ||
Long.prototype.getNumBitsAbs = function () { | ||
@@ -244,42 +99,17 @@ if (this.isNegative()) | ||
}; | ||
/** | ||
* Tests if this Long's value equals zero. | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.isZero = function () { | ||
return this.high === 0 && this.low === 0; | ||
}; | ||
/** | ||
* Tests if this Long's value is negative. | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.isNegative = function () { | ||
return !this.unsigned && this.high < 0; | ||
}; | ||
/** | ||
* Tests if this Long's value is positive. | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.isPositive = function () { | ||
return this.unsigned || this.high >= 0; | ||
}; | ||
/** | ||
* Tests if this Long's value is odd. | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.isOdd = function () { | ||
return (this.low & 1) === 1; | ||
}; | ||
/** | ||
* Tests if this Long's value is even. | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.isEven = function () { | ||
return (this.low & 1) === 0; | ||
}; | ||
/** | ||
* Tests if this Long's value equals the specified's. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.equals = function (other) { | ||
@@ -292,48 +122,17 @@ if (!isLong(other)) | ||
}; | ||
/** | ||
* Tests if this Long's value differs from the specified's. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.notEquals = function (other) { | ||
return !this.eq(/* validates */ other); | ||
return !this.eq(other); | ||
}; | ||
/** | ||
* Tests if this Long's value is less than the specified's. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.lessThan = function (other) { | ||
return this.comp(/* validates */ other) < 0; | ||
return this.comp(other) < 0; | ||
}; | ||
/** | ||
* Tests if this Long's value is less than or equal the specified's. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.lessThanOrEqual = function (other) { | ||
return this.comp(/* validates */ other) <= 0; | ||
return this.comp(other) <= 0; | ||
}; | ||
/** | ||
* Tests if this Long's value is greater than the specified's. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.greaterThan = function (other) { | ||
return this.comp(/* validates */ other) > 0; | ||
return this.comp(other) > 0; | ||
}; | ||
/** | ||
* Tests if this Long's value is greater than or equal the specified's. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {boolean} | ||
*/ | ||
Long.prototype.greaterThanOrEqual = function (other) { | ||
return this.comp(/* validates */ other) >= 0; | ||
return this.comp(other) >= 0; | ||
}; | ||
/** | ||
* Compares this Long's value with the specified's. | ||
* @param {!Long|number|string} other Other value | ||
* @returns {number} 0 if they are the same, 1 if the this is greater and -1 | ||
* if the given one is greater | ||
*/ | ||
Long.prototype.compare = function (other) { | ||
@@ -349,12 +148,6 @@ if (!isLong(other)) | ||
return 1; | ||
// At this point the sign bits are the same | ||
if (!this.unsigned) | ||
return this.sub(other).isNegative() ? -1 : 1; | ||
// Both are positive if at least one is unsigned | ||
return (other.high >>> 0) > (this.high >>> 0) || (other.high === this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1; | ||
}; | ||
/** | ||
* Negates this Long's value. | ||
* @returns {!Long} Negated Long | ||
*/ | ||
Long.prototype.negate = function () { | ||
@@ -365,6 +158,2 @@ if (!this.unsigned && this.eq(exports.MIN_VALUE)) | ||
}; | ||
/** | ||
* Returns this Long's absolute value. | ||
* @returns {!Long} Absolute Long | ||
*/ | ||
Long.prototype.absolute = function () { | ||
@@ -376,11 +165,5 @@ if (!this.unsigned && this.isNegative()) | ||
}; | ||
/** | ||
* Returns the sum of this and the specified | ||
* @param {!Long|number|string} addend Addend | ||
* @returns {!Long} Sum | ||
*/ | ||
Long.prototype.add = function (addend) { | ||
if (!isLong(addend)) | ||
addend = fromValue(addend); | ||
// Divide each number into 4 chunks of 16 bits, and then sum the chunks. | ||
var a48 = this.high >>> 16; | ||
@@ -408,7 +191,2 @@ var a32 = this.high & 0xFFFF; | ||
}; | ||
/** | ||
* Returns the difference of this and the specified | ||
* @param {!Long|number|string} subtrahend Subtrahend | ||
* @returns {!Long} Difference | ||
*/ | ||
Long.prototype.subtract = function (subtrahend) { | ||
@@ -419,7 +197,2 @@ if (!isLong(subtrahend)) | ||
}; | ||
/** | ||
* Returns the product of this and the specified | ||
* @param {!Long|number|string} multiplier Multiplier | ||
* @returns {!Long} Product | ||
*/ | ||
Long.prototype.multiply = function (multiplier) { | ||
@@ -444,7 +217,4 @@ if (this.isZero()) | ||
return this.mul(multiplier.neg()).neg(); | ||
// If both longs are small, use float multiplication | ||
if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24)) | ||
return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned); | ||
// Divide each long into 4 chunks of 16 bits, and then add up 4x4 products. | ||
// We can skip products that would overflow. | ||
var a48 = this.high >>> 16; | ||
@@ -481,8 +251,2 @@ var a32 = this.high & 0xFFFF; | ||
}; | ||
/** | ||
* Returns this Long divided by the specified. The result is signed if this Long is signed or | ||
* unsigned if this Long is unsigned. | ||
* @param {!Long|number|string} divisor Divisor | ||
* @returns {!Long} Quotient | ||
*/ | ||
Long.prototype.divide = function (divisor) { | ||
@@ -497,11 +261,8 @@ if (!isLong(divisor)) | ||
if (!this.unsigned) { | ||
// This section is only relevant for signed longs and is derived from the | ||
// closure library as a whole. | ||
if (this.eq(exports.MIN_VALUE)) { | ||
if (divisor.eq(exports.ONE) || divisor.eq(exports.NEG_ONE)) | ||
return exports.MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE | ||
return exports.MIN_VALUE; | ||
else if (divisor.eq(exports.MIN_VALUE)) | ||
return exports.ONE; | ||
else { | ||
// At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|. | ||
var halfThis = this.shr(1); | ||
@@ -531,4 +292,2 @@ var approx_1 = halfThis.div(divisor).shl(1); | ||
else { | ||
// The algorithm below has not been made for unsigned longs. It's therefore | ||
// required to take special care of the MSB prior to running it. | ||
if (!divisor.unsigned) | ||
@@ -542,18 +301,6 @@ divisor = divisor.toUnsigned(); | ||
} | ||
// Repeat the following until the remainder is less than other: find a | ||
// floating-point that approximates remainder / other *from below*, add this | ||
// into the result, and subtract it from the remainder. It is critical that | ||
// the approximate value is less than or equal to the real value so that the | ||
// remainder never becomes negative. | ||
rem = this; | ||
while (rem.gte(divisor)) { | ||
// Approximate the result of division. This may be a little greater or | ||
// smaller than the actual value. | ||
approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber())); | ||
// We will tweak the approximate result by changing it in the 48-th digit or | ||
// the smallest non-fractional digit, whichever is larger. | ||
var log2 = Math.ceil(Math.log(approx) / Math.LN2), delta = (log2 <= 48) ? 1 : pow_dbl(2, log2 - 48), | ||
// Decrease the approximation until it is smaller than the remainder. Note | ||
// that if it is too large, the product overflows and is negative. | ||
approxRes = fromNumber(approx), approxRem = approxRes.mul(divisor); | ||
var log2 = Math.ceil(Math.log(approx) / Math.LN2), delta = (log2 <= 48) ? 1 : pow_dbl(2, log2 - 48), approxRes = fromNumber(approx), approxRem = approxRes.mul(divisor); | ||
while (approxRem.isNegative() || approxRem.gt(rem)) { | ||
@@ -564,4 +311,2 @@ approx -= delta; | ||
} | ||
// We know the answer can't be zero... and actually, zero would cause | ||
// infinite recursion since we would make no progress. | ||
if (approxRes.isZero()) | ||
@@ -574,7 +319,2 @@ approxRes = exports.ONE; | ||
}; | ||
/** | ||
* Returns this Long modulo the specified. | ||
* @param {!Long|number|string} divisor Divisor | ||
* @returns {!Long} Remainder | ||
*/ | ||
Long.prototype.modulo = function (divisor) { | ||
@@ -586,6 +326,2 @@ if (!isLong(divisor)) | ||
; | ||
/** | ||
* Returns the bitwise NOT of this | ||
* @returns {!Long} | ||
*/ | ||
Long.prototype.not = function () { | ||
@@ -595,7 +331,2 @@ return fromBits(~this.low, ~this.high, this.unsigned); | ||
; | ||
/** | ||
* Returns the bitwise AND of this Long and the specified. | ||
* @param {!Long|number|string} other Other Long | ||
* @returns {!Long} | ||
*/ | ||
Long.prototype.and = function (other) { | ||
@@ -606,7 +337,2 @@ if (!isLong(other)) | ||
}; | ||
/** | ||
* Returns the bitwise OR of this Long and the specified. | ||
* @param {!Long|number|string} other Other Long | ||
* @returns {!Long} | ||
*/ | ||
Long.prototype.or = function (other) { | ||
@@ -617,7 +343,2 @@ if (!isLong(other)) | ||
}; | ||
/** | ||
* Returns the bitwise XOR of this Long and the given one. | ||
* @param {!Long|number|string} other Other Long | ||
* @returns {!Long} | ||
*/ | ||
Long.prototype.xor = function (other) { | ||
@@ -628,7 +349,2 @@ if (!isLong(other)) | ||
}; | ||
/** | ||
* Returns this Long with bits shifted to the left by the given amount. | ||
* @param {number|!Long} numBits Number of bits | ||
* @returns {!Long} Shifted Long | ||
*/ | ||
Long.prototype.shiftLeft = function (numBits) { | ||
@@ -645,7 +361,2 @@ if (isLong(numBits)) | ||
}; | ||
/** | ||
* Returns this Long with bits arithmetically shifted to the right by the given amount. | ||
* @param {number|!Long} numBits Number of bits | ||
* @returns {!Long} Shifted Long | ||
*/ | ||
Long.prototype.shiftRight = function (numBits) { | ||
@@ -662,7 +373,2 @@ if (isLong(numBits)) | ||
}; | ||
/** | ||
* Returns this Long with bits logically shifted to the right by the given amount. | ||
* @param {number|!Long} numBits Number of bits | ||
* @returns {!Long} Shifted Long | ||
*/ | ||
Long.prototype.shiftRightUnsigned = function (numBits) { | ||
@@ -686,6 +392,2 @@ if (isLong(numBits)) | ||
}; | ||
/** | ||
* Converts this Long to signed. | ||
* @returns {!Long} Signed long | ||
*/ | ||
Long.prototype.toSigned = function () { | ||
@@ -696,6 +398,2 @@ if (!this.unsigned) | ||
}; | ||
/** | ||
* Converts this Long to unsigned. | ||
* @returns {!Long} Unsigned long | ||
*/ | ||
Long.prototype.toUnsigned = function () { | ||
@@ -706,14 +404,5 @@ if (this.unsigned) | ||
}; | ||
/** | ||
* Converts this Long to its byte representation. | ||
* @param {boolean=} le Whether little or big endian, defaults to big endian | ||
* @returns {!Array.<number>} Byte representation | ||
*/ | ||
Long.prototype.toBytes = function (le) { | ||
return le ? this.toBytesLE() : this.toBytesBE(); | ||
}; | ||
/** | ||
* Converts this Long to its little endian byte representation. | ||
* @returns {!Array.<number>} Little endian byte representation | ||
*/ | ||
Long.prototype.toBytesLE = function () { | ||
@@ -732,6 +421,2 @@ var hi = this.high, lo = this.low; | ||
}; | ||
/** | ||
* Converts this Long to its big endian byte representation. | ||
* @returns {!Array.<number>} Big endian byte representation | ||
*/ | ||
Long.prototype.toBytesBE = function () { | ||
@@ -753,11 +438,4 @@ var hi = this.high, lo = this.low; | ||
exports.Long = Long; | ||
// A cache of the Long representations of small integer values. | ||
var INT_CACHE = {}; | ||
// A cache of the Long representations of small unsigned integer values. | ||
var UINT_CACHE = {}; | ||
/** | ||
* Tests if the specified object is a | ||
* @param {*} obj Object | ||
* @returns {boolean} | ||
*/ | ||
function isLong(obj) { | ||
@@ -767,8 +445,2 @@ return (obj && obj instanceof Long); | ||
exports.isLong = isLong; | ||
/** | ||
* Returns a Long representing the given 32 bit integer value. | ||
* @param {number} value The 32 bit integer in question | ||
* @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed | ||
* @returns {!Long} The corresponding Long value | ||
*/ | ||
function fromInt(value, unsigned) { | ||
@@ -803,8 +475,2 @@ if (unsigned === void 0) { unsigned = false; } | ||
exports.fromInt = fromInt; | ||
/** | ||
* Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned. | ||
* @param {number} value The number in question | ||
* @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed | ||
* @returns {!Long} The corresponding Long value | ||
*/ | ||
function fromNumber(value, unsigned) { | ||
@@ -831,10 +497,2 @@ if (unsigned === void 0) { unsigned = false; } | ||
exports.fromNumber = fromNumber; | ||
/** | ||
* Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is | ||
* assumed to use 32 bits. | ||
* @param {number} lowBits The low 32 bits | ||
* @param {number} highBits The high 32 bits | ||
* @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed | ||
* @returns {!Long} The corresponding Long value | ||
*/ | ||
function fromBits(lowBits, highBits, unsigned) { | ||
@@ -844,15 +502,3 @@ return new Long(lowBits, highBits, unsigned); | ||
exports.fromBits = fromBits; | ||
/** | ||
* @param {number} base | ||
* @param {number} exponent | ||
* @returns {number} | ||
*/ | ||
var pow_dbl = Math.pow; // Used 4 times (4*8 to 15+4) | ||
/** | ||
* Returns a Long representation of the given string, written using the specified radix. | ||
* @param {string} str The textual representation of the Long | ||
* @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to `false` for signed | ||
* @param {number=} radix The radix in which the text is written (2-36), defaults to 10 | ||
* @returns {!Long} The corresponding Long value | ||
*/ | ||
var pow_dbl = Math.pow; | ||
function fromString(str, unsigned, radix) { | ||
@@ -866,3 +512,2 @@ if (unsigned === void 0) { unsigned = false; } | ||
if (typeof unsigned === 'number') { | ||
// For goog.math.long compatibility | ||
radix = unsigned, | ||
@@ -883,4 +528,2 @@ unsigned = false; | ||
} | ||
// Do several (8) digits each time through the loop, so as to | ||
// minimize the calls to the very expensive emulated div. | ||
var radixToPower = fromNumber(pow_dbl(radix, 8)); | ||
@@ -903,9 +546,4 @@ var result = exports.ZERO; | ||
exports.fromString = fromString; | ||
/** | ||
* Converts the specified value to a | ||
* @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value | ||
* @returns {!Long} | ||
*/ | ||
function fromValue(val) { | ||
if (val /* is compatible */ instanceof Long) | ||
if (val instanceof Long) | ||
return val; | ||
@@ -916,8 +554,5 @@ if (typeof val === 'number') | ||
return fromString(val); | ||
// Throws for non-objects, converts non-instanceof Long: | ||
return fromBits(val.low, val.high, val.unsigned); | ||
} | ||
exports.fromValue = fromValue; | ||
// NOTE: the compiler should inline these constant values below and then remove these variables, so there should be | ||
// no runtime penalty for these. | ||
var TWO_PWR_16_DBL = 1 << 16; | ||
@@ -929,42 +564,10 @@ var TWO_PWR_24_DBL = 1 << 24; | ||
var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL); | ||
/** | ||
* Signed zero. | ||
* @type {!Long} | ||
*/ | ||
exports.ZERO = fromInt(0); | ||
/** | ||
* Unsigned zero. | ||
* @type {!Long} | ||
*/ | ||
exports.UZERO = fromInt(0, true); | ||
/** | ||
* Signed one. | ||
* @type {!Long} | ||
*/ | ||
exports.ONE = fromInt(1); | ||
/** | ||
* Unsigned one. | ||
* @type {!Long} | ||
*/ | ||
exports.UONE = fromInt(1, true); | ||
/** | ||
* Signed negative one. | ||
* @type {!Long} | ||
*/ | ||
exports.NEG_ONE = fromInt(-1); | ||
/** | ||
* Maximum signed value. | ||
* @type {!Long} | ||
*/ | ||
exports.MAX_VALUE = fromBits(0xFFFFFFFF | 0, 0x7FFFFFFF | 0, false); | ||
/** | ||
* Maximum unsigned value. | ||
* @type {!Long} | ||
*/ | ||
exports.MAX_UNSIGNED_VALUE = fromBits(0xFFFFFFFF | 0, 0xFFFFFFFF | 0, true); | ||
/** | ||
* Minimum signed value. | ||
* @type {!Long} | ||
*/ | ||
exports.MIN_VALUE = fromBits(0, 0x80000000 | 0, false); | ||
}); |
146
umd/Map.js
@@ -22,5 +22,2 @@ (function (dependencies, factory) { | ||
var Seq_5 = require("./Seq"); | ||
// ---------------------------------------------- | ||
// These functions belong to Seq.ts but are | ||
// implemented here to prevent cyclic dependencies | ||
function groupBy(f, xs) { | ||
@@ -212,7 +209,3 @@ var keys = [], iter = xs[Symbol.iterator](); | ||
function tree_filterAux(comparer, f, s, acc) { | ||
return s.Case === "MapOne" ? tree_filter1(comparer, f, s.Fields[0], s.Fields[1], acc) : s.Case === "MapNode" ? (function () { | ||
var acc_1 = tree_filterAux(comparer, f, s.Fields[2], acc); | ||
var acc_2 = tree_filter1(comparer, f, s.Fields[0], s.Fields[1], acc_1); | ||
return tree_filterAux(comparer, f, s.Fields[3], acc_2); | ||
})() : acc; | ||
return s.Case === "MapOne" ? tree_filter1(comparer, f, s.Fields[0], s.Fields[1], acc) : s.Case === "MapNode" ? tree_filterAux(comparer, f, s.Fields[3], tree_filter1(comparer, f, s.Fields[0], s.Fields[1], tree_filterAux(comparer, f, s.Fields[2], acc))) : acc; | ||
} | ||
@@ -281,3 +274,6 @@ function tree_filter(comparer, f, s) { | ||
function tree_mem(comparer, k, m) { | ||
return m.Case === "MapOne" ? comparer.Compare(k, m.Fields[0]) === 0 : m.Case === "MapNode" ? (function () { | ||
if (m.Case === "MapOne") { | ||
return comparer.Compare(k, m.Fields[0]) === 0; | ||
} | ||
else if (m.Case === "MapNode") { | ||
var c = comparer.Compare(k, m.Fields[0]); | ||
@@ -295,3 +291,6 @@ if (c < 0) { | ||
} | ||
})() : false; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
@@ -309,3 +308,6 @@ function tree_iter(f, m) { | ||
function tree_tryPick(f, m) { | ||
return m.Case === "MapOne" ? f(m.Fields[0], m.Fields[1]) : m.Case === "MapNode" ? (function () { | ||
if (m.Case === "MapOne") { | ||
return f(m.Fields[0], m.Fields[1]); | ||
} | ||
else if (m.Case === "MapNode") { | ||
var matchValue = tree_tryPick(f, m.Fields[2]); | ||
@@ -326,3 +328,6 @@ if (matchValue == null) { | ||
} | ||
})() : null; | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
@@ -335,70 +340,11 @@ function tree_exists(f, m) { | ||
} | ||
// function tree_map(f: (v:any) => any, m: MapTree): MapTree { | ||
// return m.Case === "MapOne" ? new MapTree("MapOne", [m.Fields[0], f(m.Fields[1])]) : m.Case === "MapNode" ? (() => { | ||
// var l2 = tree_map(f, m.Fields[2]); | ||
// var v2 = f(m.Fields[1]); | ||
// var r2 = tree_map(f, m.Fields[3]); | ||
// return new MapTree("MapNode", [m.Fields[0], v2, l2, r2, m.Fields[4]]); | ||
// })() : tree_empty(); | ||
// } | ||
function tree_mapi(f, m) { | ||
return m.Case === "MapOne" ? new MapTree("MapOne", [m.Fields[0], f(m.Fields[0], m.Fields[1])]) : m.Case === "MapNode" ? (function () { | ||
var l2 = tree_mapi(f, m.Fields[2]); | ||
var v2 = f(m.Fields[0], m.Fields[1]); | ||
var r2 = tree_mapi(f, m.Fields[3]); | ||
return new MapTree("MapNode", [m.Fields[0], v2, l2, r2, m.Fields[4]]); | ||
})() : tree_empty(); | ||
return m.Case === "MapOne" ? new MapTree("MapOne", [m.Fields[0], f(m.Fields[0], m.Fields[1])]) : m.Case === "MapNode" ? new MapTree("MapNode", [m.Fields[0], f(m.Fields[0], m.Fields[1]), tree_mapi(f, m.Fields[2]), tree_mapi(f, m.Fields[3]), m.Fields[4]]) : tree_empty(); | ||
} | ||
function tree_foldBack(f, m, x) { | ||
return m.Case === "MapOne" ? f(m.Fields[0], m.Fields[1], x) : m.Case === "MapNode" ? (function () { | ||
var x_1 = tree_foldBack(f, m.Fields[3], x); | ||
var x_2 = f(m.Fields[0], m.Fields[1], x_1); | ||
return tree_foldBack(f, m.Fields[2], x_2); | ||
})() : x; | ||
return m.Case === "MapOne" ? f(m.Fields[0], m.Fields[1], x) : m.Case === "MapNode" ? tree_foldBack(f, m.Fields[2], f(m.Fields[0], m.Fields[1], tree_foldBack(f, m.Fields[3], x))) : x; | ||
} | ||
function tree_fold(f, x, m) { | ||
return m.Case === "MapOne" ? f(x, m.Fields[0], m.Fields[1]) : m.Case === "MapNode" ? (function () { | ||
var x_1 = tree_fold(f, x, m.Fields[2]); | ||
var x_2 = f(x_1, m.Fields[0], m.Fields[1]); | ||
return tree_fold(f, x_2, m.Fields[3]); | ||
})() : x; | ||
return m.Case === "MapOne" ? f(x, m.Fields[0], m.Fields[1]) : m.Case === "MapNode" ? tree_fold(f, f(tree_fold(f, x, m.Fields[2]), m.Fields[0], m.Fields[1]), m.Fields[3]) : x; | ||
} | ||
// function tree_foldFromTo(comparer: IComparer<any>, lo: any, hi: any, f: (k:any, v:any, acc: any) => any, m: MapTree, x: any): any { | ||
// if (m.Case === "MapOne") { | ||
// var cLoKey = comparer.Compare(lo, m.Fields[0]); | ||
// var cKeyHi = comparer.Compare(m.Fields[0], hi); | ||
// var x_1 = (cLoKey <= 0 ? cKeyHi <= 0 : false) ? f(m.Fields[0], m.Fields[1], x) : x; | ||
// return x_1; | ||
// } | ||
// else if (m.Case === "MapNode") { | ||
// var cLoKey = comparer.Compare(lo, m.Fields[0]); | ||
// var cKeyHi = comparer.Compare(m.Fields[0], hi); | ||
// var x_1 = cLoKey < 0 ? tree_foldFromTo(comparer, lo, hi, f, m.Fields[2], x) : x; | ||
// var x_2 = (cLoKey <= 0 ? cKeyHi <= 0 : false) ? f(m.Fields[0], m.Fields[1], x_1) : x_1; | ||
// var x_3 = cKeyHi < 0 ? tree_foldFromTo(comparer, lo, hi, f, m.Fields[3], x_2) : x_2; | ||
// return x_3; | ||
// } | ||
// return x; | ||
// } | ||
// function tree_foldSection(comparer: IComparer<any>, lo: any, hi: any, f: (k:any, v:any, acc: any) => any, m: MapTree, x: any) { | ||
// return comparer.Compare(lo, hi) === 1 ? x : tree_foldFromTo(comparer, lo, hi, f, m, x); | ||
// } | ||
// function tree_loop(m: MapTree, acc: any): List<[any,any]> { | ||
// return m.Case === "MapOne" | ||
// ? new List([m.Fields[0], m.Fields[1]], acc) | ||
// : m.Case === "MapNode" | ||
// ? tree_loop(m.Fields[2], new List([m.Fields[0], m.Fields[1]], tree_loop(m.Fields[3], acc))) | ||
// : acc; | ||
// } | ||
// function tree_toList(m: MapTree) { | ||
// return tree_loop(m, new List()); | ||
// } | ||
// function tree_toArray(m: MapTree) { | ||
// return Array.from(tree_toList(m)); | ||
// } | ||
// function tree_ofList(comparer: IComparer<any>, l: List<[any,any]>) { | ||
// return Seq.fold((acc: MapTree, tupledArg: [any, any]) => { | ||
// return tree_add(comparer, tupledArg[0], tupledArg[1], acc); | ||
// }, tree_empty(), l); | ||
// } | ||
function tree_mkFromEnumerator(comparer, acc, e) { | ||
@@ -412,9 +358,2 @@ var cur = e.next(); | ||
} | ||
// function tree_ofArray(comparer: IComparer<any>, arr: ArrayLike<[any,any]>) { | ||
// var res = tree_empty(); | ||
// for (var i = 0; i <= arr.length - 1; i++) { | ||
// res = tree_add(comparer, arr[i][0], arr[i][1], res); | ||
// } | ||
// return res; | ||
// } | ||
function tree_ofSeq(comparer, c) { | ||
@@ -424,5 +363,2 @@ var ie = c[Symbol.iterator](); | ||
} | ||
// function tree_copyToArray(s: MapTree, arr: ArrayLike<any>, i: number) { | ||
// tree_iter((x, y) => { arr[i++] = [x, y]; }, s); | ||
// } | ||
function tree_collapseLHS(stack) { | ||
@@ -487,13 +423,12 @@ if (stack.tail != null) { | ||
} | ||
var FMap = (function () { | ||
/** Do not call, use Map.create instead. */ | ||
function FMap() { | ||
var FableMap = (function () { | ||
function FableMap() { | ||
} | ||
FMap.prototype.ToString = function () { | ||
FableMap.prototype.ToString = function () { | ||
return "map [" + Array.from(this).map(Util_1.toString).join("; ") + "]"; | ||
}; | ||
FMap.prototype.Equals = function (m2) { | ||
FableMap.prototype.Equals = function (m2) { | ||
return this.CompareTo(m2) === 0; | ||
}; | ||
FMap.prototype.CompareTo = function (m2) { | ||
FableMap.prototype.CompareTo = function (m2) { | ||
var _this = this; | ||
@@ -505,3 +440,3 @@ return this === m2 ? 0 : Seq_5.compareWith(function (kvp1, kvp2) { | ||
}; | ||
FMap.prototype[Symbol.iterator] = function () { | ||
FableMap.prototype[Symbol.iterator] = function () { | ||
var i = tree_mkIterator(this.tree); | ||
@@ -512,30 +447,27 @@ return { | ||
}; | ||
FMap.prototype.entries = function () { | ||
FableMap.prototype.entries = function () { | ||
return this[Symbol.iterator](); | ||
}; | ||
FMap.prototype.keys = function () { | ||
FableMap.prototype.keys = function () { | ||
return Seq_1.map(function (kv) { return kv[0]; }, this); | ||
}; | ||
FMap.prototype.values = function () { | ||
FableMap.prototype.values = function () { | ||
return Seq_1.map(function (kv) { return kv[1]; }, this); | ||
}; | ||
FMap.prototype.get = function (k) { | ||
FableMap.prototype.get = function (k) { | ||
return tree_find(this.comparer, k, this.tree); | ||
}; | ||
FMap.prototype.has = function (k) { | ||
FableMap.prototype.has = function (k) { | ||
return tree_mem(this.comparer, k, this.tree); | ||
}; | ||
/** Not supported */ | ||
FMap.prototype.set = function (k, v) { | ||
FableMap.prototype.set = function (k, v) { | ||
throw new Error("not supported"); | ||
}; | ||
/** Not supported */ | ||
FMap.prototype.delete = function (k) { | ||
FableMap.prototype.delete = function (k) { | ||
throw new Error("not supported"); | ||
}; | ||
/** Not supported */ | ||
FMap.prototype.clear = function () { | ||
FableMap.prototype.clear = function () { | ||
throw new Error("not supported"); | ||
}; | ||
Object.defineProperty(FMap.prototype, "size", { | ||
Object.defineProperty(FableMap.prototype, "size", { | ||
get: function () { | ||
@@ -547,3 +479,3 @@ return tree_size(this.tree); | ||
}); | ||
FMap.prototype[Symbol_1.default.reflection] = function () { | ||
FableMap.prototype[Symbol_1.default.reflection] = function () { | ||
return { | ||
@@ -554,8 +486,8 @@ type: "Microsoft.FSharp.Collections.FSharpMap", | ||
}; | ||
return FMap; | ||
return FableMap; | ||
}()); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = FMap; | ||
exports.default = FableMap; | ||
function from(comparer, tree) { | ||
var map = new FMap(); | ||
var map = new FableMap(); | ||
map.tree = tree; | ||
@@ -562,0 +494,0 @@ map.comparer = comparer || new GenericComparer_1.default(); |
@@ -52,3 +52,2 @@ (function (dependencies, factory) { | ||
exports.getType = getType; | ||
// TODO: This needs improvement, check namespace for non-custom types? | ||
function getTypeFullName(typ, option) { | ||
@@ -91,3 +90,2 @@ function trim(fullName, option) { | ||
else { | ||
// Attention: this doesn't work with Object.getPrototypeOf | ||
var proto = typ.prototype; | ||
@@ -94,0 +92,0 @@ return trim(typeof proto[Symbol_1.default.reflection] === "function" |
@@ -17,3 +17,2 @@ (function (dependencies, factory) { | ||
exports.create = create; | ||
// From http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex | ||
function escape(str) { | ||
@@ -49,3 +48,3 @@ return str.replace(/[\-\[\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); | ||
if (!reg.global) | ||
throw new Error("Non-global RegExp"); // Prevent infinite loop | ||
throw new Error("Non-global RegExp"); | ||
var m; | ||
@@ -59,3 +58,3 @@ var matches = []; | ||
function options(reg) { | ||
var options = 256; // ECMAScript | ||
var options = 256; | ||
options |= reg.ignoreCase ? 1 : 0; | ||
@@ -62,0 +61,0 @@ options |= reg.multiline ? 2 : 0; |
@@ -410,3 +410,2 @@ (function (dependencies, factory) { | ||
exports.last = last; | ||
// A export function 'length' method causes problems in JavaScript -- https://github.com/Microsoft/TypeScript/issues/442 | ||
function count(xs) { | ||
@@ -413,0 +412,0 @@ return Array.isArray(xs) || ArrayBuffer.isView(xs) |
@@ -50,3 +50,2 @@ (function (dependencies, factory) { | ||
else if (v.Fields.length === 1) { | ||
// Prevent undefined assignment from removing case property; see #611: | ||
var fieldValue = typeof v.Fields[0] === 'undefined' ? null : v.Fields[0]; | ||
@@ -95,3 +94,3 @@ return _a = {}, _a[v.Case] = fieldValue, _a; | ||
case "Array": | ||
return needsInflate(new List_1.default(typ.generics, enclosing)); | ||
return typ.definition != null || needsInflate(new List_1.default(typ.generics, enclosing)); | ||
case "Tuple": | ||
@@ -115,3 +114,2 @@ return typ.generics.some(function (x) { | ||
} | ||
// TODO: Validate non-inflated elements | ||
return needsInflate(enclosing) | ||
@@ -172,3 +170,8 @@ ? arr.map(function (x, i) { return inflate(x, enclosing, combine(path, i)); }) | ||
case "Array": | ||
return inflateArray(val, new List_1.default(typ.generics, enclosing), path); | ||
if (typ.definition != null) { | ||
return new typ.definition(val); | ||
} | ||
else { | ||
return inflateArray(val, new List_1.default(typ.generics, enclosing), path); | ||
} | ||
case "Tuple": | ||
@@ -187,3 +190,2 @@ return typ.generics.map(function (x, i) { | ||
} | ||
// TODO: Should we try to inflate also sets and maps serialized with `JSON.stringify`? | ||
if (def === Set_1.default) { | ||
@@ -211,6 +213,4 @@ return Set_2.create(inflateArray(val, Reflection_1.resolveGeneric(0, enclosing), path)); | ||
var info = typeof typ.prototype[Symbol_1.default.reflection] === "function" ? typ.prototype[Symbol_1.default.reflection]() : {}; | ||
// Union types | ||
if (info.cases) { | ||
var uCase = void 0, uFields = []; | ||
// Cases withouth fields are serialized as strings by `toJson` | ||
if (typeof val === "string") { | ||
@@ -235,3 +235,2 @@ uCase = val; | ||
} | ||
// Validate | ||
if (uCase in info.cases === false) { | ||
@@ -243,3 +242,3 @@ invalidate(val, typ, path); | ||
if (info.properties) { | ||
var temp = {}; | ||
var newObj = new typ(); | ||
var properties = info.properties; | ||
@@ -249,5 +248,5 @@ var ks = Object.getOwnPropertyNames(properties); | ||
var k = ks[i]; | ||
temp[k] = inflate(val[k], new List_1.default(properties[k], enclosing), combine(path, k)); | ||
newObj[k] = inflate(val[k], new List_1.default(properties[k], enclosing), combine(path, k)); | ||
} | ||
return Object.assign(new typ(), temp); | ||
return newObj; | ||
} | ||
@@ -306,3 +305,2 @@ return val; | ||
else if (typeof v === "object" && typeof v.$type === "string") { | ||
// Remove generic args and assembly info added by Newtonsoft.Json | ||
var type = v.$type.replace('+', '.'), i = type.indexOf('`'); | ||
@@ -309,0 +307,0 @@ if (i > -1) { |
265
umd/Set.js
@@ -22,5 +22,2 @@ (function (dependencies, factory) { | ||
var Seq_7 = require("./Seq"); | ||
// ---------------------------------------------- | ||
// These functions belong to Seq.ts but are | ||
// implemented here to prevent cyclic dependencies | ||
function distinctBy(f, xs) { | ||
@@ -128,3 +125,3 @@ return Seq_6.choose(function (tup) { return tup[0]; }, Seq_7.scan(function (tup, x) { | ||
function tree_add(comparer, k, t) { | ||
return t.Case === "SetOne" ? (function () { | ||
if (t.Case === "SetOne") { | ||
var c = comparer.Compare(k, t.Fields[0]); | ||
@@ -134,11 +131,13 @@ if (c < 0) { | ||
} | ||
else if (c === 0) { | ||
return t; | ||
} | ||
else { | ||
if (c === 0) { | ||
return t; | ||
} | ||
else { | ||
return tree_SetNode(k, t, new SetTree("SetEmpty", []), 2); | ||
} | ||
return tree_SetNode(k, t, new SetTree("SetEmpty", []), 2); | ||
} | ||
})() : t.Case === "SetEmpty" ? tree_SetOne(k) : (function () { | ||
} | ||
else if (t.Case === "SetEmpty") { | ||
return tree_SetOne(k); | ||
} | ||
else { | ||
var c = comparer.Compare(k, t.Fields[0]); | ||
@@ -148,11 +147,9 @@ if (c < 0) { | ||
} | ||
else if (c === 0) { | ||
return t; | ||
} | ||
else { | ||
if (c === 0) { | ||
return t; | ||
} | ||
else { | ||
return tree_rebalance(t.Fields[1], t.Fields[0], tree_add(comparer, k, t.Fields[2])); | ||
} | ||
return tree_rebalance(t.Fields[1], t.Fields[0], tree_add(comparer, k, t.Fields[2])); | ||
} | ||
})(); | ||
} | ||
} | ||
@@ -217,3 +214,3 @@ function tree_balance(comparer, t1, k, t2) { | ||
function tree_split(comparer, pivot, t) { | ||
return t.Case === "SetOne" ? (function () { | ||
if (t.Case === "SetOne") { | ||
var c = comparer.Compare(t.Fields[0], pivot); | ||
@@ -223,45 +220,46 @@ if (c < 0) { | ||
} | ||
else if (c === 0) { | ||
return [new SetTree("SetEmpty", []), true, new SetTree("SetEmpty", [])]; | ||
} | ||
else { | ||
if (c === 0) { | ||
return [new SetTree("SetEmpty", []), true, new SetTree("SetEmpty", [])]; | ||
} | ||
else { | ||
return [new SetTree("SetEmpty", []), false, t]; | ||
} | ||
return [new SetTree("SetEmpty", []), false, t]; | ||
} | ||
})() : t.Case === "SetEmpty" ? [new SetTree("SetEmpty", []), false, new SetTree("SetEmpty", [])] : (function () { | ||
} | ||
else if (t.Case === "SetEmpty") { | ||
return [new SetTree("SetEmpty", []), false, new SetTree("SetEmpty", [])]; | ||
} | ||
else { | ||
var c = comparer.Compare(pivot, t.Fields[0]); | ||
if (c < 0) { | ||
var patternInput = tree_split(comparer, pivot, t.Fields[1]); | ||
var t11Lo = patternInput[0]; | ||
var t11Hi = patternInput[2]; | ||
var havePivot = patternInput[1]; | ||
return [t11Lo, havePivot, tree_balance(comparer, t11Hi, t.Fields[0], t.Fields[2])]; | ||
return [patternInput[0], patternInput[1], tree_balance(comparer, patternInput[2], t.Fields[0], t.Fields[2])]; | ||
} | ||
else if (c === 0) { | ||
return [t.Fields[1], true, t.Fields[2]]; | ||
} | ||
else { | ||
if (c === 0) { | ||
return [t.Fields[1], true, t.Fields[2]]; | ||
} | ||
else { | ||
var patternInput = tree_split(comparer, pivot, t.Fields[2]); | ||
var t12Lo = patternInput[0]; | ||
var t12Hi = patternInput[2]; | ||
var havePivot = patternInput[1]; | ||
return [tree_balance(comparer, t.Fields[1], t.Fields[0], t12Lo), havePivot, t12Hi]; | ||
} | ||
var patternInput = tree_split(comparer, pivot, t.Fields[2]); | ||
return [tree_balance(comparer, t.Fields[1], t.Fields[0], patternInput[0]), patternInput[1], patternInput[2]]; | ||
} | ||
})(); | ||
} | ||
} | ||
function tree_spliceOutSuccessor(t) { | ||
return t.Case === "SetOne" ? [t.Fields[0], new SetTree("SetEmpty", [])] : t.Case === "SetNode" ? t.Fields[1].Case === "SetEmpty" ? [t.Fields[0], t.Fields[2]] : (function () { | ||
var patternInput = tree_spliceOutSuccessor(t.Fields[1]); | ||
var l_ = patternInput[1]; | ||
var k3 = patternInput[0]; | ||
return [k3, tree_mk(l_, t.Fields[0], t.Fields[2])]; | ||
})() : (function () { | ||
if (t.Case === "SetOne") { | ||
return [t.Fields[0], new SetTree("SetEmpty", [])]; | ||
} | ||
else if (t.Case === "SetNode") { | ||
if (t.Fields[1].Case === "SetEmpty") { | ||
return [t.Fields[0], t.Fields[2]]; | ||
} | ||
else { | ||
var patternInput = tree_spliceOutSuccessor(t.Fields[1]); | ||
return [patternInput[0], tree_mk(patternInput[1], t.Fields[0], t.Fields[2])]; | ||
} | ||
} | ||
else { | ||
throw new Error("internal error: Map.spliceOutSuccessor"); | ||
})(); | ||
} | ||
} | ||
function tree_remove(comparer, k, t) { | ||
return t.Case === "SetOne" ? (function () { | ||
if (t.Case === "SetOne") { | ||
var c = comparer.Compare(k, t.Fields[0]); | ||
@@ -274,3 +272,4 @@ if (c === 0) { | ||
} | ||
})() : t.Case === "SetNode" ? (function () { | ||
} | ||
else if (t.Case === "SetNode") { | ||
var c = comparer.Compare(k, t.Fields[0]); | ||
@@ -280,28 +279,31 @@ if (c < 0) { | ||
} | ||
else { | ||
if (c === 0) { | ||
var matchValue = [t.Fields[1], t.Fields[2]]; | ||
if (matchValue[0].Case === "SetEmpty") { | ||
return t.Fields[2]; | ||
} | ||
else { | ||
if (matchValue[1].Case === "SetEmpty") { | ||
return t.Fields[1]; | ||
} | ||
else { | ||
var patternInput = tree_spliceOutSuccessor(t.Fields[2]); | ||
var sk = patternInput[0]; | ||
var r_ = patternInput[1]; | ||
return tree_mk(t.Fields[1], sk, r_); | ||
} | ||
} | ||
else if (c === 0) { | ||
var matchValue = [t.Fields[1], t.Fields[2]]; | ||
if (matchValue[0].Case === "SetEmpty") { | ||
return t.Fields[2]; | ||
} | ||
else if (matchValue[1].Case === "SetEmpty") { | ||
return t.Fields[1]; | ||
} | ||
else { | ||
return tree_rebalance(t.Fields[1], t.Fields[0], tree_remove(comparer, k, t.Fields[2])); | ||
var patternInput = tree_spliceOutSuccessor(t.Fields[2]); | ||
return tree_mk(t.Fields[1], patternInput[0], patternInput[1]); | ||
} | ||
} | ||
})() : t; | ||
else { | ||
return tree_rebalance(t.Fields[1], t.Fields[0], tree_remove(comparer, k, t.Fields[2])); | ||
} | ||
} | ||
else { | ||
return t; | ||
} | ||
} | ||
function tree_mem(comparer, k, t) { | ||
return t.Case === "SetOne" ? comparer.Compare(k, t.Fields[0]) === 0 : t.Case === "SetEmpty" ? false : (function () { | ||
if (t.Case === "SetOne") { | ||
return comparer.Compare(k, t.Fields[0]) === 0; | ||
} | ||
else if (t.Case === "SetEmpty") { | ||
return false; | ||
} | ||
else { | ||
var c = comparer.Compare(k, t.Fields[0]); | ||
@@ -311,11 +313,9 @@ if (c < 0) { | ||
} | ||
else if (c === 0) { | ||
return true; | ||
} | ||
else { | ||
if (c === 0) { | ||
return true; | ||
} | ||
else { | ||
return tree_mem(comparer, k, t.Fields[2]); | ||
} | ||
return tree_mem(comparer, k, t.Fields[2]); | ||
} | ||
})(); | ||
} | ||
} | ||
@@ -339,7 +339,13 @@ function tree_iter(f, t) { | ||
function tree_fold(f, x, m) { | ||
return m.Case === "SetOne" ? f(x, m.Fields[0]) : m.Case === "SetEmpty" ? x : (function () { | ||
if (m.Case === "SetOne") { | ||
return f(x, m.Fields[0]); | ||
} | ||
else if (m.Case === "SetEmpty") { | ||
return x; | ||
} | ||
else { | ||
var x_1 = tree_fold(f, x, m.Fields[1]); | ||
var x_2 = f(x_1, m.Fields[0]); | ||
return tree_fold(f, x_2, m.Fields[2]); | ||
})(); | ||
} | ||
} | ||
@@ -362,6 +368,17 @@ function tree_forall(f, m) { | ||
function tree_filterAux(comparer, f, s, acc) { | ||
return s.Case === "SetOne" ? f(s.Fields[0]) ? tree_add(comparer, s.Fields[0], acc) : acc : s.Case === "SetEmpty" ? acc : (function () { | ||
if (s.Case === "SetOne") { | ||
if (f(s.Fields[0])) { | ||
return tree_add(comparer, s.Fields[0], acc); | ||
} | ||
else { | ||
return acc; | ||
} | ||
} | ||
else if (s.Case === "SetEmpty") { | ||
return acc; | ||
} | ||
else { | ||
var acc_1 = f(s.Fields[0]) ? tree_add(comparer, s.Fields[0], acc) : acc; | ||
return tree_filterAux(comparer, f, s.Fields[1], tree_filterAux(comparer, f, s.Fields[2], acc_1)); | ||
})(); | ||
} | ||
} | ||
@@ -436,7 +453,18 @@ function tree_filter(comparer, f, s) { | ||
function tree_intersectionAux(comparer, b, m, acc) { | ||
return m.Case === "SetOne" ? tree_mem(comparer, m.Fields[0], b) ? tree_add(comparer, m.Fields[0], acc) : acc : m.Case === "SetEmpty" ? acc : (function () { | ||
if (m.Case === "SetOne") { | ||
if (tree_mem(comparer, m.Fields[0], b)) { | ||
return tree_add(comparer, m.Fields[0], acc); | ||
} | ||
else { | ||
return acc; | ||
} | ||
} | ||
else if (m.Case === "SetEmpty") { | ||
return acc; | ||
} | ||
else { | ||
var acc_1 = tree_intersectionAux(comparer, b, m.Fields[2], acc); | ||
var acc_2 = tree_mem(comparer, m.Fields[0], b) ? tree_add(comparer, m.Fields[0], acc_1) : acc_1; | ||
return tree_intersectionAux(comparer, b, m.Fields[1], acc_2); | ||
})(); | ||
} | ||
} | ||
@@ -461,15 +489,5 @@ function tree_intersection(comparer, a, b) { | ||
else { | ||
var acc_2 = (function () { | ||
var arg30_ = acc[0]; | ||
var arg31_ = acc[1]; | ||
return tree_partitionAux(comparer, f, s.Fields[2], arg30_, arg31_); | ||
})(); | ||
var acc_3 = (function () { | ||
var acc1 = acc_2[0]; | ||
var acc2 = acc_2[1]; | ||
return tree_partition1(comparer, f, s.Fields[0], acc1, acc2); | ||
})(); | ||
var arg30_ = acc_3[0]; | ||
var arg31_ = acc_3[1]; | ||
return tree_partitionAux(comparer, f, s.Fields[1], arg30_, arg31_); | ||
var acc_2 = tree_partitionAux(comparer, f, s.Fields[2], acc[0], acc[1]); | ||
var acc_3 = tree_partition1(comparer, f, s.Fields[0], acc_2[0], acc_2[1]); | ||
return tree_partitionAux(comparer, f, s.Fields[1], acc_3[0], acc_3[1]); | ||
} | ||
@@ -484,5 +502,2 @@ } | ||
} | ||
// function tree_$MatchSetNode$MatchSetEmpty$(s: SetTree) { | ||
// return s.Case === "SetOne" ? new Choice("Choice1Of2", [[s.Fields[0], new SetTree("SetEmpty", []), new SetTree("SetEmpty", [])]]) : s.Case === "SetEmpty" ? new Choice("Choice2Of2", [null]) : new Choice("Choice1Of2", [[s.Fields[0], s.Fields[1], s.Fields[2]]]); | ||
// } | ||
function tree_minimumElementAux(s, n) { | ||
@@ -535,8 +550,2 @@ return s.Case === "SetOne" ? s.Fields[0] : s.Case === "SetEmpty" ? n : tree_minimumElementAux(s.Fields[1], s.Fields[0]); | ||
; | ||
// function tree_notStarted() { | ||
// throw new Error("Enumeration not started"); | ||
// }; | ||
// var alreadyFinished = $exports.alreadyFinished = function () { | ||
// throw new Error("Enumeration already started"); | ||
// }; | ||
function tree_moveNext(i) { | ||
@@ -719,16 +728,15 @@ function current(i) { | ||
} | ||
var FSet = (function () { | ||
/** Do not call, use Set.create instead. */ | ||
function FSet() { | ||
var FableSet = (function () { | ||
function FableSet() { | ||
} | ||
FSet.prototype.ToString = function () { | ||
FableSet.prototype.ToString = function () { | ||
return "set [" + Array.from(this).map(Util_1.toString).join("; ") + "]"; | ||
}; | ||
FSet.prototype.Equals = function (s2) { | ||
FableSet.prototype.Equals = function (s2) { | ||
return this.CompareTo(s2) === 0; | ||
}; | ||
FSet.prototype.CompareTo = function (s2) { | ||
FableSet.prototype.CompareTo = function (s2) { | ||
return this === s2 ? 0 : tree_compare(this.comparer, this.tree, s2.tree); | ||
}; | ||
FSet.prototype[Symbol.iterator] = function () { | ||
FableSet.prototype[Symbol.iterator] = function () { | ||
var i = tree_mkIterator(this.tree); | ||
@@ -739,21 +747,18 @@ return { | ||
}; | ||
FSet.prototype.values = function () { | ||
FableSet.prototype.values = function () { | ||
return this[Symbol.iterator](); | ||
}; | ||
FSet.prototype.has = function (v) { | ||
FableSet.prototype.has = function (v) { | ||
return tree_mem(this.comparer, v, this.tree); | ||
}; | ||
/** Not supported */ | ||
FSet.prototype.add = function (v) { | ||
FableSet.prototype.add = function (v) { | ||
throw new Error("not supported"); | ||
}; | ||
/** Not supported */ | ||
FSet.prototype.delete = function (v) { | ||
FableSet.prototype.delete = function (v) { | ||
throw new Error("not supported"); | ||
}; | ||
/** Not supported */ | ||
FSet.prototype.clear = function () { | ||
FableSet.prototype.clear = function () { | ||
throw new Error("not supported"); | ||
}; | ||
Object.defineProperty(FSet.prototype, "size", { | ||
Object.defineProperty(FableSet.prototype, "size", { | ||
get: function () { | ||
@@ -765,3 +770,3 @@ return tree_count(this.tree); | ||
}); | ||
FSet.prototype[Symbol_1.default.reflection] = function () { | ||
FableSet.prototype[Symbol_1.default.reflection] = function () { | ||
return { | ||
@@ -772,8 +777,8 @@ type: "Microsoft.FSharp.Collections.FSharpSet", | ||
}; | ||
return FSet; | ||
return FableSet; | ||
}()); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = FSet; | ||
exports.default = FableSet; | ||
function from(comparer, tree) { | ||
var s = new FSet(); | ||
var s = new FableSet(); | ||
s.tree = tree; | ||
@@ -821,4 +826,2 @@ s.comparer = comparer || new GenericComparer_1.default(); | ||
function unionMany(sets) { | ||
// Pass args as union(s, acc) instead of union(acc, s) | ||
// to discard the comparer of the first empty set | ||
return Seq_2.fold(function (acc, s) { return union(s, acc); }, create(), sets); | ||
@@ -863,3 +866,3 @@ } | ||
function isProperSubsetOf(set1, set2) { | ||
if (set1 instanceof FSet && set2 instanceof FSet) { | ||
if (set1 instanceof FableSet && set2 instanceof FableSet) { | ||
return tree_psubset(set1.comparer, set1.tree, set2.tree); | ||
@@ -878,3 +881,3 @@ } | ||
function isSubsetOf(set1, set2) { | ||
if (set1 instanceof FSet && set2 instanceof FSet) { | ||
if (set1 instanceof FableSet && set2 instanceof FableSet) { | ||
return tree_subset(set1.comparer, set1.tree, set2.tree); | ||
@@ -893,3 +896,3 @@ } | ||
function isProperSupersetOf(set1, set2) { | ||
if (set1 instanceof FSet && set2 instanceof FSet) { | ||
if (set1 instanceof FableSet && set2 instanceof FableSet) { | ||
return tree_psubset(set1.comparer, set2.tree, set1.tree); | ||
@@ -907,3 +910,3 @@ } | ||
function isSupersetOf(set1, set2) { | ||
if (set1 instanceof FSet && set2 instanceof FSet) { | ||
if (set1 instanceof FableSet && set2 instanceof FableSet) { | ||
return tree_subset(set1.comparer, set2.tree, set1.tree); | ||
@@ -910,0 +913,0 @@ } |
@@ -43,3 +43,3 @@ (function (dependencies, factory) { | ||
if (y == null) | ||
return 1; // everything is bigger than null | ||
return 1; | ||
if (isOrdinal(ic)) { | ||
@@ -145,3 +145,2 @@ if (isIgnoreCase(ic)) { | ||
catch (err) { | ||
// Fallback for objects with circular references | ||
rep = "{" + Object.getOwnPropertyNames(rep).map(function (k) { return k + ": " + String(rep[k]); }).join(", ") + "}"; | ||
@@ -249,3 +248,3 @@ } | ||
case "O": | ||
if (rep.kind === 2 /* Local */) { | ||
if (rep.kind === 2) { | ||
var offset = rep.getTimezoneOffset() * -1; | ||
@@ -252,0 +251,0 @@ rep = format("{0:yyyy-MM-dd}T{0:HH:mm}:{1:00.000}{2}{3:00}:{4:00}", rep, Date_1.second(rep), offset >= 0 ? "+" : "-", ~~(offset / 60), offset % 60); |
@@ -20,10 +20,7 @@ (function (dependencies, factory) { | ||
case 1: | ||
// ticks | ||
return fromTicks(arguments[0]); | ||
case 3: | ||
// h,m,s | ||
d = 0, h = arguments[0], m = arguments[1], s = arguments[2], ms = 0; | ||
break; | ||
default: | ||
// d,h,m,s,ms | ||
d = arguments[0], h = arguments[1], m = arguments[2], s = arguments[3], ms = arguments[4] || 0; | ||
@@ -30,0 +27,0 @@ break; |
@@ -31,11 +31,19 @@ (function (dependencies, factory) { | ||
function Option(t) { | ||
return new NonDeclaredType("Option", "Option", t); | ||
return new NonDeclaredType("Option", null, t); | ||
} | ||
exports.Option = Option; | ||
function FArray(t) { | ||
return new NonDeclaredType("Array", "Array", t); | ||
function FableArray(t, isTypedArray) { | ||
if (isTypedArray === void 0) { isTypedArray = false; } | ||
var def = null, genArg = null; | ||
if (isTypedArray) { | ||
def = t; | ||
} | ||
else { | ||
genArg = t; | ||
} | ||
return new NonDeclaredType("Array", def, genArg); | ||
} | ||
exports.Array = FArray; | ||
exports.Array = FableArray; | ||
function Tuple(ts) { | ||
return new NonDeclaredType("Tuple", "Tuple", ts); | ||
return new NonDeclaredType("Tuple", null, ts); | ||
} | ||
@@ -59,6 +67,2 @@ exports.Tuple = Tuple; | ||
exports.isGeneric = isGeneric; | ||
/** | ||
* Returns the parent if this is a declared generic type or the argument otherwise. | ||
* Attention: Unlike .NET this doesn't throw an exception if type is not generic. | ||
*/ | ||
function getDefinition(typ) { | ||
@@ -123,3 +127,2 @@ return isGeneric(typ) ? typ.definition : typ; | ||
function equals(x, y) { | ||
// Optimization if they are referencially equal | ||
if (x === y) | ||
@@ -159,3 +162,2 @@ return true; | ||
function compare(x, y) { | ||
// Optimization if they are referencially equal | ||
if (x === y) | ||
@@ -166,3 +168,3 @@ return 0; | ||
else if (y == null) | ||
return 1; // everything is bigger than null | ||
return 1; | ||
else if (Object.getPrototypeOf(x) !== Object.getPrototypeOf(y)) | ||
@@ -200,3 +202,2 @@ return -1; | ||
function equalsRecords(x, y) { | ||
// Optimization if they are referencially equal | ||
if (x === y) { | ||
@@ -216,3 +217,2 @@ return true; | ||
function compareRecords(x, y) { | ||
// Optimization if they are referencially equal | ||
if (x === y) { | ||
@@ -233,3 +233,2 @@ return 0; | ||
function equalsUnions(x, y) { | ||
// Optimization if they are referencially equal | ||
if (x === y) { | ||
@@ -251,3 +250,2 @@ return true; | ||
function compareUnions(x, y) { | ||
// Optimization if they are referencially equal | ||
if (x === y) { | ||
@@ -295,3 +293,2 @@ return 0; | ||
} | ||
// Copy also properties from prototype, see #192 | ||
var proto = Object.getPrototypeOf(source); | ||
@@ -298,0 +295,0 @@ if (proto != null) { |
31
Util.js
@@ -22,10 +22,18 @@ import FSymbol from "./Symbol"; | ||
export function Option(t) { | ||
return new NonDeclaredType("Option", "Option", t); | ||
return new NonDeclaredType("Option", null, t); | ||
} | ||
function FArray(t) { | ||
return new NonDeclaredType("Array", "Array", t); | ||
function FableArray(t, isTypedArray) { | ||
if (isTypedArray === void 0) { isTypedArray = false; } | ||
var def = null, genArg = null; | ||
if (isTypedArray) { | ||
def = t; | ||
} | ||
else { | ||
genArg = t; | ||
} | ||
return new NonDeclaredType("Array", def, genArg); | ||
} | ||
export { FArray as Array }; | ||
export { FableArray as Array }; | ||
export function Tuple(ts) { | ||
return new NonDeclaredType("Tuple", "Tuple", ts); | ||
return new NonDeclaredType("Tuple", null, ts); | ||
} | ||
@@ -44,6 +52,2 @@ export function GenericParam(definition) { | ||
} | ||
/** | ||
* Returns the parent if this is a declared generic type or the argument otherwise. | ||
* Attention: Unlike .NET this doesn't throw an exception if type is not generic. | ||
*/ | ||
export function getDefinition(typ) { | ||
@@ -101,3 +105,2 @@ return isGeneric(typ) ? typ.definition : typ; | ||
export function equals(x, y) { | ||
// Optimization if they are referencially equal | ||
if (x === y) | ||
@@ -136,3 +139,2 @@ return true; | ||
export function compare(x, y) { | ||
// Optimization if they are referencially equal | ||
if (x === y) | ||
@@ -143,3 +145,3 @@ return 0; | ||
else if (y == null) | ||
return 1; // everything is bigger than null | ||
return 1; | ||
else if (Object.getPrototypeOf(x) !== Object.getPrototypeOf(y)) | ||
@@ -176,3 +178,2 @@ return -1; | ||
export function equalsRecords(x, y) { | ||
// Optimization if they are referencially equal | ||
if (x === y) { | ||
@@ -191,3 +192,2 @@ return true; | ||
export function compareRecords(x, y) { | ||
// Optimization if they are referencially equal | ||
if (x === y) { | ||
@@ -207,3 +207,2 @@ return 0; | ||
export function equalsUnions(x, y) { | ||
// Optimization if they are referencially equal | ||
if (x === y) { | ||
@@ -224,3 +223,2 @@ return true; | ||
export function compareUnions(x, y) { | ||
// Optimization if they are referencially equal | ||
if (x === y) { | ||
@@ -265,3 +263,2 @@ return 0; | ||
} | ||
// Copy also properties from prototype, see #192 | ||
var proto = Object.getPrototypeOf(source); | ||
@@ -268,0 +265,0 @@ if (proto != null) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
4677631
15568
62