Remove hard-copies of nuget packages
Better to just download them once when a dev env is set up
This commit is contained in:
1 parent
dd7f6e3eec
commit
bb14047524
836 files changed
-214305
No files matched your search
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
-1301
File diff suppressed because it is too large.
Load diff
-97
@@ -1,97 +0,0 @@
|
||||
{
|
||||
"version": 2,
|
||||
"dgSpecHash": "PW98S90Pd8TmBmkRVENrW73SOHkYdS7RqnT9xXoJSQCrXGs/r7Zx382P8fM3X2qxPxE/sPMuoKwtzXKpKVnV7g==",
|
||||
"success": true,
|
||||
"projectFilePath": "/home/ppinto/Dropbox/bts/spark/src/web/ui/src/ui.fsproj",
|
||||
"expectedPackageFiles": [
|
||||
"/home/ppinto/.nuget/packages/dotnet-fable/1.3.15/dotnet-fable.1.3.15.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/dotnet.projinfo/0.9.0/dotnet.projinfo.0.9.0.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/fable.compiler/1.3.15/fable.compiler.1.3.15.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/fable.core/1.3.12/fable.core.1.3.12.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/fsharp.compiler.service/20.0.1/fsharp.compiler.service.20.0.1.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/fsharp.core/4.2.3/fsharp.core.4.2.3.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/microsoft.netcore.app/2.0.0/microsoft.netcore.app.2.0.0.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/microsoft.netcore.dotnetapphost/2.0.0/microsoft.netcore.dotnetapphost.2.0.0.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/microsoft.netcore.dotnethostpolicy/2.0.0/microsoft.netcore.dotnethostpolicy.2.0.0.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/microsoft.netcore.dotnethostresolver/2.0.0/microsoft.netcore.dotnethostresolver.2.0.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/microsoft.netcore.platforms/2.0.0/microsoft.netcore.platforms.2.0.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/microsoft.netcore.targets/1.1.0/microsoft.netcore.targets.1.1.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/microsoft.win32.primitives/4.0.1/microsoft.win32.primitives.4.0.1.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/microsoft.win32.registry/4.0.0/microsoft.win32.registry.4.0.0.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/netstandard.library/2.0.0/netstandard.library.2.0.0.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/newtonsoft.json/11.0.1/newtonsoft.json.11.0.1.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/runtime.debian.8-x64.runtime.native.system.security.cryptography.openssl/4.3.0/runtime.debian.8-x64.runtime.native.system.security.cryptography.openssl.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/runtime.fedora.23-x64.runtime.native.system.security.cryptography.openssl/4.3.0/runtime.fedora.23-x64.runtime.native.system.security.cryptography.openssl.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/runtime.fedora.24-x64.runtime.native.system.security.cryptography.openssl/4.3.0/runtime.fedora.24-x64.runtime.native.system.security.cryptography.openssl.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/runtime.native.system/4.0.0/runtime.native.system.4.0.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/runtime.native.system.net.http/4.0.1/runtime.native.system.net.http.4.0.1.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/runtime.native.system.security.cryptography/4.0.0/runtime.native.system.security.cryptography.4.0.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/runtime.native.system.security.cryptography.apple/4.3.0/runtime.native.system.security.cryptography.apple.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/runtime.native.system.security.cryptography.openssl/4.3.0/runtime.native.system.security.cryptography.openssl.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/runtime.opensuse.13.2-x64.runtime.native.system.security.cryptography.openssl/4.3.0/runtime.opensuse.13.2-x64.runtime.native.system.security.cryptography.openssl.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/runtime.opensuse.42.1-x64.runtime.native.system.security.cryptography.openssl/4.3.0/runtime.opensuse.42.1-x64.runtime.native.system.security.cryptography.openssl.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/runtime.osx.10.10-x64.runtime.native.system.security.cryptography.apple/4.3.0/runtime.osx.10.10-x64.runtime.native.system.security.cryptography.apple.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/runtime.osx.10.10-x64.runtime.native.system.security.cryptography.openssl/4.3.0/runtime.osx.10.10-x64.runtime.native.system.security.cryptography.openssl.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/runtime.rhel.7-x64.runtime.native.system.security.cryptography.openssl/4.3.0/runtime.rhel.7-x64.runtime.native.system.security.cryptography.openssl.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/runtime.ubuntu.14.04-x64.runtime.native.system.security.cryptography.openssl/4.3.0/runtime.ubuntu.14.04-x64.runtime.native.system.security.cryptography.openssl.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/runtime.ubuntu.16.04-x64.runtime.native.system.security.cryptography.openssl/4.3.0/runtime.ubuntu.16.04-x64.runtime.native.system.security.cryptography.openssl.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/runtime.ubuntu.16.10-x64.runtime.native.system.security.cryptography.openssl/4.3.0/runtime.ubuntu.16.10-x64.runtime.native.system.security.cryptography.openssl.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.collections/4.3.0/system.collections.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.collections.concurrent/4.3.0/system.collections.concurrent.4.3.0.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/system.collections.immutable/1.4.0/system.collections.immutable.1.4.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.console/4.0.0/system.console.4.0.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.diagnostics.debug/4.3.0/system.diagnostics.debug.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.diagnostics.diagnosticsource/4.0.0/system.diagnostics.diagnosticsource.4.0.0.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/system.diagnostics.process/4.1.0/system.diagnostics.process.4.1.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.diagnostics.tools/4.0.1/system.diagnostics.tools.4.0.1.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/system.diagnostics.tracesource/4.0.0/system.diagnostics.tracesource.4.0.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.diagnostics.tracing/4.3.0/system.diagnostics.tracing.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.globalization/4.3.0/system.globalization.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.globalization.calendars/4.0.1/system.globalization.calendars.4.0.1.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.globalization.extensions/4.0.1/system.globalization.extensions.4.0.1.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.io/4.3.0/system.io.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.io.filesystem/4.0.1/system.io.filesystem.4.0.1.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.io.filesystem.primitives/4.0.1/system.io.filesystem.primitives.4.0.1.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.linq/4.3.0/system.linq.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.linq.expressions/4.1.0/system.linq.expressions.4.1.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.linq.queryable/4.0.1/system.linq.queryable.4.0.1.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.net.http/4.1.0/system.net.http.4.1.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.net.primitives/4.0.11/system.net.primitives.4.0.11.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/system.net.requests/4.0.11/system.net.requests.4.0.11.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/system.net.webheadercollection/4.0.1/system.net.webheadercollection.4.0.1.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.objectmodel/4.0.12/system.objectmodel.4.0.12.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.reflection/4.3.0/system.reflection.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.reflection.emit/4.3.0/system.reflection.emit.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.reflection.emit.ilgeneration/4.3.0/system.reflection.emit.ilgeneration.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.reflection.emit.lightweight/4.0.1/system.reflection.emit.lightweight.4.0.1.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.reflection.extensions/4.0.1/system.reflection.extensions.4.0.1.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/system.reflection.metadata/1.5.0/system.reflection.metadata.1.5.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.reflection.primitives/4.3.0/system.reflection.primitives.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.reflection.typeextensions/4.3.0/system.reflection.typeextensions.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.resources.resourcemanager/4.3.0/system.resources.resourcemanager.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.runtime/4.3.0/system.runtime.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.runtime.extensions/4.3.0/system.runtime.extensions.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.runtime.handles/4.3.0/system.runtime.handles.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.runtime.interopservices/4.3.0/system.runtime.interopservices.4.3.0.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/system.runtime.loader/4.3.0/system.runtime.loader.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.runtime.numerics/4.3.0/system.runtime.numerics.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.security.cryptography.algorithms/4.3.0/system.security.cryptography.algorithms.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.security.cryptography.cng/4.2.0/system.security.cryptography.cng.4.2.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.security.cryptography.csp/4.0.0/system.security.cryptography.csp.4.0.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.security.cryptography.encoding/4.3.0/system.security.cryptography.encoding.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.security.cryptography.openssl/4.0.0/system.security.cryptography.openssl.4.0.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.security.cryptography.primitives/4.3.0/system.security.cryptography.primitives.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.security.cryptography.x509certificates/4.1.0/system.security.cryptography.x509certificates.4.1.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.text.encoding/4.3.0/system.text.encoding.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.text.encoding.extensions/4.0.11/system.text.encoding.extensions.4.0.11.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.text.regularexpressions/4.1.0/system.text.regularexpressions.4.1.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.threading/4.3.0/system.threading.4.3.0.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.threading.tasks/4.3.0/system.threading.tasks.4.3.0.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/system.threading.tasks.parallel/4.0.1/system.threading.tasks.parallel.4.0.1.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/system.threading.thread/4.0.0/system.threading.thread.4.0.0.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/system.threading.threadpool/4.0.10/system.threading.threadpool.4.0.10.nupkg.sha512",
|
||||
"/usr/share/dotnet/sdk/NuGetFallbackFolder/system.threading.timer/4.0.1/system.threading.timer.4.0.1.nupkg.sha512",
|
||||
"/home/ppinto/.nuget/packages/system.valuetuple/4.4.0/system.valuetuple.4.4.0.nupkg.sha512"
|
||||
],
|
||||
"logs": []
|
||||
}
|
||||
-5242
File diff suppressed because it is too large.
Load diff
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"version": 1,
|
||||
"contentHash": "smJIObxp3UbGIBiPM8ZTKqz86FcVJvD06eq2sold15rMEj4pOMrc5wlUBZNYbIamoOoX+Ls53dNBfSMRoB/d6g=="
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
vgDhp2J3q9FqLluUCj8w+9Bh5+Gl7WNW5QKnHRdnJTRwmsmqKbGKoaFVSp995V7FB1s+WIpOoxZtWccKxkL19Q==
|
||||
@@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>dotnet-fable</id>
|
||||
<version>1.3.15</version>
|
||||
<authors>Alfonso García-Caro Núñez</authors>
|
||||
<owners>Alfonso García-Caro Núñez</owners>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<licenseUrl>https://raw.githubusercontent.com/fable-compiler/Fable/master/LICENSE</licenseUrl>
|
||||
<projectUrl>http://fable.io/</projectUrl>
|
||||
<iconUrl>https://raw.githubusercontent.com/fable-compiler/Fable/master/docs/img/fable_logo.png</iconUrl>
|
||||
<description>DotNet CLI tool to run Fable</description>
|
||||
<tags>fsharp fable javascript f# js</tags>
|
||||
<packageTypes>
|
||||
<packageType name="DotnetCliTool" />
|
||||
</packageTypes>
|
||||
<dependencies>
|
||||
<group targetFramework=".NETCoreApp2.0">
|
||||
<dependency id="Fable.Core" version="1.3.12" exclude="Build,Analyzers" />
|
||||
<dependency id="Fable.Compiler" version="1.3.15" exclude="Build,Analyzers" />
|
||||
<dependency id="Dotnet.ProjInfo" version="0.9.0" exclude="Build,Analyzers" />
|
||||
<dependency id="FSharp.Core" version="4.2.3" exclude="Build,Analyzers" />
|
||||
<dependency id="Microsoft.NETCore.App" version="2.0.0" exclude="Build,Analyzers" />
|
||||
</group>
|
||||
</dependencies>
|
||||
</metadata>
|
||||
</package>
|
||||
Binary file not shown.
-9
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"tfm": "netcoreapp2.0",
|
||||
"framework": {
|
||||
"name": "Microsoft.NETCore.App",
|
||||
"version": "2.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"version": 1,
|
||||
"contentHash": "ooIqkOdRRocSyP87AL2MwLUj6jr8wBSrKF0KhpUUMy8X5Q0/hThtVvKU/ygSOgtxQdFpewguex4ueMQyUOnsmA=="
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
mRNi4hLVkdkQEfL6essh3ngTyhfqs1FdbLg1ACLd0/8/M7gzeP4jwWv01/17T8Ev08SDu93dmCXmaOFusOo4rQ==
|
||||
@@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>Dotnet.ProjInfo</id>
|
||||
<version>0.9.0</version>
|
||||
<authors>Enrico Sada</authors>
|
||||
<owners>Enrico Sada</owners>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<licenseUrl>https://github.com/enricosada/dotnet-proj-info/blob/master/LICENSE</licenseUrl>
|
||||
<projectUrl>https://github.com/enricosada/dotnet-proj-info/</projectUrl>
|
||||
<description>Get msbuild info</description>
|
||||
<tags>mbuild dotnet sdk csproj fsproj</tags>
|
||||
<repository url="https://github.com/enricosada/dotnet-proj-info.git" />
|
||||
<dependencies>
|
||||
<group targetFramework=".NETFramework4.5">
|
||||
<dependency id="FSharp.Core" version="4.0.0.1" exclude="Build,Analyzers" />
|
||||
</group>
|
||||
<group targetFramework=".NETStandard1.6">
|
||||
<dependency id="NETStandard.Library" version="1.6.1" exclude="Build,Analyzers" />
|
||||
<dependency id="FSharp.Core" version="4.1.18" exclude="Build,Analyzers" />
|
||||
<dependency id="System.ValueTuple" version="4.4.0" exclude="Build,Analyzers" />
|
||||
</group>
|
||||
<group targetFramework=".NETStandard2.0">
|
||||
<dependency id="FSharp.Core" version="4.2.3" exclude="Build,Analyzers" />
|
||||
</group>
|
||||
</dependencies>
|
||||
</metadata>
|
||||
</package>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"version": 1,
|
||||
"contentHash": "kVXVZcupJcA94FTnyQ6KnGIMJiZv5XvOx1o9/yffG72dKvBLZtcubZKyrg4n0n9JnFkouiMKvtRdX70kaB4qYA=="
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
kEIiAAYtBecNsauFLzpmZ3D8dwemFjFLn4cpkloHRiV6X0RBb7GlHIUGAVnRMsdub/2etgdcC0dRfKTJ9i552A==
|
||||
@@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>Fable.Compiler</id>
|
||||
<version>1.3.15</version>
|
||||
<authors>Alfonso García-Caro Núñez</authors>
|
||||
<owners>Alfonso García-Caro Núñez</owners>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<licenseUrl>https://raw.githubusercontent.com/fable-compiler/Fable/master/LICENSE</licenseUrl>
|
||||
<projectUrl>http://fable.io/</projectUrl>
|
||||
<iconUrl>https://raw.githubusercontent.com/fable-compiler/Fable/master/docs/img/fable_logo.png</iconUrl>
|
||||
<description>Fable: F# to JS Compiler</description>
|
||||
<tags>fsharp fable javascript f# js</tags>
|
||||
<dependencies>
|
||||
<group targetFramework=".NETStandard1.6">
|
||||
<dependency id="Fable.Core" version="1.3.12" exclude="Build,Analyzers" />
|
||||
<dependency id="FSharp.Compiler.Service" version="20.0.1" exclude="Build,Analyzers" />
|
||||
<dependency id="FSharp.Core" version="4.2.3" exclude="Build,Analyzers" />
|
||||
<dependency id="Newtonsoft.Json" version="11.0.1" exclude="Build,Analyzers" />
|
||||
<dependency id="System.Collections.Immutable" version="1.4.0" exclude="Build,Analyzers" />
|
||||
<dependency id="System.Reflection.Metadata" version="1.5.0" exclude="Build,Analyzers" />
|
||||
<dependency id="System.Runtime.Loader" version="4.3.0" exclude="Build,Analyzers" />
|
||||
</group>
|
||||
</dependencies>
|
||||
</metadata>
|
||||
</package>
|
||||
Binary file not shown.
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"version": 1,
|
||||
"contentHash": "7Iobm78yfG//4+mCuHbZFtPfAcLgvnYzTyTjTrX5EDrrurhc6mC7kY7y/2NHLtu9z5d0GVYhR8eOWj3C47a61w=="
|
||||
}
|
||||
BIN
Binary file not shown.
@@ -1,141 +0,0 @@
|
||||
export function map(f, source, TargetCons) {
|
||||
const target = new TargetCons(source.length);
|
||||
for (let i = 0; i < source.length; i++) {
|
||||
target[i] = f(source[i]);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
export function mapIndexed(f, source, TargetCons) {
|
||||
const target = new TargetCons(source.length);
|
||||
for (let i = 0; i < source.length; i++) {
|
||||
target[i] = f(i, source[i]);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
export function indexed(source) {
|
||||
return mapIndexed((i, x) => [i, x], source, Array);
|
||||
}
|
||||
export function addRangeInPlace(range, xs) {
|
||||
const iter = range[Symbol.iterator]();
|
||||
let cur = iter.next();
|
||||
while (!cur.done) {
|
||||
xs.push(cur.value);
|
||||
cur = iter.next();
|
||||
}
|
||||
}
|
||||
export function copyTo(source, sourceIndex, target, targetIndex, count) {
|
||||
while (count--) {
|
||||
target[targetIndex++] = source[sourceIndex++];
|
||||
}
|
||||
}
|
||||
export function partition(f, xs) {
|
||||
const ys = [];
|
||||
const zs = [];
|
||||
let j = 0;
|
||||
let k = 0;
|
||||
for (let i = 0; i < xs.length; i++) {
|
||||
if (f(xs[i])) {
|
||||
ys[j++] = xs[i];
|
||||
}
|
||||
else {
|
||||
zs[k++] = xs[i];
|
||||
}
|
||||
}
|
||||
return [ys, zs];
|
||||
}
|
||||
export function permute(f, xs) {
|
||||
// Keep the type of the array
|
||||
const ys = xs.map(() => null);
|
||||
const checkFlags = new Array(xs.length);
|
||||
for (let i = 0; i < xs.length; i++) {
|
||||
const j = f(i);
|
||||
if (j < 0 || j >= xs.length) {
|
||||
throw new Error("Not a valid permutation");
|
||||
}
|
||||
ys[j] = xs[i];
|
||||
checkFlags[j] = 1;
|
||||
}
|
||||
for (let i = 0; i < xs.length; i++) {
|
||||
if (checkFlags[i] !== 1) {
|
||||
throw new Error("Not a valid permutation");
|
||||
}
|
||||
}
|
||||
return ys;
|
||||
}
|
||||
export function removeInPlace(item, xs) {
|
||||
const i = xs.indexOf(item);
|
||||
if (i > -1) {
|
||||
xs.splice(i, 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function setSlice(target, lower, upper, source) {
|
||||
const length = (upper || target.length - 1) - lower;
|
||||
if (ArrayBuffer.isView(target) && source.length <= length) {
|
||||
target.set(source, lower);
|
||||
}
|
||||
else {
|
||||
for (let i = lower | 0, j = 0; j <= length; i++, j++) {
|
||||
target[i] = source[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
export function sortInPlaceBy(f, xs, dir = 1) {
|
||||
return xs.sort((x, y) => {
|
||||
x = f(x);
|
||||
y = f(y);
|
||||
return (x < y ? -1 : x === y ? 0 : 1) * dir;
|
||||
});
|
||||
}
|
||||
export function unzip(xs) {
|
||||
const bs = new Array(xs.length);
|
||||
const cs = new Array(xs.length);
|
||||
for (let i = 0; i < xs.length; i++) {
|
||||
bs[i] = xs[i][0];
|
||||
cs[i] = xs[i][1];
|
||||
}
|
||||
return [bs, cs];
|
||||
}
|
||||
export function unzip3(xs) {
|
||||
const bs = new Array(xs.length);
|
||||
const cs = new Array(xs.length);
|
||||
const ds = new Array(xs.length);
|
||||
for (let i = 0; i < xs.length; i++) {
|
||||
bs[i] = xs[i][0];
|
||||
cs[i] = xs[i][1];
|
||||
ds[i] = xs[i][2];
|
||||
}
|
||||
return [bs, cs, ds];
|
||||
}
|
||||
export function chunkBySize(size, xs) {
|
||||
if (size < 1) {
|
||||
throw new Error("The input must be positive. parameter name: chunkSize");
|
||||
}
|
||||
if (xs.length === 0) {
|
||||
return [[]];
|
||||
}
|
||||
const result = [];
|
||||
// add each chunk to the result
|
||||
for (let x = 0; x < Math.ceil(xs.length / size); x++) {
|
||||
const start = x * size;
|
||||
const end = start + size;
|
||||
result.push(xs.slice(start, end));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
export function getSubArray(xs, startIndex, count) {
|
||||
return xs.slice(startIndex, startIndex + count);
|
||||
}
|
||||
export function fill(target, targetIndex, count, value) {
|
||||
target.fill(value, targetIndex, targetIndex + count);
|
||||
}
|
||||
export function splitAt(index, xs) {
|
||||
if (index < 0) {
|
||||
throw new Error("The input must be non-negative.");
|
||||
}
|
||||
if (index > xs.length) {
|
||||
throw new Error("The input sequence has an insufficient number of elements.");
|
||||
}
|
||||
return [xs.slice(0, index), xs.slice(index)];
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { equals } from "./Util";
|
||||
export class AssertionError extends Error {
|
||||
constructor(msg, actual, expected) {
|
||||
super(msg);
|
||||
this.actual = actual;
|
||||
this.expected = expected;
|
||||
}
|
||||
}
|
||||
export function equal(actual, expected, msg) {
|
||||
if (!equals(actual, expected)) {
|
||||
throw new AssertionError(msg || `Expected: ${expected} - Actual: ${actual}`, actual, expected);
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
import { OperationCanceledError, Trampoline } from "./AsyncBuilder";
|
||||
import { protectedCont } from "./AsyncBuilder";
|
||||
import { protectedBind } from "./AsyncBuilder";
|
||||
import { protectedReturn } from "./AsyncBuilder";
|
||||
import { choice1Of2 } from "./Choice";
|
||||
import { choice2Of2 } from "./Choice";
|
||||
import { map } from "./Seq";
|
||||
// Implemented just for type references
|
||||
export default class Async {
|
||||
}
|
||||
function emptyContinuation(x) {
|
||||
// NOP
|
||||
}
|
||||
export function createCancellationToken(arg) {
|
||||
const token = { isCancelled: false };
|
||||
if (typeof arg === "number") {
|
||||
setTimeout(() => { token.isCancelled = true; }, arg);
|
||||
}
|
||||
else if (typeof arg === "boolean") {
|
||||
token.isCancelled = arg;
|
||||
}
|
||||
return token;
|
||||
}
|
||||
export function cancel(token) {
|
||||
token.isCancelled = true;
|
||||
}
|
||||
export function cancelAfter(token, ms) {
|
||||
setTimeout(() => { token.isCancelled = true; }, ms);
|
||||
}
|
||||
export function isCancellationRequested(token) {
|
||||
return token != null && token.isCancelled;
|
||||
}
|
||||
export function startChild(computation) {
|
||||
const promise = startAsPromise(computation);
|
||||
// JS Promises are hot, computation has already started
|
||||
// but we delay returning the result
|
||||
return protectedCont((ctx) => protectedReturn(awaitPromise(promise))(ctx));
|
||||
}
|
||||
export function awaitPromise(p) {
|
||||
return fromContinuations((conts) => p.then(conts[0]).catch((err) => (err instanceof OperationCanceledError
|
||||
? conts[2] : conts[1])(err)));
|
||||
}
|
||||
export function cancellationToken() {
|
||||
return protectedCont((ctx) => ctx.onSuccess(ctx.cancelToken));
|
||||
}
|
||||
export const defaultCancellationToken = { isCancelled: false };
|
||||
export function catchAsync(work) {
|
||||
return protectedCont((ctx) => {
|
||||
work({
|
||||
onSuccess: (x) => ctx.onSuccess(choice1Of2(x)),
|
||||
onError: (ex) => ctx.onSuccess(choice2Of2(ex)),
|
||||
onCancel: ctx.onCancel,
|
||||
cancelToken: ctx.cancelToken,
|
||||
trampoline: ctx.trampoline,
|
||||
});
|
||||
});
|
||||
}
|
||||
export function fromContinuations(f) {
|
||||
return protectedCont((ctx) => f([ctx.onSuccess, ctx.onError, ctx.onCancel]));
|
||||
}
|
||||
export function ignore(computation) {
|
||||
return protectedBind(computation, (x) => protectedReturn(void 0));
|
||||
}
|
||||
export function parallel(computations) {
|
||||
return awaitPromise(Promise.all(map((w) => startAsPromise(w), computations)));
|
||||
}
|
||||
export function sleep(millisecondsDueTime) {
|
||||
return protectedCont((ctx) => {
|
||||
setTimeout(() => ctx.cancelToken.isCancelled
|
||||
? ctx.onCancel(new OperationCanceledError())
|
||||
: ctx.onSuccess(void 0), millisecondsDueTime);
|
||||
});
|
||||
}
|
||||
export function start(computation, cancellationToken) {
|
||||
return startWithContinuations(computation, cancellationToken);
|
||||
}
|
||||
export function startImmediate(computation, cancellationToken) {
|
||||
return start(computation, cancellationToken);
|
||||
}
|
||||
export function startWithContinuations(computation, continuation, exceptionContinuation, cancellationContinuation, cancelToken) {
|
||||
if (typeof continuation !== "function") {
|
||||
cancelToken = continuation;
|
||||
continuation = null;
|
||||
}
|
||||
const trampoline = new Trampoline();
|
||||
computation({
|
||||
onSuccess: continuation ? continuation : emptyContinuation,
|
||||
onError: exceptionContinuation ? exceptionContinuation : emptyContinuation,
|
||||
onCancel: cancellationContinuation ? cancellationContinuation : emptyContinuation,
|
||||
cancelToken: cancelToken ? cancelToken : defaultCancellationToken,
|
||||
trampoline,
|
||||
});
|
||||
}
|
||||
export function startAsPromise(computation, cancellationToken) {
|
||||
return new Promise((resolve, reject) => startWithContinuations(computation, resolve, reject, reject, cancellationToken ? cancellationToken : defaultCancellationToken));
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
export class OperationCanceledError extends Error {
|
||||
constructor() {
|
||||
super("The operation was canceled");
|
||||
Object.setPrototypeOf(this, OperationCanceledError.prototype);
|
||||
}
|
||||
}
|
||||
export class Trampoline {
|
||||
static get maxTrampolineCallCount() {
|
||||
return 2000;
|
||||
}
|
||||
constructor() {
|
||||
this.callCount = 0;
|
||||
}
|
||||
incrementAndCheck() {
|
||||
return this.callCount++ > Trampoline.maxTrampolineCallCount;
|
||||
}
|
||||
hijack(f) {
|
||||
this.callCount = 0;
|
||||
setTimeout(f, 0);
|
||||
}
|
||||
}
|
||||
export function protectedCont(f) {
|
||||
return (ctx) => {
|
||||
if (ctx.cancelToken.isCancelled) {
|
||||
ctx.onCancel(new OperationCanceledError());
|
||||
}
|
||||
else if (ctx.trampoline.incrementAndCheck()) {
|
||||
ctx.trampoline.hijack(() => {
|
||||
try {
|
||||
f(ctx);
|
||||
}
|
||||
catch (err) {
|
||||
ctx.onError(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
try {
|
||||
f(ctx);
|
||||
}
|
||||
catch (err) {
|
||||
ctx.onError(err);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
export function protectedBind(computation, binder) {
|
||||
return protectedCont((ctx) => {
|
||||
computation({
|
||||
onSuccess: (x) => {
|
||||
try {
|
||||
binder(x)(ctx);
|
||||
}
|
||||
catch (ex) {
|
||||
ctx.onError(ex);
|
||||
}
|
||||
},
|
||||
onError: ctx.onError,
|
||||
onCancel: ctx.onCancel,
|
||||
cancelToken: ctx.cancelToken,
|
||||
trampoline: ctx.trampoline,
|
||||
});
|
||||
});
|
||||
}
|
||||
export function protectedReturn(value) {
|
||||
return protectedCont((ctx) => ctx.onSuccess(value));
|
||||
}
|
||||
export class AsyncBuilder {
|
||||
Bind(computation, binder) {
|
||||
return protectedBind(computation, binder);
|
||||
}
|
||||
Combine(computation1, computation2) {
|
||||
return this.Bind(computation1, () => computation2);
|
||||
}
|
||||
Delay(generator) {
|
||||
return protectedCont((ctx) => generator()(ctx));
|
||||
}
|
||||
For(sequence, body) {
|
||||
const iter = sequence[Symbol.iterator]();
|
||||
let cur = iter.next();
|
||||
return this.While(() => !cur.done, this.Delay(() => {
|
||||
const res = body(cur.value);
|
||||
cur = iter.next();
|
||||
return res;
|
||||
}));
|
||||
}
|
||||
Return(value) {
|
||||
return protectedReturn(value);
|
||||
}
|
||||
ReturnFrom(computation) {
|
||||
return computation;
|
||||
}
|
||||
TryFinally(computation, compensation) {
|
||||
return protectedCont((ctx) => {
|
||||
computation({
|
||||
onSuccess: (x) => {
|
||||
compensation();
|
||||
ctx.onSuccess(x);
|
||||
},
|
||||
onError: (x) => {
|
||||
compensation();
|
||||
ctx.onError(x);
|
||||
},
|
||||
onCancel: (x) => {
|
||||
compensation();
|
||||
ctx.onCancel(x);
|
||||
},
|
||||
cancelToken: ctx.cancelToken,
|
||||
trampoline: ctx.trampoline,
|
||||
});
|
||||
});
|
||||
}
|
||||
TryWith(computation, catchHandler) {
|
||||
return protectedCont((ctx) => {
|
||||
computation({
|
||||
onSuccess: ctx.onSuccess,
|
||||
onCancel: ctx.onCancel,
|
||||
cancelToken: ctx.cancelToken,
|
||||
trampoline: ctx.trampoline,
|
||||
onError: (ex) => {
|
||||
try {
|
||||
catchHandler(ex)(ctx);
|
||||
}
|
||||
catch (ex2) {
|
||||
ctx.onError(ex2);
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
Using(resource, binder) {
|
||||
return this.TryFinally(binder(resource), () => resource.Dispose());
|
||||
}
|
||||
While(guard, computation) {
|
||||
if (guard()) {
|
||||
return this.Bind(computation, () => this.While(guard, computation));
|
||||
}
|
||||
else {
|
||||
return this.Return(void 0);
|
||||
}
|
||||
}
|
||||
Zero() {
|
||||
return protectedCont((ctx) => ctx.onSuccess(void 0));
|
||||
}
|
||||
}
|
||||
export const singleton = new AsyncBuilder();
|
||||
@@ -1,813 +0,0 @@
|
||||
import { setType } from "./Symbol";
|
||||
import _Symbol from "./Symbol";
|
||||
import { toString as toString_1 } from "./Util";
|
||||
import { factorial as bigNatFactorial, ofString, toFloat, toUInt64 as bigNattoUInt64, toUInt32 as bigNattoUInt32, pow as bigNatPow, two as bigNatTwo, rem, lte, hcf, bitOr, bitAnd, divmod, mul, isOne, sub, gte, scale as bigNatScale, one as bigNatOne, add, ofInt64, toString, gt, lt, isZero, equal, getSmall, isSmall, ofInt32 } from "./BigInt/BigNat";
|
||||
import BigNat from "./BigInt/BigNat";
|
||||
import { initialize } from "./Seq";
|
||||
import { fromBits, fromNumber } from "./Long";
|
||||
import { trim } from "./String";
|
||||
export default class BigInteger {
|
||||
constructor(signInt, v) {
|
||||
this.toJSON = this.ToString;
|
||||
this.signInt = signInt;
|
||||
this.v = v;
|
||||
}
|
||||
[_Symbol.reflection]() {
|
||||
return {
|
||||
type: "System.Numerics.BigInteger",
|
||||
interfaces: ["FSharpRecord", "System.IComparable"],
|
||||
properties: {
|
||||
signInt: "number",
|
||||
v: BigNat,
|
||||
},
|
||||
};
|
||||
}
|
||||
get Sign() {
|
||||
if (this.IsZero) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return this.signInt;
|
||||
}
|
||||
}
|
||||
get SignInt() {
|
||||
return this.signInt;
|
||||
}
|
||||
get V() {
|
||||
return this.v;
|
||||
}
|
||||
get IsZero() {
|
||||
if (this.SignInt === 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return isZero(this.V);
|
||||
}
|
||||
}
|
||||
get IsOne() {
|
||||
if (this.SignInt === 1) {
|
||||
return isOne(this.V);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
get StructuredDisplayString() {
|
||||
return toString_1(this);
|
||||
}
|
||||
get IsSmall() {
|
||||
if (this.IsZero) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return isSmall(this.V);
|
||||
}
|
||||
}
|
||||
get IsNegative() {
|
||||
if (this.SignInt === -1) {
|
||||
return !this.IsZero;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
get IsPositive() {
|
||||
if (this.SignInt === 1) {
|
||||
return !this.IsZero;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
CompareTo(obj) {
|
||||
if (obj instanceof BigInteger) {
|
||||
const that = obj;
|
||||
return compare(this, that);
|
||||
}
|
||||
else {
|
||||
throw new Error("the objects are not comparable" + "\nParameter name: " + "obj");
|
||||
}
|
||||
}
|
||||
ToString() {
|
||||
const matchValue = this.SignInt;
|
||||
let $var19 = null;
|
||||
switch (matchValue) {
|
||||
case 1:
|
||||
$var19 = toString(this.V);
|
||||
break;
|
||||
case -1:
|
||||
if (isZero(this.V)) {
|
||||
$var19 = "0";
|
||||
}
|
||||
else {
|
||||
$var19 = "-" + toString(this.V);
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
$var19 = "0";
|
||||
break;
|
||||
default:
|
||||
throw new Error("signs should be +/- 1 or 0");
|
||||
}
|
||||
return $var19;
|
||||
}
|
||||
Equals(obj) {
|
||||
if (obj instanceof BigInteger) {
|
||||
const that = obj;
|
||||
return op_Equality(this, that);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
GetHashCode() {
|
||||
return hash(this);
|
||||
}
|
||||
}
|
||||
BigInteger.ofJSON = parse;
|
||||
setType("System.Numerics.BigInteger", BigInteger);
|
||||
const smallLim = 4096;
|
||||
const smallPosTab = Array.from(initialize(smallLim, n => ofInt32(n)));
|
||||
export const one = fromInt32(1);
|
||||
export const two = fromInt32(2);
|
||||
export const zero = fromInt32(0);
|
||||
export function fromInt32(n) {
|
||||
if (n >= 0) {
|
||||
return new BigInteger(1, nat(ofInt32(n)));
|
||||
}
|
||||
else if (n === -2147483648) {
|
||||
return new BigInteger(-1, nat(ofInt64(fromNumber(n, false).neg())));
|
||||
}
|
||||
else {
|
||||
return new BigInteger(-1, nat(ofInt32(-n)));
|
||||
}
|
||||
}
|
||||
export function fromInt64(n) {
|
||||
if (n.CompareTo(fromBits(0, 0, false)) >= 0) {
|
||||
return new BigInteger(1, nat(ofInt64(n)));
|
||||
}
|
||||
else if (n.Equals(fromBits(0, 2147483648, false))) {
|
||||
return new BigInteger(-1, nat(add(ofInt64(fromBits(4294967295, 2147483647, false)), bigNatOne)));
|
||||
}
|
||||
else {
|
||||
return new BigInteger(-1, nat(ofInt64(n.neg())));
|
||||
}
|
||||
}
|
||||
export function nat(n) {
|
||||
if (isSmall(n) ? getSmall(n) < smallLim : false) {
|
||||
return smallPosTab[getSmall(n)];
|
||||
}
|
||||
else {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
export function create(s, n) {
|
||||
return new BigInteger(s, nat(n));
|
||||
}
|
||||
export function posn(n) {
|
||||
return new BigInteger(1, nat(n));
|
||||
}
|
||||
export function negn(n) {
|
||||
return new BigInteger(-1, nat(n));
|
||||
}
|
||||
export function op_Equality(x, y) {
|
||||
const matchValue = [x.SignInt, y.SignInt];
|
||||
if (matchValue[0] === -1) {
|
||||
if (matchValue[1] === -1) {
|
||||
return equal(x.V, y.V);
|
||||
}
|
||||
else if (matchValue[1] === 0) {
|
||||
return isZero(x.V);
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
if (isZero(x.V)) {
|
||||
return isZero(y.V);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else if (matchValue[0] === 0) {
|
||||
if (matchValue[1] === -1) {
|
||||
return isZero(y.V);
|
||||
}
|
||||
else if (matchValue[1] === 0) {
|
||||
return true;
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
return isZero(y.V);
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else if (matchValue[0] === 1) {
|
||||
if (matchValue[1] === -1) {
|
||||
if (isZero(x.V)) {
|
||||
return isZero(y.V);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (matchValue[1] === 0) {
|
||||
return isZero(x.V);
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
return equal(x.V, y.V);
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
export function op_Inequality(x, y) {
|
||||
return !op_Equality(x, y);
|
||||
}
|
||||
export function op_LessThan(x, y) {
|
||||
const matchValue = [x.SignInt, y.SignInt];
|
||||
if (matchValue[0] === -1) {
|
||||
if (matchValue[1] === -1) {
|
||||
return lt(y.V, x.V);
|
||||
}
|
||||
else if (matchValue[1] === 0) {
|
||||
return !isZero(x.V);
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
if (!isZero(x.V)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return !isZero(y.V);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else if (matchValue[0] === 0) {
|
||||
if (matchValue[1] === -1) {
|
||||
return false;
|
||||
}
|
||||
else if (matchValue[1] === 0) {
|
||||
return false;
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
return !isZero(y.V);
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else if (matchValue[0] === 1) {
|
||||
if (matchValue[1] === -1) {
|
||||
return false;
|
||||
}
|
||||
else if (matchValue[1] === 0) {
|
||||
return false;
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
return lt(x.V, y.V);
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
export function op_GreaterThan(x, y) {
|
||||
const matchValue = [x.SignInt, y.SignInt];
|
||||
if (matchValue[0] === -1) {
|
||||
if (matchValue[1] === -1) {
|
||||
return gt(y.V, x.V);
|
||||
}
|
||||
else if (matchValue[1] === 0) {
|
||||
return false;
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else if (matchValue[0] === 0) {
|
||||
if (matchValue[1] === -1) {
|
||||
return !isZero(y.V);
|
||||
}
|
||||
else if (matchValue[1] === 0) {
|
||||
return false;
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else if (matchValue[0] === 1) {
|
||||
if (matchValue[1] === -1) {
|
||||
if (!isZero(x.V)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return !isZero(y.V);
|
||||
}
|
||||
}
|
||||
else if (matchValue[1] === 0) {
|
||||
return !isZero(x.V);
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
return gt(x.V, y.V);
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
export function compare(n, nn) {
|
||||
if (op_LessThan(n, nn)) {
|
||||
return -1;
|
||||
}
|
||||
else if (op_Equality(n, nn)) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
export function hash(z) {
|
||||
if (z.SignInt === 0) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return z.SignInt + hash(z.V);
|
||||
}
|
||||
}
|
||||
export function op_UnaryNegation(z) {
|
||||
const matchValue = z.SignInt;
|
||||
if (matchValue === 0) {
|
||||
return zero;
|
||||
}
|
||||
else {
|
||||
return create(-matchValue, z.V);
|
||||
}
|
||||
}
|
||||
export function scale(k, z) {
|
||||
if (z.SignInt === 0) {
|
||||
return zero;
|
||||
}
|
||||
else if (k < 0) {
|
||||
return create(-z.SignInt, bigNatScale(-k, z.V));
|
||||
}
|
||||
else {
|
||||
return create(z.SignInt, bigNatScale(k, z.V));
|
||||
}
|
||||
}
|
||||
export function subnn(nx, ny) {
|
||||
if (gte(nx, ny)) {
|
||||
return posn(sub(nx, ny));
|
||||
}
|
||||
else {
|
||||
return negn(sub(ny, nx));
|
||||
}
|
||||
}
|
||||
export function addnn(nx, ny) {
|
||||
return posn(add(nx, ny));
|
||||
}
|
||||
export function op_Addition(x, y) {
|
||||
if (y.IsZero) {
|
||||
return x;
|
||||
}
|
||||
else if (x.IsZero) {
|
||||
return y;
|
||||
}
|
||||
else {
|
||||
const matchValue = [x.SignInt, y.SignInt];
|
||||
if (matchValue[0] === -1) {
|
||||
if (matchValue[1] === -1) {
|
||||
return op_UnaryNegation(addnn(x.V, y.V));
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
return subnn(y.V, x.V);
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else if (matchValue[0] === 1) {
|
||||
if (matchValue[1] === -1) {
|
||||
return subnn(x.V, y.V);
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
return addnn(x.V, y.V);
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
}
|
||||
export function op_Subtraction(x, y) {
|
||||
if (y.IsZero) {
|
||||
return x;
|
||||
}
|
||||
else if (x.IsZero) {
|
||||
return op_UnaryNegation(y);
|
||||
}
|
||||
else {
|
||||
const matchValue = [x.SignInt, y.SignInt];
|
||||
if (matchValue[0] === -1) {
|
||||
if (matchValue[1] === -1) {
|
||||
return subnn(y.V, x.V);
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
return op_UnaryNegation(addnn(x.V, y.V));
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else if (matchValue[0] === 1) {
|
||||
if (matchValue[1] === -1) {
|
||||
return addnn(x.V, y.V);
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
return subnn(x.V, y.V);
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
}
|
||||
export function op_Multiply(x, y) {
|
||||
if (x.IsZero) {
|
||||
return x;
|
||||
}
|
||||
else if (y.IsZero) {
|
||||
return y;
|
||||
}
|
||||
else if (x.IsOne) {
|
||||
return y;
|
||||
}
|
||||
else if (y.IsOne) {
|
||||
return x;
|
||||
}
|
||||
else {
|
||||
const m = mul(x.V, y.V);
|
||||
return create(x.SignInt * y.SignInt, m);
|
||||
}
|
||||
}
|
||||
export function divRem(x, y) {
|
||||
if (y.IsZero) {
|
||||
throw new Error();
|
||||
}
|
||||
if (x.IsZero) {
|
||||
return [zero, zero];
|
||||
}
|
||||
else {
|
||||
const patternInput = divmod(x.V, y.V);
|
||||
const matchValue = [x.SignInt, y.SignInt];
|
||||
if (matchValue[0] === -1) {
|
||||
if (matchValue[1] === -1) {
|
||||
return [posn(patternInput[0]), negn(patternInput[1])];
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
return [negn(patternInput[0]), negn(patternInput[1])];
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else if (matchValue[0] === 1) {
|
||||
if (matchValue[1] === -1) {
|
||||
return [negn(patternInput[0]), posn(patternInput[1])];
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
return [posn(patternInput[0]), posn(patternInput[1])];
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
}
|
||||
export function op_Division(x, y) {
|
||||
return divRem(x, y)[0];
|
||||
}
|
||||
export function op_Modulus(x, y) {
|
||||
return divRem(x, y)[1];
|
||||
}
|
||||
export function op_RightShift(x, y) {
|
||||
return op_Division(x, pow(two, y));
|
||||
}
|
||||
export function op_LeftShift(x, y) {
|
||||
return op_Multiply(x, pow(two, y));
|
||||
}
|
||||
export function op_BitwiseAnd(x, y) {
|
||||
return posn(bitAnd(x.V, y.V));
|
||||
}
|
||||
export function op_BitwiseOr(x, y) {
|
||||
return posn(bitOr(x.V, y.V));
|
||||
}
|
||||
export function greatestCommonDivisor(x, y) {
|
||||
const matchValue = [x.SignInt, y.SignInt];
|
||||
if (matchValue[0] === 0) {
|
||||
if (matchValue[1] === 0) {
|
||||
return zero;
|
||||
}
|
||||
else {
|
||||
return posn(y.V);
|
||||
}
|
||||
}
|
||||
else if (matchValue[1] === 0) {
|
||||
return posn(x.V);
|
||||
}
|
||||
else {
|
||||
return posn(hcf(x.V, y.V));
|
||||
}
|
||||
}
|
||||
export function abs(x) {
|
||||
if (x.SignInt === -1) {
|
||||
return op_UnaryNegation(x);
|
||||
}
|
||||
else {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
export function op_LessThanOrEqual(x, y) {
|
||||
const matchValue = [x.SignInt, y.SignInt];
|
||||
if (matchValue[0] === -1) {
|
||||
if (matchValue[1] === -1) {
|
||||
return lte(y.V, x.V);
|
||||
}
|
||||
else if (matchValue[1] === 0) {
|
||||
return true;
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else if (matchValue[0] === 0) {
|
||||
if (matchValue[1] === -1) {
|
||||
return isZero(y.V);
|
||||
}
|
||||
else if (matchValue[1] === 0) {
|
||||
return true;
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else if (matchValue[0] === 1) {
|
||||
if (matchValue[1] === -1) {
|
||||
if (isZero(x.V)) {
|
||||
return isZero(y.V);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (matchValue[1] === 0) {
|
||||
return isZero(x.V);
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
return lte(x.V, y.V);
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
export function op_GreaterThanOrEqual(x, y) {
|
||||
const matchValue = [x.SignInt, y.SignInt];
|
||||
if (matchValue[0] === -1) {
|
||||
if (matchValue[1] === -1) {
|
||||
return gte(y.V, x.V);
|
||||
}
|
||||
else if (matchValue[1] === 0) {
|
||||
return isZero(x.V);
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
if (isZero(x.V)) {
|
||||
return isZero(y.V);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else if (matchValue[0] === 0) {
|
||||
if (matchValue[1] === -1) {
|
||||
return true;
|
||||
}
|
||||
else if (matchValue[1] === 0) {
|
||||
return true;
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
return isZero(y.V);
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else if (matchValue[0] === 1) {
|
||||
if (matchValue[1] === -1) {
|
||||
return true;
|
||||
}
|
||||
else if (matchValue[1] === 0) {
|
||||
return true;
|
||||
}
|
||||
else if (matchValue[1] === 1) {
|
||||
return gte(x.V, y.V);
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
}
|
||||
export function toSByte(x) {
|
||||
return (toInt32(x) + 0x80 & 0xFF) - 0x80;
|
||||
}
|
||||
export function toByte(x) {
|
||||
return toUInt32(x) & 0xFF;
|
||||
}
|
||||
export function toInt16(x) {
|
||||
return (toInt32(x) + 0x8000 & 0xFFFF) - 0x8000;
|
||||
}
|
||||
export function toUInt16(x) {
|
||||
return toUInt32(x) & 0xFFFF;
|
||||
}
|
||||
export function toInt32(x) {
|
||||
if (x.IsZero) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
const u = bigNattoUInt32(x.V);
|
||||
if (u <= 2147483647 >>> 0) {
|
||||
return x.SignInt * ~~u;
|
||||
}
|
||||
else if (x.SignInt === -1 ? u === 2147483647 + 1 >>> 0 : false) {
|
||||
return -2147483648;
|
||||
}
|
||||
else {
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
}
|
||||
export function toUInt32(x) {
|
||||
if (x.IsZero) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return bigNattoUInt32(x.V);
|
||||
}
|
||||
}
|
||||
export function toInt64(x) {
|
||||
if (x.IsZero) {
|
||||
return fromBits(0, 0, false);
|
||||
}
|
||||
else {
|
||||
const u = bigNattoUInt64(x.V);
|
||||
if (u.CompareTo(fromBits(4294967295, 2147483647, false)) <= 0) {
|
||||
return fromNumber(x.SignInt, false).mul(u);
|
||||
}
|
||||
else if (x.SignInt === -1 ? u.Equals(fromBits(4294967295, 2147483647, false).add(fromBits(1, 0, false))) : false) {
|
||||
return fromBits(0, 2147483648, false);
|
||||
}
|
||||
else {
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
}
|
||||
export function toUInt64(x) {
|
||||
if (x.IsZero) {
|
||||
return fromBits(0, 0, true);
|
||||
}
|
||||
else {
|
||||
return bigNattoUInt64(x.V);
|
||||
}
|
||||
}
|
||||
export function toDouble(x) {
|
||||
const matchValue = x.SignInt;
|
||||
let $var20 = null;
|
||||
switch (matchValue) {
|
||||
case 1:
|
||||
$var20 = toFloat(x.V);
|
||||
break;
|
||||
case -1:
|
||||
$var20 = -toFloat(x.V);
|
||||
break;
|
||||
case 0:
|
||||
$var20 = 0;
|
||||
break;
|
||||
default:
|
||||
throw new Error("signs should be +/- 1 or 0" + "\nParameter name: " + "x");
|
||||
}
|
||||
return $var20;
|
||||
}
|
||||
export function toSingle(x) {
|
||||
return Math.fround(toDouble(x));
|
||||
}
|
||||
export function toDecimal(x) {
|
||||
return toDouble(x); //TODO: fix when decimal is implemented
|
||||
}
|
||||
export function parse(text) {
|
||||
if (text == null) {
|
||||
throw new Error("text");
|
||||
}
|
||||
const text_1 = trim(text, "both");
|
||||
const len = text_1.length;
|
||||
if (len === 0) {
|
||||
throw new Error();
|
||||
}
|
||||
const matchValue = [text_1[0], len];
|
||||
if (matchValue[0] === "+") {
|
||||
if (matchValue[1] === 1) {
|
||||
throw new Error();
|
||||
}
|
||||
else {
|
||||
return posn(ofString(text_1.slice(1, len - 1 + 1)));
|
||||
}
|
||||
}
|
||||
else if (matchValue[0] === "-") {
|
||||
if (matchValue[1] === 1) {
|
||||
throw new Error();
|
||||
}
|
||||
else {
|
||||
return negn(ofString(text_1.slice(1, len - 1 + 1)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
return posn(ofString(text_1));
|
||||
}
|
||||
}
|
||||
export function factorial(x) {
|
||||
if (x.IsNegative) {
|
||||
throw new Error("mustBeNonNegative" + "\nParameter name: " + "x");
|
||||
}
|
||||
if (x.IsPositive) {
|
||||
return posn(bigNatFactorial(x.V));
|
||||
}
|
||||
else {
|
||||
return one;
|
||||
}
|
||||
}
|
||||
export function op_UnaryPlus(n1) {
|
||||
return n1;
|
||||
}
|
||||
export function pow(x, y) {
|
||||
if (y < 0) {
|
||||
throw new Error("y");
|
||||
}
|
||||
const matchValue = [x.IsZero, y];
|
||||
if (matchValue[0]) {
|
||||
if (matchValue[1] === 0) {
|
||||
return one;
|
||||
}
|
||||
else {
|
||||
return zero;
|
||||
}
|
||||
}
|
||||
else {
|
||||
const yval = fromInt32(y);
|
||||
return create(isZero(rem(yval.V, bigNatTwo)) ? 1 : x.SignInt, bigNatPow(x.V, yval.V));
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,136 +0,0 @@
|
||||
import { fromNumber, fromBits } from "../Long";
|
||||
import { map, initialize, replicate } from "../Seq";
|
||||
export function pow32(x, n) {
|
||||
if (n === 0) {
|
||||
return 1;
|
||||
}
|
||||
else if (n % 2 === 0) {
|
||||
return pow32(x * x, ~~(n / 2));
|
||||
}
|
||||
else {
|
||||
return x * pow32(x * x, ~~(n / 2));
|
||||
}
|
||||
}
|
||||
export function leastBounding2Power(b) {
|
||||
const findBounding2Power = b_1 => tp => i => {
|
||||
if (b_1 <= tp) {
|
||||
return [tp, i];
|
||||
}
|
||||
else {
|
||||
return findBounding2Power(b_1)(tp * 2)(i + 1);
|
||||
}
|
||||
};
|
||||
return findBounding2Power(b)(1)(0);
|
||||
}
|
||||
export const k = 27;
|
||||
export const m = 15;
|
||||
export const g = 31;
|
||||
export const w = 440564289;
|
||||
export const primeP = fromBits(2013265921, 0, false);
|
||||
export const maxBitsInsideFp = 30;
|
||||
export const p = 2013265921;
|
||||
export const p64 = fromBits(2013265921, 0, true);
|
||||
export function toInt(x) {
|
||||
return ~~x;
|
||||
}
|
||||
export function ofInt32(x) {
|
||||
return x >>> 0;
|
||||
}
|
||||
export const mzero = 0;
|
||||
export const mone = 1;
|
||||
export const mtwo = 2;
|
||||
export function mpow(x, n) {
|
||||
if (n === 0) {
|
||||
return mone;
|
||||
}
|
||||
else if (n % 2 === 0) {
|
||||
return mpow(fromNumber(x, true).mul(fromNumber(x, true)).mod(p64).toNumber() >>> 0, ~~(n / 2));
|
||||
}
|
||||
else {
|
||||
return fromNumber(x, true).mul(fromNumber(mpow(fromNumber(x, true).mul(fromNumber(x, true)).mod(p64).toNumber() >>> 0, ~~(n / 2)), true)).mod(p64).toNumber() >>> 0;
|
||||
}
|
||||
}
|
||||
export function mpowL(x, n) {
|
||||
if (n.Equals(fromBits(0, 0, false))) {
|
||||
return mone;
|
||||
}
|
||||
else if (n.mod(fromBits(2, 0, false)).Equals(fromBits(0, 0, false))) {
|
||||
return mpowL(fromNumber(x, true).mul(fromNumber(x, true)).mod(p64).toNumber() >>> 0, n.div(fromBits(2, 0, false)));
|
||||
}
|
||||
else {
|
||||
return fromNumber(x, true).mul(fromNumber(mpowL(fromNumber(x, true).mul(fromNumber(x, true)).mod(p64).toNumber() >>> 0, n.div(fromBits(2, 0, false))), true)).mod(p64).toNumber() >>> 0;
|
||||
}
|
||||
}
|
||||
export function m2PowNthRoot(n) {
|
||||
return mpow(w >>> 0, pow32(2, k - n));
|
||||
}
|
||||
export function minv(x) {
|
||||
return mpowL(x, primeP.sub(fromBits(2, 0, false)));
|
||||
}
|
||||
export function computeFFT(lambda, mu, n, w_1, u, res, offset) {
|
||||
if (n === 1) {
|
||||
res[offset] = u[mu];
|
||||
}
|
||||
else {
|
||||
const halfN = ~~(n / 2);
|
||||
const ww = fromNumber(w_1, true).mul(fromNumber(w_1, true)).mod(p64).toNumber() >>> 0;
|
||||
const offsetHalfN = offset + halfN;
|
||||
computeFFT(lambda * 2, mu, halfN, ww, u, res, offset);
|
||||
computeFFT(lambda * 2, lambda + mu, halfN, ww, u, res, offsetHalfN);
|
||||
let wj = mone;
|
||||
for (let j = 0; j <= halfN - 1; j++) {
|
||||
const even = res[offset + j];
|
||||
const odd = res[offsetHalfN + j];
|
||||
res[offset + j] = (even + (fromNumber(wj, true).mul(fromNumber(odd, true)).mod(p64).toNumber() >>> 0)) % p;
|
||||
res[offsetHalfN + j] = (even + p - (fromNumber(wj, true).mul(fromNumber(odd, true)).mod(p64).toNumber() >>> 0)) % p;
|
||||
wj = fromNumber(w_1, true).mul(fromNumber(wj, true)).mod(p64).toNumber() >>> 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
export function computFftInPlace(n, w_1, u) {
|
||||
const lambda = 1;
|
||||
const mu = 0;
|
||||
const res = Uint32Array.from(replicate(n, mzero));
|
||||
const offset = 0;
|
||||
computeFFT(lambda, mu, n, w_1, u, res, offset);
|
||||
return res;
|
||||
}
|
||||
export function computeInverseFftInPlace(n, w_1, uT) {
|
||||
const bigKInv = minv(n >>> 0);
|
||||
return computFftInPlace(n, minv(w_1), uT).map(y => fromNumber(bigKInv, true).mul(fromNumber(y, true)).mod(p64).toNumber() >>> 0);
|
||||
}
|
||||
export const maxTwoPower = 29;
|
||||
export const twoPowerTable = Int32Array.from(initialize(maxTwoPower - 1, i => pow32(2, i)));
|
||||
export function computeFftPaddedPolynomialProduct(bigK, k_1, u, v) {
|
||||
const w_1 = m2PowNthRoot(k_1);
|
||||
const uT = computFftInPlace(bigK, w_1, u);
|
||||
const vT = computFftInPlace(bigK, w_1, v);
|
||||
const rT = Uint32Array.from(initialize(bigK, i => fromNumber(uT[i], true).mul(fromNumber(vT[i], true)).mod(p64).toNumber() >>> 0));
|
||||
const r = computeInverseFftInPlace(bigK, w_1, rT);
|
||||
return r;
|
||||
}
|
||||
export function padTo(n, u) {
|
||||
const uBound = u.length;
|
||||
return Uint32Array.from(initialize(n, i => {
|
||||
if (i < uBound) {
|
||||
return ofInt32(u[i]);
|
||||
}
|
||||
else {
|
||||
return mzero;
|
||||
}
|
||||
}));
|
||||
}
|
||||
export function computeFftPolynomialProduct(degu, u, degv, v) {
|
||||
const deguv = degu + degv;
|
||||
const bound = deguv + 1;
|
||||
const patternInput = leastBounding2Power(bound);
|
||||
const w_1 = m2PowNthRoot(patternInput[1]);
|
||||
const u_1 = padTo(patternInput[0], u);
|
||||
const v_1 = padTo(patternInput[0], v);
|
||||
const uT = computFftInPlace(patternInput[0], w_1, u_1);
|
||||
const vT = computFftInPlace(patternInput[0], w_1, v_1);
|
||||
const rT = Uint32Array.from(initialize(patternInput[0], i => fromNumber(uT[i], true).mul(fromNumber(vT[i], true)).mod(p64).toNumber() >>> 0));
|
||||
const r = computeInverseFftInPlace(patternInput[0], w_1, rT);
|
||||
return Int32Array.from(map(x => toInt(x), r));
|
||||
}
|
||||
export const maxFp = (p + p - mone) % p;
|
||||
@@ -1,115 +0,0 @@
|
||||
import { fromBits } from "./Long";
|
||||
const littleEndian = true;
|
||||
export function isLittleEndian() {
|
||||
return littleEndian;
|
||||
}
|
||||
export function getBytesBoolean(value) {
|
||||
const bytes = new Uint8Array(1);
|
||||
new DataView(bytes.buffer).setUint8(0, value ? 1 : 0);
|
||||
return bytes;
|
||||
}
|
||||
export function getBytesChar(value) {
|
||||
const bytes = new Uint8Array(2);
|
||||
new DataView(bytes.buffer).setUint16(0, value.charCodeAt(0), littleEndian);
|
||||
return bytes;
|
||||
}
|
||||
export function getBytesInt16(value) {
|
||||
const bytes = new Uint8Array(2);
|
||||
new DataView(bytes.buffer).setInt16(0, value, littleEndian);
|
||||
return bytes;
|
||||
}
|
||||
export function getBytesInt32(value) {
|
||||
const bytes = new Uint8Array(4);
|
||||
new DataView(bytes.buffer).setInt32(0, value, littleEndian);
|
||||
return bytes;
|
||||
}
|
||||
export function getBytesInt64(value) {
|
||||
const bytes = new Uint8Array(8);
|
||||
new DataView(bytes.buffer).setInt32(littleEndian ? 0 : 4, value.getLowBits(), littleEndian);
|
||||
new DataView(bytes.buffer).setInt32(littleEndian ? 4 : 0, value.getHighBits(), littleEndian);
|
||||
return bytes;
|
||||
}
|
||||
export function getBytesUInt16(value) {
|
||||
const bytes = new Uint8Array(2);
|
||||
new DataView(bytes.buffer).setUint16(0, value, littleEndian);
|
||||
return bytes;
|
||||
}
|
||||
export function getBytesUInt32(value) {
|
||||
const bytes = new Uint8Array(4);
|
||||
new DataView(bytes.buffer).setUint32(0, value, littleEndian);
|
||||
return bytes;
|
||||
}
|
||||
export function getBytesUInt64(value) {
|
||||
const bytes = new Uint8Array(8);
|
||||
new DataView(bytes.buffer).setUint32(littleEndian ? 0 : 4, value.getLowBitsUnsigned(), littleEndian);
|
||||
new DataView(bytes.buffer).setUint32(littleEndian ? 4 : 0, value.getHighBitsUnsigned(), littleEndian);
|
||||
return bytes;
|
||||
}
|
||||
export function getBytesSingle(value) {
|
||||
const bytes = new Uint8Array(4);
|
||||
new DataView(bytes.buffer).setFloat32(0, value, littleEndian);
|
||||
return bytes;
|
||||
}
|
||||
export function getBytesDouble(value) {
|
||||
const bytes = new Uint8Array(8);
|
||||
new DataView(bytes.buffer).setFloat64(0, value, littleEndian);
|
||||
return bytes;
|
||||
}
|
||||
export function int64BitsToDouble(value) {
|
||||
const buffer = new ArrayBuffer(8);
|
||||
new DataView(buffer).setInt32(littleEndian ? 0 : 4, value.getLowBits(), littleEndian);
|
||||
new DataView(buffer).setInt32(littleEndian ? 4 : 0, value.getHighBits(), littleEndian);
|
||||
return new DataView(buffer).getFloat64(0, littleEndian);
|
||||
}
|
||||
export function doubleToInt64Bits(value) {
|
||||
const buffer = new ArrayBuffer(8);
|
||||
new DataView(buffer).setFloat64(0, value, littleEndian);
|
||||
const lowBits = new DataView(buffer).getInt32(littleEndian ? 0 : 4, littleEndian);
|
||||
const highBits = new DataView(buffer).getInt32(littleEndian ? 4 : 0, littleEndian);
|
||||
return fromBits(lowBits, highBits, false);
|
||||
}
|
||||
export function toBoolean(bytes, offset) {
|
||||
return new DataView(bytes.buffer).getUint8(offset) === 1 ? true : false;
|
||||
}
|
||||
export function toChar(bytes, offset) {
|
||||
const code = new DataView(bytes.buffer).getUint16(offset, littleEndian);
|
||||
return String.fromCharCode(code);
|
||||
}
|
||||
export function toInt16(bytes, offset) {
|
||||
return new DataView(bytes.buffer).getInt16(offset, littleEndian);
|
||||
}
|
||||
export function toInt32(bytes, offset) {
|
||||
return new DataView(bytes.buffer).getInt32(offset, littleEndian);
|
||||
}
|
||||
export function toInt64(bytes, offset) {
|
||||
const lowBits = new DataView(bytes.buffer).getInt32(offset + (littleEndian ? 0 : 4), littleEndian);
|
||||
const highBits = new DataView(bytes.buffer).getInt32(offset + (littleEndian ? 4 : 0), littleEndian);
|
||||
return fromBits(lowBits, highBits, false);
|
||||
}
|
||||
export function toUInt16(bytes, offset) {
|
||||
return new DataView(bytes.buffer).getUint16(offset, littleEndian);
|
||||
}
|
||||
export function toUInt32(bytes, offset) {
|
||||
return new DataView(bytes.buffer).getUint32(offset, littleEndian);
|
||||
}
|
||||
export function toUInt64(bytes, offset) {
|
||||
const lowBits = new DataView(bytes.buffer).getUint32(offset + (littleEndian ? 0 : 4), littleEndian);
|
||||
const highBits = new DataView(bytes.buffer).getUint32(offset + (littleEndian ? 4 : 0), littleEndian);
|
||||
return fromBits(lowBits, highBits, true);
|
||||
}
|
||||
export function toSingle(bytes, offset) {
|
||||
return new DataView(bytes.buffer).getFloat32(offset, littleEndian);
|
||||
}
|
||||
export function toDouble(bytes, offset) {
|
||||
return new DataView(bytes.buffer).getFloat64(offset, littleEndian);
|
||||
}
|
||||
export function toString(bytes, offset, count) {
|
||||
let ar = bytes;
|
||||
if (typeof offset !== "undefined" && typeof count !== "undefined") {
|
||||
ar = bytes.subarray(offset, offset + count);
|
||||
}
|
||||
else if (typeof offset !== "undefined") {
|
||||
ar = bytes.subarray(offset);
|
||||
}
|
||||
return Array.from(ar).map((b) => ("0" + b.toString(16)).slice(-2)).join("-");
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
function isChar(input) {
|
||||
return typeof input === "string" && input.length === 1;
|
||||
}
|
||||
export function isLetter(input) {
|
||||
return isChar(input) && input.toLowerCase() !== input.toUpperCase();
|
||||
}
|
||||
export function isUpper(input) {
|
||||
return isLetter(input) && input.toUpperCase() === input;
|
||||
}
|
||||
export function isLower(input) {
|
||||
return isLetter(input) && input.toLowerCase() === input;
|
||||
}
|
||||
export function isDigit(input) {
|
||||
return isChar(input) && /\d/.test(input);
|
||||
}
|
||||
export function isLetterOrDigit(input) {
|
||||
return isChar(input) &&
|
||||
(input.toLowerCase() !== input.toUpperCase() || /\d/.test(input));
|
||||
}
|
||||
export function isWhiteSpace(input) {
|
||||
return isChar(input) && /\s/.test(input);
|
||||
}
|
||||
export function parse(input) {
|
||||
if (isChar(input)) {
|
||||
return input[0];
|
||||
}
|
||||
else {
|
||||
throw Error("String must be exactly one character long.");
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
import FSymbol from "./Symbol";
|
||||
import { Any } from "./Util";
|
||||
import { compareUnions, equalsUnions } from "./Util";
|
||||
export function choice1Of2(v) {
|
||||
return new Choice(0, v);
|
||||
}
|
||||
export function choice2Of2(v) {
|
||||
return new Choice(1, v);
|
||||
}
|
||||
export default class Choice {
|
||||
constructor(tag, data) {
|
||||
this.tag = tag | 0;
|
||||
this.data = data;
|
||||
}
|
||||
get valueIfChoice1() {
|
||||
return this.tag === 0 ? this.data : null;
|
||||
}
|
||||
get valueIfChoice2() {
|
||||
return this.tag === 1 ? this.data : null;
|
||||
}
|
||||
Equals(other) {
|
||||
return equalsUnions(this, other);
|
||||
}
|
||||
CompareTo(other) {
|
||||
return compareUnions(this, other);
|
||||
}
|
||||
[FSymbol.reflection]() {
|
||||
return {
|
||||
type: "Microsoft.FSharp.Core.FSharpChoice",
|
||||
interfaces: ["FSharpUnion", "System.IEquatable", "System.IComparable"],
|
||||
cases: [["Choice1Of2", Any], ["Choice2Of2", Any]],
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
import FSymbol from "./Symbol";
|
||||
import { compare } from "./Util";
|
||||
export default class Comparer {
|
||||
constructor(f) {
|
||||
this.Compare = f || compare;
|
||||
}
|
||||
[FSymbol.reflection]() {
|
||||
return { interfaces: ["System.IComparer"] };
|
||||
}
|
||||
}
|
||||
export function fromEqualityComparer(comparer) {
|
||||
// Sometimes IEqualityComparer also implements IComparer
|
||||
if (typeof comparer.Compare === "function") {
|
||||
return new Comparer(comparer.Compare);
|
||||
}
|
||||
else {
|
||||
return new Comparer((x, y) => {
|
||||
const xhash = comparer.GetHashCode(x);
|
||||
const yhash = comparer.GetHashCode(y);
|
||||
if (xhash === yhash) {
|
||||
return comparer.Equals(x, y) ? 0 : -1;
|
||||
}
|
||||
else {
|
||||
return xhash < yhash ? -1 : 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
export default function CurriedLambda(f, expectedArgsLength) {
|
||||
if (f.curried === true) {
|
||||
return f;
|
||||
}
|
||||
const curriedFn = (...args) => {
|
||||
const args2 = args.map((x) => typeof x === "function" ? CurriedLambda(x) : x);
|
||||
const actualArgsLength = Math.max(args2.length, 1);
|
||||
expectedArgsLength = Math.max(expectedArgsLength || f.length, 1);
|
||||
if (actualArgsLength >= expectedArgsLength) {
|
||||
const restArgs = args2.splice(expectedArgsLength);
|
||||
const res = f(...args2);
|
||||
if (typeof res === "function") {
|
||||
const newLambda = CurriedLambda(res);
|
||||
return restArgs.length === 0 ? newLambda : newLambda(...restArgs);
|
||||
}
|
||||
else {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return CurriedLambda((...args3) => {
|
||||
return f(...args2.concat(args3));
|
||||
}, expectedArgsLength - actualArgsLength);
|
||||
}
|
||||
};
|
||||
curriedFn.curried = true;
|
||||
return curriedFn;
|
||||
}
|
||||
-342
@@ -1,342 +0,0 @@
|
||||
export const offsetRegex = /(?:Z|[+-](\d{2}):?(\d{2})?)$/;
|
||||
export function padWithZeros(i, length) {
|
||||
let str = i.toString(10);
|
||||
while (str.length < length) {
|
||||
str = "0" + str;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
export function offsetToString(offset) {
|
||||
const isMinus = offset < 0;
|
||||
offset = Math.abs(offset);
|
||||
const hours = ~~(offset / 3600000);
|
||||
const minutes = (offset % 3600000) / 60000;
|
||||
return (isMinus ? "-" : "+") +
|
||||
padWithZeros(hours, 2) + ":" +
|
||||
padWithZeros(minutes, 2);
|
||||
}
|
||||
export function toHalfUTCString(date, half) {
|
||||
const str = date.toISOString();
|
||||
return half === "first"
|
||||
? str.substring(0, str.indexOf("T"))
|
||||
: str.substring(str.indexOf("T") + 1, str.length - 1);
|
||||
}
|
||||
function toISOString(d, utc) {
|
||||
if (utc) {
|
||||
return d.toISOString();
|
||||
}
|
||||
else {
|
||||
// JS Date is always local
|
||||
const printOffset = d.kind == null ? true : d.kind === 2 /* Local */;
|
||||
return padWithZeros(d.getFullYear(), 4) + "-" +
|
||||
padWithZeros(d.getMonth() + 1, 2) + "-" +
|
||||
padWithZeros(d.getDate(), 2) + "T" +
|
||||
padWithZeros(d.getHours(), 2) + ":" +
|
||||
padWithZeros(d.getMinutes(), 2) + ":" +
|
||||
padWithZeros(d.getSeconds(), 2) + "." +
|
||||
padWithZeros(d.getMilliseconds(), 3) +
|
||||
(printOffset ? offsetToString(d.getTimezoneOffset() * -60000) : "");
|
||||
}
|
||||
}
|
||||
function toISOStringWithOffset(dateWithOffset, offset) {
|
||||
const str = dateWithOffset.toISOString();
|
||||
return str.substring(0, str.length - 1) + offsetToString(offset);
|
||||
}
|
||||
function toStringWithCustomFormat(date, format, utc) {
|
||||
return format.replace(/(\w)\1*/g, (match) => {
|
||||
let rep = match;
|
||||
switch (match.substring(0, 1)) {
|
||||
case "y":
|
||||
const y = utc ? date.getUTCFullYear() : date.getFullYear();
|
||||
rep = match.length < 4 ? y % 100 : y;
|
||||
break;
|
||||
case "M":
|
||||
rep = (utc ? date.getUTCMonth() : date.getMonth()) + 1;
|
||||
break;
|
||||
case "d":
|
||||
rep = utc ? date.getUTCDate() : date.getDate();
|
||||
break;
|
||||
case "H":
|
||||
rep = utc ? date.getUTCHours() : date.getHours();
|
||||
break;
|
||||
case "h":
|
||||
const h = utc ? date.getUTCHours() : date.getHours();
|
||||
rep = h > 12 ? h % 12 : h;
|
||||
break;
|
||||
case "m":
|
||||
rep = utc ? date.getUTCMinutes() : date.getMinutes();
|
||||
break;
|
||||
case "s":
|
||||
rep = utc ? date.getUTCSeconds() : date.getSeconds();
|
||||
break;
|
||||
}
|
||||
if (rep !== match && rep < 10 && match.length > 1) {
|
||||
rep = "0" + rep;
|
||||
}
|
||||
return rep;
|
||||
});
|
||||
}
|
||||
export function toStringWithOffset(date, format) {
|
||||
const d = new Date(date.getTime() + date.offset);
|
||||
if (!format) {
|
||||
return d.toISOString().replace(/\.\d+/, "").replace(/[A-Z]|\.\d+/g, " ") + offsetToString(date.offset);
|
||||
}
|
||||
else if (format.length === 1) {
|
||||
switch (format) {
|
||||
case "D":
|
||||
case "d": return toHalfUTCString(d, "first");
|
||||
case "T":
|
||||
case "t": return toHalfUTCString(d, "second");
|
||||
case "O":
|
||||
case "o": return toISOStringWithOffset(d, date.offset);
|
||||
default: throw new Error("Unrecognized Date print format");
|
||||
}
|
||||
}
|
||||
else {
|
||||
return toStringWithCustomFormat(d, format, true);
|
||||
}
|
||||
}
|
||||
export function toStringWithKind(date, format) {
|
||||
const utc = date.kind === 1 /* UTC */;
|
||||
if (!format) {
|
||||
return utc ? date.toUTCString() : date.toLocaleString();
|
||||
}
|
||||
else if (format.length === 1) {
|
||||
switch (format) {
|
||||
case "D":
|
||||
case "d":
|
||||
return utc ? toHalfUTCString(date, "first") : date.toLocaleDateString();
|
||||
case "T":
|
||||
case "t":
|
||||
return utc ? toHalfUTCString(date, "second") : date.toLocaleTimeString();
|
||||
case "O":
|
||||
case "o":
|
||||
return toISOString(date, utc);
|
||||
default:
|
||||
throw new Error("Unrecognized Date print format");
|
||||
}
|
||||
}
|
||||
else {
|
||||
return toStringWithCustomFormat(date, format, utc);
|
||||
}
|
||||
}
|
||||
export function toString(date, format) {
|
||||
return date.offset != null
|
||||
? toStringWithOffset(date, format)
|
||||
: toStringWithKind(date, format);
|
||||
}
|
||||
export default function DateTime(value, kind) {
|
||||
kind = kind == null ? 0 /* Unspecified */ : kind;
|
||||
const d = new Date(value);
|
||||
d.kind = kind | 0;
|
||||
return d;
|
||||
}
|
||||
export function minValue() {
|
||||
// This is "0001-01-01T00:00:00.000Z", actual JS min value is -8640000000000000
|
||||
return DateTime(-62135596800000, 0 /* Unspecified */);
|
||||
}
|
||||
export function maxValue() {
|
||||
// This is "9999-12-31T23:59:59.999Z", actual JS max value is 8640000000000000
|
||||
return DateTime(253402300799999, 0 /* Unspecified */);
|
||||
}
|
||||
export function parseRaw(str) {
|
||||
let date = new Date(str);
|
||||
if (isNaN(date.getTime())) {
|
||||
// Check if this is a time-only string, which JS Date parsing cannot handle (see #1045)
|
||||
if (/^(?:[01]?\d|2[0-3]):(?:[0-5]?\d)(?::[0-5]?\d(?:\.\d+)?)?(?:\s*[AaPp][Mm])?$/.test(str)) {
|
||||
const d = new Date();
|
||||
date = new Date(d.getFullYear() + "/" + (d.getMonth() + 1) + "/" + d.getDate() + " " + str);
|
||||
}
|
||||
else {
|
||||
throw new Error("The string is not a valid Date.");
|
||||
}
|
||||
}
|
||||
return date;
|
||||
}
|
||||
export function parse(str, detectUTC = false) {
|
||||
const date = parseRaw(str);
|
||||
const offset = offsetRegex.exec(str);
|
||||
// .NET always parses DateTime as Local if there's offset info (even "Z")
|
||||
// Newtonsoft.Json uses UTC if the offset is "Z"
|
||||
const kind = offset != null
|
||||
? (detectUTC && offset[0] === "Z" ? 1 /* UTC */ : 2 /* Local */)
|
||||
: 0 /* Unspecified */;
|
||||
return DateTime(date.getTime(), kind);
|
||||
}
|
||||
export function tryParse(v) {
|
||||
try {
|
||||
return [true, parse(v)];
|
||||
}
|
||||
catch (_err) {
|
||||
return [false, minValue()];
|
||||
}
|
||||
}
|
||||
export function offset(date) {
|
||||
const date1 = date;
|
||||
return typeof date1.offset === "number"
|
||||
? date1.offset
|
||||
: (date.kind === 1 /* UTC */
|
||||
? 0 : date.getTimezoneOffset() * -60000);
|
||||
}
|
||||
export function create(year, month, day, h = 0, m = 0, s = 0, ms = 0, kind) {
|
||||
const dateValue = kind === 1 /* UTC */
|
||||
? Date.UTC(year, month - 1, day, h, m, s, ms)
|
||||
: new Date(year, month - 1, day, h, m, s, ms).getTime();
|
||||
if (isNaN(dateValue)) {
|
||||
throw new Error("The parameters describe an unrepresentable Date.");
|
||||
}
|
||||
const date = DateTime(dateValue, kind);
|
||||
if (year <= 99) {
|
||||
date.setFullYear(year, month - 1, day);
|
||||
}
|
||||
return date;
|
||||
}
|
||||
export function now() {
|
||||
return DateTime(Date.now(), 2 /* Local */);
|
||||
}
|
||||
export function utcNow() {
|
||||
return DateTime(Date.now(), 1 /* UTC */);
|
||||
}
|
||||
export function today() {
|
||||
return date(now());
|
||||
}
|
||||
export function isLeapYear(year) {
|
||||
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
||||
}
|
||||
export function daysInMonth(year, month) {
|
||||
return month === 2
|
||||
? (isLeapYear(year) ? 29 : 28)
|
||||
: (month >= 8 ? (month % 2 === 0 ? 31 : 30) : (month % 2 === 0 ? 30 : 31));
|
||||
}
|
||||
export function toUniversalTime(date) {
|
||||
return date.kind === 1 /* UTC */ ? date : DateTime(date.getTime(), 1 /* UTC */);
|
||||
}
|
||||
export function toLocalTime(date) {
|
||||
return date.kind === 2 /* Local */ ? date : DateTime(date.getTime(), 2 /* Local */);
|
||||
}
|
||||
export function timeOfDay(d) {
|
||||
return hour(d) * 3600000
|
||||
+ minute(d) * 60000
|
||||
+ second(d) * 1000
|
||||
+ millisecond(d);
|
||||
}
|
||||
export function date(d) {
|
||||
return create(year(d), month(d), day(d), 0, 0, 0, 0, d.kind);
|
||||
}
|
||||
export function day(d) {
|
||||
return d.kind === 1 /* UTC */ ? d.getUTCDate() : d.getDate();
|
||||
}
|
||||
export function hour(d) {
|
||||
return d.kind === 1 /* UTC */ ? d.getUTCHours() : d.getHours();
|
||||
}
|
||||
export function millisecond(d) {
|
||||
return d.kind === 1 /* UTC */ ? d.getUTCMilliseconds() : d.getMilliseconds();
|
||||
}
|
||||
export function minute(d) {
|
||||
return d.kind === 1 /* UTC */ ? d.getUTCMinutes() : d.getMinutes();
|
||||
}
|
||||
export function month(d) {
|
||||
return (d.kind === 1 /* UTC */ ? d.getUTCMonth() : d.getMonth()) + 1;
|
||||
}
|
||||
export function second(d) {
|
||||
return d.kind === 1 /* UTC */ ? d.getUTCSeconds() : d.getSeconds();
|
||||
}
|
||||
export function year(d) {
|
||||
return d.kind === 1 /* UTC */ ? d.getUTCFullYear() : d.getFullYear();
|
||||
}
|
||||
export function dayOfWeek(d) {
|
||||
return d.kind === 1 /* UTC */ ? d.getUTCDay() : d.getDay();
|
||||
}
|
||||
export function dayOfYear(d) {
|
||||
const _year = year(d);
|
||||
const _month = month(d);
|
||||
let _day = day(d);
|
||||
for (let i = 1; i < _month; i++) {
|
||||
_day += daysInMonth(_year, i);
|
||||
}
|
||||
return _day;
|
||||
}
|
||||
export function add(d, ts) {
|
||||
return DateTime(d.getTime() + ts, d.kind);
|
||||
}
|
||||
export function addDays(d, v) {
|
||||
return DateTime(d.getTime() + v * 86400000, d.kind);
|
||||
}
|
||||
export function addHours(d, v) {
|
||||
return DateTime(d.getTime() + v * 3600000, d.kind);
|
||||
}
|
||||
export function addMinutes(d, v) {
|
||||
return DateTime(d.getTime() + v * 60000, d.kind);
|
||||
}
|
||||
export function addSeconds(d, v) {
|
||||
return DateTime(d.getTime() + v * 1000, d.kind);
|
||||
}
|
||||
export function addMilliseconds(d, v) {
|
||||
return DateTime(d.getTime() + v, d.kind);
|
||||
}
|
||||
export function addYears(d, v) {
|
||||
const newMonth = month(d);
|
||||
const newYear = year(d) + v;
|
||||
const _daysInMonth = daysInMonth(newYear, newMonth);
|
||||
const newDay = Math.min(_daysInMonth, day(d));
|
||||
return create(newYear, newMonth, newDay, hour(d), minute(d), second(d), millisecond(d), d.kind);
|
||||
}
|
||||
export function addMonths(d, v) {
|
||||
let newMonth = month(d) + v;
|
||||
let newMonth_ = 0;
|
||||
let yearOffset = 0;
|
||||
if (newMonth > 12) {
|
||||
newMonth_ = newMonth % 12;
|
||||
yearOffset = Math.floor(newMonth / 12);
|
||||
newMonth = newMonth_;
|
||||
}
|
||||
else if (newMonth < 1) {
|
||||
newMonth_ = 12 + newMonth % 12;
|
||||
yearOffset = Math.floor(newMonth / 12) + (newMonth_ === 12 ? -1 : 0);
|
||||
newMonth = newMonth_;
|
||||
}
|
||||
const newYear = year(d) + yearOffset;
|
||||
const _daysInMonth = daysInMonth(newYear, newMonth);
|
||||
const newDay = Math.min(_daysInMonth, day(d));
|
||||
return create(newYear, newMonth, newDay, hour(d), minute(d), second(d), millisecond(d), d.kind);
|
||||
}
|
||||
export function subtract(d, that) {
|
||||
return typeof that === "number"
|
||||
? DateTime(d.getTime() - that, d.kind)
|
||||
: d.getTime() - that.getTime();
|
||||
}
|
||||
export function toLongDateString(d) {
|
||||
return d.toDateString();
|
||||
}
|
||||
export function toShortDateString(d) {
|
||||
return d.toLocaleDateString();
|
||||
}
|
||||
export function toLongTimeString(d) {
|
||||
return d.toLocaleTimeString();
|
||||
}
|
||||
export function toShortTimeString(d) {
|
||||
return d.toLocaleTimeString().replace(/:\d\d(?!:)/, "");
|
||||
}
|
||||
export function equals(d1, d2) {
|
||||
return d1.getTime() === d2.getTime();
|
||||
}
|
||||
export function compare(x, y) {
|
||||
const xtime = x.getTime();
|
||||
const ytime = y.getTime();
|
||||
return xtime === ytime ? 0 : (xtime < ytime ? -1 : 1);
|
||||
}
|
||||
export const compareTo = compare;
|
||||
export function op_Addition(x, y) {
|
||||
return add(x, y);
|
||||
}
|
||||
export function op_Subtraction(x, y) {
|
||||
return subtract(x, y);
|
||||
}
|
||||
export function isDaylightSavingTime(x) {
|
||||
const jan = new Date(x.getFullYear(), 0, 1);
|
||||
const jul = new Date(x.getFullYear(), 6, 1);
|
||||
return isDST(jan.getTimezoneOffset(), jul.getTimezoneOffset(), x.getTimezoneOffset());
|
||||
}
|
||||
function isDST(janOffset, julOffset, tOffset) {
|
||||
return Math.min(janOffset, julOffset) === tOffset;
|
||||
}
|
||||
@@ -1,204 +0,0 @@
|
||||
import { compare as compareDates, create as createDate, daysInMonth, offsetRegex, offsetToString, padWithZeros, parseRaw } from "./Date";
|
||||
export default function DateTimeOffset(value, offset) {
|
||||
const d = new Date(value);
|
||||
d.offset = offset != null ? offset : new Date().getTimezoneOffset() * -60000;
|
||||
return d;
|
||||
}
|
||||
export function fromDate(date, offset) {
|
||||
const isUtc = date.kind === 1 /* UTC */;
|
||||
const offset2 = isUtc ? 0 : date.getTimezoneOffset() * -60000;
|
||||
if (offset != null && offset !== offset2) {
|
||||
throw new Error(isUtc
|
||||
? "The UTC Offset for Utc DateTime instances must be 0."
|
||||
: "The UTC Offset of the local dateTime parameter does not match the offset argument.");
|
||||
}
|
||||
return DateTimeOffset(date.getTime(), offset2);
|
||||
}
|
||||
export function minValue() {
|
||||
// This is "0001-01-01T00:00:00.000Z", actual JS min value is -8640000000000000
|
||||
return DateTimeOffset(-62135596800000, 0);
|
||||
}
|
||||
export function maxValue() {
|
||||
// This is "9999-12-31T23:59:59.999Z", actual JS max value is 8640000000000000
|
||||
return DateTimeOffset(253402300799999, 0);
|
||||
}
|
||||
export function parse(str) {
|
||||
const date = parseRaw(str);
|
||||
const offsetMatch = offsetRegex.exec(str);
|
||||
const offset = offsetMatch == null
|
||||
? date.getTimezoneOffset() * -60000
|
||||
: (offsetMatch[0] === "Z"
|
||||
? 0
|
||||
: parseInt(offsetMatch[1], 10) * 3600000
|
||||
+ parseInt(offsetMatch[2], 10) * 60000);
|
||||
return DateTimeOffset(date.getTime(), offset);
|
||||
}
|
||||
export function tryParse(v) {
|
||||
try {
|
||||
return [true, parse(v)];
|
||||
}
|
||||
catch (_err) {
|
||||
return [false, minValue()];
|
||||
}
|
||||
}
|
||||
export function create(year, month, day, h, m, s, ms, offset) {
|
||||
if (offset == null) {
|
||||
offset = ms;
|
||||
ms = 0;
|
||||
}
|
||||
if (offset !== 0) {
|
||||
if (offset % 60000 !== 0) {
|
||||
throw new Error("Offset must be specified in whole minutes");
|
||||
}
|
||||
if (~~(offset / 3600000) > 14) {
|
||||
throw new Error("Offset must be within plus or minus 14 hour");
|
||||
}
|
||||
}
|
||||
let date;
|
||||
if (offset === 0) {
|
||||
date = new Date(Date.UTC(year, month - 1, day, h, m, s, ms));
|
||||
if (year <= 99) {
|
||||
date.setFullYear(year, month - 1, day);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const str = padWithZeros(year, 4) + "-" +
|
||||
padWithZeros(month, 2) + "-" +
|
||||
padWithZeros(day, 2) + "T" +
|
||||
padWithZeros(h, 2) + ":" +
|
||||
padWithZeros(m, 2) + ":" +
|
||||
padWithZeros(s, 2) + "." +
|
||||
padWithZeros(ms, 3) +
|
||||
offsetToString(offset);
|
||||
date = new Date(str);
|
||||
}
|
||||
const dateValue = date.getTime();
|
||||
if (isNaN(dateValue)) {
|
||||
throw new Error("The parameters describe an unrepresentable Date");
|
||||
}
|
||||
return DateTimeOffset(dateValue, offset);
|
||||
}
|
||||
export function now() {
|
||||
const date = new Date();
|
||||
return DateTimeOffset(date.getTime(), date.getTimezoneOffset() * -60000);
|
||||
}
|
||||
export function utcNow() {
|
||||
return DateTimeOffset(Date.now(), 0);
|
||||
}
|
||||
export function toUniversalTime(date) {
|
||||
return DateTimeOffset(date.getTime(), 0);
|
||||
}
|
||||
export function toLocalTime(date) {
|
||||
return DateTimeOffset(date.getTime(), date.getTimezoneOffset() * -60000);
|
||||
}
|
||||
export function timeOfDay(d) {
|
||||
const d2 = new Date(d.getTime() + d.offset);
|
||||
return d2.getUTCHours() * 3600000
|
||||
+ d2.getUTCMinutes() * 60000
|
||||
+ d2.getUTCSeconds() * 1000
|
||||
+ d2.getUTCMilliseconds();
|
||||
}
|
||||
export function date(d) {
|
||||
const d2 = new Date(d.getTime() + d.offset);
|
||||
return createDate(d2.getUTCFullYear(), d2.getUTCMonth() + 1, d2.getUTCDate(), 0, 0, 0, 0);
|
||||
}
|
||||
export function day(d) {
|
||||
return new Date(d.getTime() + d.offset).getUTCDate();
|
||||
}
|
||||
export function hour(d) {
|
||||
return new Date(d.getTime() + d.offset).getUTCHours();
|
||||
}
|
||||
export function millisecond(d) {
|
||||
return new Date(d.getTime() + d.offset).getUTCMilliseconds();
|
||||
}
|
||||
export function minute(d) {
|
||||
return new Date(d.getTime() + d.offset).getUTCMinutes();
|
||||
}
|
||||
export function month(d) {
|
||||
return new Date(d.getTime() + d.offset).getUTCMonth() + 1;
|
||||
}
|
||||
export function second(d) {
|
||||
return new Date(d.getTime() + d.offset).getUTCSeconds();
|
||||
}
|
||||
export function year(d) {
|
||||
return new Date(d.getTime() + d.offset).getUTCFullYear();
|
||||
}
|
||||
export function dayOfWeek(d) {
|
||||
return new Date(d.getTime() + d.offset).getUTCDay();
|
||||
}
|
||||
export function dayOfYear(d) {
|
||||
const d2 = new Date(d.getTime() + d.offset);
|
||||
const _year = d2.getUTCFullYear();
|
||||
const _month = d2.getUTCMonth() + 1;
|
||||
let _day = d2.getUTCDate();
|
||||
for (let i = 1; i < _month; i++) {
|
||||
_day += daysInMonth(_year, i);
|
||||
}
|
||||
return _day;
|
||||
}
|
||||
export function add(d, ts) {
|
||||
return DateTimeOffset(d.getTime() + ts, d.offset);
|
||||
}
|
||||
export function addDays(d, v) {
|
||||
return DateTimeOffset(d.getTime() + v * 86400000, d.offset);
|
||||
}
|
||||
export function addHours(d, v) {
|
||||
return DateTimeOffset(d.getTime() + v * 3600000, d.offset);
|
||||
}
|
||||
export function addMinutes(d, v) {
|
||||
return DateTimeOffset(d.getTime() + v * 60000, d.offset);
|
||||
}
|
||||
export function addSeconds(d, v) {
|
||||
return DateTimeOffset(d.getTime() + v * 1000, d.offset);
|
||||
}
|
||||
export function addMilliseconds(d, v) {
|
||||
return DateTimeOffset(d.getTime() + v, d.offset);
|
||||
}
|
||||
export function addYears(d, v) {
|
||||
const newMonth = d.getUTCMonth() + 1;
|
||||
const newYear = d.getUTCFullYear() + v;
|
||||
const _daysInMonth = daysInMonth(newYear, newMonth);
|
||||
const newDay = Math.min(_daysInMonth, d.getUTCDate());
|
||||
return create(newYear, newMonth, newDay, d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds(), d.offset);
|
||||
}
|
||||
export function addMonths(d, v) {
|
||||
const d2 = new Date(d.getTime() + d.offset);
|
||||
let newMonth = d2.getUTCMonth() + 1 + v;
|
||||
let newMonth_ = 0;
|
||||
let yearOffset = 0;
|
||||
if (newMonth > 12) {
|
||||
newMonth_ = newMonth % 12;
|
||||
yearOffset = Math.floor(newMonth / 12);
|
||||
newMonth = newMonth_;
|
||||
}
|
||||
else if (newMonth < 1) {
|
||||
newMonth_ = 12 + newMonth % 12;
|
||||
yearOffset = Math.floor(newMonth / 12) + (newMonth_ === 12 ? -1 : 0);
|
||||
newMonth = newMonth_;
|
||||
}
|
||||
const newYear = d2.getUTCFullYear() + yearOffset;
|
||||
const _daysInMonth = daysInMonth(newYear, newMonth);
|
||||
const newDay = Math.min(_daysInMonth, d2.getUTCDate());
|
||||
return create(newYear, newMonth, newDay, d2.getUTCHours(), d2.getUTCMinutes(), d2.getUTCSeconds(), d2.getUTCMilliseconds(), d.offset);
|
||||
}
|
||||
export function subtract(d, that) {
|
||||
return typeof that === "number"
|
||||
? DateTimeOffset(d.getTime() - that, d.offset)
|
||||
: d.getTime() - that.getTime();
|
||||
}
|
||||
export function equals(d1, d2) {
|
||||
return d1.getTime() === d2.getTime();
|
||||
}
|
||||
export function equalsExact(d1, d2) {
|
||||
return d1.getTime() === d2.getTime() && d1.offset === d2.offset;
|
||||
}
|
||||
export function compare(d1, d2) {
|
||||
return compareDates(d1, d2);
|
||||
}
|
||||
export const compareTo = compare;
|
||||
export function op_Addition(x, y) {
|
||||
return add(x, y);
|
||||
}
|
||||
export function op_Subtraction(x, y) {
|
||||
return subtract(x, y);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
// TODO does this perfectly match the .NET behavior ?
|
||||
export function tryParse(s, radix, initial) {
|
||||
if (s != null && /\S/.test(s)) {
|
||||
if (radix === 10) {
|
||||
const v = +s;
|
||||
if (!Number.isNaN(v)) {
|
||||
return [true, v];
|
||||
}
|
||||
}
|
||||
}
|
||||
return [false, initial != null ? initial : 0];
|
||||
}
|
||||
export function parse(s, radix = 10) {
|
||||
const a = tryParse(s, radix, 0);
|
||||
if (a[0]) {
|
||||
return a[1];
|
||||
}
|
||||
else {
|
||||
// TODO FormatException ?
|
||||
throw new Error("Input string was not in a correct format.");
|
||||
}
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
import { Observer, protect } from "./Observable";
|
||||
import { getValue } from "./Option";
|
||||
import { iterate as seqIterate } from "./Seq";
|
||||
import { createDisposable } from "./Util";
|
||||
export default class Event {
|
||||
constructor(_subscriber, delegates) {
|
||||
this._subscriber = _subscriber;
|
||||
this.delegates = delegates || new Array();
|
||||
}
|
||||
Add(f) {
|
||||
this._addHandler(f);
|
||||
}
|
||||
// IEvent<T> methods
|
||||
get Publish() {
|
||||
return this;
|
||||
}
|
||||
Trigger(value) {
|
||||
seqIterate((f) => f(value), this.delegates);
|
||||
}
|
||||
// IDelegateEvent<T> methods
|
||||
AddHandler(handler) {
|
||||
if (this._dotnetDelegates == null) {
|
||||
this._dotnetDelegates = new Map();
|
||||
}
|
||||
const f = (x) => handler(null, x);
|
||||
this._dotnetDelegates.set(handler, f);
|
||||
this._addHandler(f);
|
||||
}
|
||||
RemoveHandler(handler) {
|
||||
if (this._dotnetDelegates != null) {
|
||||
const f = this._dotnetDelegates.get(handler);
|
||||
if (f != null) {
|
||||
this._dotnetDelegates.delete(handler);
|
||||
this._removeHandler(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
// IObservable<T> methods
|
||||
Subscribe(arg) {
|
||||
return typeof arg === "function"
|
||||
? this._subscribeFromCallback(arg)
|
||||
: this._subscribeFromObserver(arg);
|
||||
}
|
||||
_addHandler(f) {
|
||||
this.delegates.push(f);
|
||||
}
|
||||
_removeHandler(f) {
|
||||
const index = this.delegates.indexOf(f);
|
||||
if (index > -1) {
|
||||
this.delegates.splice(index, 1);
|
||||
}
|
||||
}
|
||||
_subscribeFromObserver(observer) {
|
||||
if (this._subscriber) {
|
||||
return this._subscriber(observer);
|
||||
}
|
||||
const callback = observer.OnNext;
|
||||
this._addHandler(callback);
|
||||
return createDisposable(() => this._removeHandler(callback));
|
||||
}
|
||||
_subscribeFromCallback(callback) {
|
||||
this._addHandler(callback);
|
||||
return createDisposable(() => this._removeHandler(callback));
|
||||
}
|
||||
}
|
||||
export function add(callback, sourceEvent) {
|
||||
sourceEvent.Subscribe(new Observer(callback));
|
||||
}
|
||||
export function choose(chooser, sourceEvent) {
|
||||
const source = sourceEvent;
|
||||
return new Event((observer) => source.Subscribe(new Observer((t) => protect(() => chooser(t), (u) => { if (u != null) {
|
||||
observer.OnNext(getValue(u));
|
||||
} }, observer.OnError), observer.OnError, observer.OnCompleted)), source.delegates);
|
||||
}
|
||||
export function filter(predicate, sourceEvent) {
|
||||
return choose((x) => predicate(x) ? x : null, sourceEvent);
|
||||
}
|
||||
export function map(mapping, sourceEvent) {
|
||||
const source = sourceEvent;
|
||||
return new Event((observer) => source.Subscribe(new Observer((t) => protect(() => mapping(t), observer.OnNext, observer.OnError), observer.OnError, observer.OnCompleted)), source.delegates);
|
||||
}
|
||||
export function merge(event1, event2) {
|
||||
const source1 = event1;
|
||||
const source2 = event2;
|
||||
return new Event((observer) => {
|
||||
let stopped = false;
|
||||
let completed1 = false;
|
||||
let completed2 = false;
|
||||
const h1 = source1.Subscribe(new Observer((v) => { if (!stopped) {
|
||||
observer.OnNext(v);
|
||||
} }, (e) => {
|
||||
if (!stopped) {
|
||||
stopped = true;
|
||||
observer.OnError(e);
|
||||
}
|
||||
}, () => {
|
||||
if (!stopped) {
|
||||
completed1 = true;
|
||||
if (completed2) {
|
||||
stopped = true;
|
||||
observer.OnCompleted();
|
||||
}
|
||||
}
|
||||
}));
|
||||
const h2 = source2.Subscribe(new Observer((v) => { if (!stopped) {
|
||||
observer.OnNext(v);
|
||||
} }, (e) => {
|
||||
if (!stopped) {
|
||||
stopped = true;
|
||||
observer.OnError(e);
|
||||
}
|
||||
}, () => {
|
||||
if (!stopped) {
|
||||
completed2 = true;
|
||||
if (completed1) {
|
||||
stopped = true;
|
||||
observer.OnCompleted();
|
||||
}
|
||||
}
|
||||
}));
|
||||
return createDisposable(() => {
|
||||
h1.Dispose();
|
||||
h2.Dispose();
|
||||
});
|
||||
}, source1.delegates.concat(source2.delegates));
|
||||
}
|
||||
export function pairwise(sourceEvent) {
|
||||
const source = sourceEvent;
|
||||
return new Event((observer) => {
|
||||
let last = null;
|
||||
return source.Subscribe(new Observer((next) => {
|
||||
if (last != null) {
|
||||
observer.OnNext([last, next]);
|
||||
}
|
||||
last = next;
|
||||
}, observer.OnError, observer.OnCompleted));
|
||||
}, source.delegates);
|
||||
}
|
||||
export function partition(predicate, sourceEvent) {
|
||||
return [filter(predicate, sourceEvent), filter((x) => !predicate(x), sourceEvent)];
|
||||
}
|
||||
export function scan(collector, state, sourceEvent) {
|
||||
const source = sourceEvent;
|
||||
return new Event((observer) => {
|
||||
return source.Subscribe(new Observer((t) => {
|
||||
protect(() => collector(state, t), (u) => { state = u; observer.OnNext(u); }, observer.OnError);
|
||||
}, observer.OnError, observer.OnCompleted));
|
||||
}, source.delegates);
|
||||
}
|
||||
export function split(splitter, sourceEvent) {
|
||||
return [
|
||||
choose((v) => splitter(v).valueIfChoice1, sourceEvent),
|
||||
choose((v) => splitter(v).valueIfChoice2, sourceEvent),
|
||||
];
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
const parseRadix = /^\s*([\+\-])?(0[xob])?([0-9a-fA-F]+)\s*$/;
|
||||
const invalidRadix2 = /[^01]/;
|
||||
const invalidRadix8 = /[^0-7]/;
|
||||
const invalidRadix10 = /[^0-9]/;
|
||||
export function isValid(s, radix) {
|
||||
const res = parseRadix.exec(s);
|
||||
if (res != null) {
|
||||
if (radix == null) {
|
||||
switch (res[2]) {
|
||||
case "0b":
|
||||
radix = 2;
|
||||
break;
|
||||
case "0o":
|
||||
radix = 8;
|
||||
break;
|
||||
case "0x":
|
||||
radix = 16;
|
||||
break;
|
||||
default:
|
||||
radix = 10;
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch (radix) {
|
||||
case 2:
|
||||
return invalidRadix2.test(res[3]) ? null : [res, 2];
|
||||
case 8:
|
||||
return invalidRadix8.test(res[3]) ? null : [res, 8];
|
||||
case 10:
|
||||
return invalidRadix10.test(res[3]) ? null : [res, 10];
|
||||
case 16:
|
||||
return [res, 16];
|
||||
default:
|
||||
throw new Error("Invalid Base.");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// TODO does this perfectly match the .NET behavior ?
|
||||
export function tryParse(s, radix, initial) {
|
||||
const a = isValid(s, radix);
|
||||
if (a !== null) {
|
||||
const [[, prefix, , digits], radix_] = a;
|
||||
const v = parseInt((prefix || "") + digits, radix_);
|
||||
if (!Number.isNaN(v)) {
|
||||
return [true, v];
|
||||
}
|
||||
}
|
||||
return [false, initial];
|
||||
}
|
||||
export function parse(s, radix) {
|
||||
const a = tryParse(s, radix, 0);
|
||||
if (a[0]) {
|
||||
return a[1];
|
||||
}
|
||||
else {
|
||||
throw new Error("Input string was not in a correct format.");
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
export function createFromValue(v) {
|
||||
return new Lazy(() => v);
|
||||
}
|
||||
export default class Lazy {
|
||||
constructor(factory) {
|
||||
this.factory = factory;
|
||||
this.isValueCreated = false;
|
||||
}
|
||||
get value() {
|
||||
if (!this.isValueCreated) {
|
||||
this.createdValue = this.factory();
|
||||
this.isValueCreated = true;
|
||||
}
|
||||
return this.createdValue;
|
||||
}
|
||||
}
|
||||
-119
@@ -1,119 +0,0 @@
|
||||
import List from "./ListClass";
|
||||
import { ofArray } from "./ListClass";
|
||||
import { groupBy as mapGroupBy } from "./Map";
|
||||
import { getValue } from "./Option";
|
||||
import { map as seqMap } from "./Seq";
|
||||
import { fold as seqFold } from "./Seq";
|
||||
import { foldBack as seqFoldBack } from "./Seq";
|
||||
import { toList as seqToList } from "./Seq";
|
||||
export default List;
|
||||
export { ofArray };
|
||||
export function append(xs, ys) {
|
||||
return seqFold((acc, x) => new List(x, acc), ys, reverse(xs));
|
||||
}
|
||||
export function choose(f, xs) {
|
||||
const r = seqFold((acc, x) => {
|
||||
const y = f(x);
|
||||
return y != null ? new List(getValue(y), acc) : acc;
|
||||
}, new List(), xs);
|
||||
return reverse(r);
|
||||
}
|
||||
export function collect(f, xs) {
|
||||
return seqFold((acc, x) => append(acc, f(x)), new List(), xs);
|
||||
}
|
||||
// TODO: should be xs: Iterable<List<T>>
|
||||
export function concat(xs) {
|
||||
return collect((x) => x, xs);
|
||||
}
|
||||
export function filter(f, xs) {
|
||||
return reverse(seqFold((acc, x) => f(x) ? new List(x, acc) : acc, new List(), xs));
|
||||
}
|
||||
export function where(f, xs) {
|
||||
return filter(f, xs);
|
||||
}
|
||||
export function initialize(n, f) {
|
||||
if (n < 0) {
|
||||
throw new Error("List length must be non-negative");
|
||||
}
|
||||
let xs = new List();
|
||||
for (let i = 1; i <= n; i++) {
|
||||
xs = new List(f(n - i), xs);
|
||||
}
|
||||
return xs;
|
||||
}
|
||||
export function map(f, xs) {
|
||||
return reverse(seqFold((acc, x) => new List(f(x), acc), new List(), xs));
|
||||
}
|
||||
export function mapIndexed(f, xs) {
|
||||
return reverse(seqFold((acc, x, i) => new List(f(i, x), acc), new List(), xs));
|
||||
}
|
||||
export function indexed(xs) {
|
||||
return mapIndexed((i, x) => [i, x], xs);
|
||||
}
|
||||
export function partition(f, xs) {
|
||||
return seqFold((acc, x) => {
|
||||
const lacc = acc[0];
|
||||
const racc = acc[1];
|
||||
return f(x) ? [new List(x, lacc), racc] : [lacc, new List(x, racc)];
|
||||
}, [new List(), new List()], reverse(xs));
|
||||
}
|
||||
export function replicate(n, x) {
|
||||
return initialize(n, () => x);
|
||||
}
|
||||
export function reverse(xs) {
|
||||
return seqFold((acc, x) => new List(x, acc), new List(), xs);
|
||||
}
|
||||
export function singleton(x) {
|
||||
return new List(x, new List());
|
||||
}
|
||||
export function slice(lower, upper, xs) {
|
||||
const noLower = (lower == null);
|
||||
const noUpper = (upper == null);
|
||||
return reverse(seqFold((acc, x, i) => (noLower || lower <= i) && (noUpper || i <= upper) ? new List(x, acc) : acc, new List(), xs));
|
||||
}
|
||||
/* ToDo: instance unzip() */
|
||||
export function unzip(xs) {
|
||||
return seqFoldBack((xy, acc) => [new List(xy[0], acc[0]), new List(xy[1], acc[1])], xs, [new List(), new List()]);
|
||||
}
|
||||
/* ToDo: instance unzip3() */
|
||||
export function unzip3(xs) {
|
||||
return seqFoldBack((xyz, acc) => [new List(xyz[0], acc[0]), new List(xyz[1], acc[1]), new List(xyz[2], acc[2]),
|
||||
], xs, [new List(), new List(), new List(),
|
||||
]);
|
||||
}
|
||||
export function groupBy(f, xs) {
|
||||
return seqToList(seqMap((k) => [k[0], seqToList(k[1])], mapGroupBy(f, xs)));
|
||||
}
|
||||
export function splitAt(index, xs) {
|
||||
if (index < 0) {
|
||||
throw new Error("The input must be non-negative.");
|
||||
}
|
||||
let i = 0;
|
||||
let last = xs;
|
||||
const first = new Array(index);
|
||||
while (i < index) {
|
||||
if (last.tail == null) {
|
||||
throw new Error("The input sequence has an insufficient number of elements.");
|
||||
}
|
||||
first[i] = last.head;
|
||||
last = last.tail;
|
||||
i++;
|
||||
}
|
||||
return [ofArray(first), last];
|
||||
}
|
||||
export function head(xs) {
|
||||
if (xs.head !== undefined) {
|
||||
return xs.head;
|
||||
}
|
||||
else {
|
||||
throw new Error("The input list was empty.");
|
||||
}
|
||||
}
|
||||
export function tail(xs) {
|
||||
if (xs.tail !== undefined) {
|
||||
return xs.tail;
|
||||
}
|
||||
else {
|
||||
throw new Error("The input list was empty.");
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
import FSymbol from "./Symbol";
|
||||
import { toString } from "./Util";
|
||||
import { equals } from "./Util";
|
||||
import { compare } from "./Util";
|
||||
// This module is split from List.ts to prevent cyclic dependencies
|
||||
export function ofArray(args, base) {
|
||||
let acc = base || new List();
|
||||
for (let i = args.length - 1; i >= 0; i--) {
|
||||
acc = new List(args[i], acc);
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
export default class List {
|
||||
constructor(head, tail) {
|
||||
this.head = head;
|
||||
this.tail = tail;
|
||||
}
|
||||
ToString() {
|
||||
return "[" + Array.from(this).map((x) => toString(x)).join("; ") + "]";
|
||||
}
|
||||
Equals(other) {
|
||||
// Optimization if they are referencially equal
|
||||
if (this === other) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
let cur1 = this;
|
||||
let cur2 = other;
|
||||
while (equals(cur1.head, cur2.head)) {
|
||||
cur1 = cur1.tail;
|
||||
cur2 = cur2.tail;
|
||||
if (cur1 == null) {
|
||||
return cur2 == null;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
CompareTo(other) {
|
||||
// Optimization if they are referencially equal
|
||||
if (this === other) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
let cur1 = this;
|
||||
let cur2 = other;
|
||||
let res = compare(cur1.head, cur2.head);
|
||||
while (res === 0) {
|
||||
cur1 = cur1.tail;
|
||||
cur2 = cur2.tail;
|
||||
if (cur1 == null) {
|
||||
return cur2 == null ? 0 : -1;
|
||||
}
|
||||
res = compare(cur1.head, cur2.head);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
get length() {
|
||||
let cur = this;
|
||||
let acc = 0;
|
||||
while (cur.tail != null) {
|
||||
cur = cur.tail;
|
||||
acc++;
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
let cur = this;
|
||||
return {
|
||||
next: () => {
|
||||
const tmp = cur;
|
||||
cur = cur.tail;
|
||||
return { done: tmp.tail == null, value: tmp.head };
|
||||
},
|
||||
};
|
||||
}
|
||||
// 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);
|
||||
// }
|
||||
[FSymbol.reflection]() {
|
||||
return {
|
||||
type: "Microsoft.FSharp.Collections.FSharpList",
|
||||
interfaces: ["System.IEquatable", "System.IComparable"],
|
||||
};
|
||||
}
|
||||
}
|
||||
-969
@@ -1,969 +0,0 @@
|
||||
// Source: https://github.com/dcodeIO/long.js/blob/master/LICENSE
|
||||
// tslint:disable:curly
|
||||
// tslint:disable:member-access
|
||||
// tslint:disable:member-ordering
|
||||
import { isValid } from "./Int32";
|
||||
import _Symbol from "./Symbol";
|
||||
// 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.
|
||||
*/
|
||||
export default class Long {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
constructor(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;
|
||||
this.high = high | 0;
|
||||
this.unsigned = !!unsigned;
|
||||
}
|
||||
/**
|
||||
* Converts the Long to a 32 bit integer, assuming it is a 32 bit integer.
|
||||
* @returns {number}
|
||||
*/
|
||||
toInt() {
|
||||
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}
|
||||
*/
|
||||
toNumber() {
|
||||
if (this.unsigned)
|
||||
return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0);
|
||||
return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
toString(radix = 10) {
|
||||
radix = radix || 10;
|
||||
if (radix < 2 || 36 < radix)
|
||||
throw RangeError("radix");
|
||||
if (this.isZero())
|
||||
return "0";
|
||||
if (this.isNegative()) {
|
||||
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.
|
||||
const radixLong = fromNumber(radix);
|
||||
const div = this.div(radixLong);
|
||||
const rem1 = div.mul(radixLong).sub(this);
|
||||
return div.toString(radix) + rem1.toInt().toString(radix);
|
||||
}
|
||||
else
|
||||
return "-" + this.neg().toString(radix);
|
||||
}
|
||||
// Do several (6) digits each time through the loop, so as to
|
||||
// minimize the calls to the very expensive emulated div.
|
||||
const radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned);
|
||||
let rem = this;
|
||||
let result = "";
|
||||
while (true) {
|
||||
const remDiv = rem.div(radixToPower);
|
||||
const intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0;
|
||||
let digits = intval.toString(radix);
|
||||
rem = remDiv;
|
||||
if (rem.isZero())
|
||||
return digits + result;
|
||||
else {
|
||||
while (digits.length < 6)
|
||||
digits = "0" + digits;
|
||||
result = "" + digits + result;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gets the high 32 bits as a signed integer.
|
||||
* @returns {number} Signed high bits
|
||||
*/
|
||||
getHighBits() {
|
||||
return this.high;
|
||||
}
|
||||
/**
|
||||
* Gets the high 32 bits as an unsigned integer.
|
||||
* @returns {number} Unsigned high bits
|
||||
*/
|
||||
getHighBitsUnsigned() {
|
||||
return this.high >>> 0;
|
||||
}
|
||||
/**
|
||||
* Gets the low 32 bits as a signed integer.
|
||||
* @returns {number} Signed low bits
|
||||
*/
|
||||
getLowBits() {
|
||||
return this.low;
|
||||
}
|
||||
/**
|
||||
* Gets the low 32 bits as an unsigned integer.
|
||||
* @returns {number} Unsigned low bits
|
||||
*/
|
||||
getLowBitsUnsigned() {
|
||||
return this.low >>> 0;
|
||||
}
|
||||
/**
|
||||
* Gets the number of bits needed to represent the absolute value of this
|
||||
* @returns {number}
|
||||
*/
|
||||
getNumBitsAbs() {
|
||||
if (this.isNegative())
|
||||
return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
|
||||
const val = this.high !== 0 ? this.high : this.low;
|
||||
let bit;
|
||||
for (bit = 31; bit > 0; bit--)
|
||||
if ((val & (1 << bit)) !== 0)
|
||||
break;
|
||||
return this.high !== 0 ? bit + 33 : bit + 1;
|
||||
}
|
||||
/**
|
||||
* Tests if this Long's value equals zero.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isZero() {
|
||||
return this.high === 0 && this.low === 0;
|
||||
}
|
||||
/**
|
||||
* Tests if this Long's value is negative.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isNegative() {
|
||||
return !this.unsigned && this.high < 0;
|
||||
}
|
||||
/**
|
||||
* Tests if this Long's value is positive.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isPositive() {
|
||||
return this.unsigned || this.high >= 0;
|
||||
}
|
||||
/**
|
||||
* Tests if this Long's value is odd.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isOdd() {
|
||||
return (this.low & 1) === 1;
|
||||
}
|
||||
/**
|
||||
* Tests if this Long's value is even.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isEven() {
|
||||
return (this.low & 1) === 0;
|
||||
}
|
||||
/**
|
||||
* Tests if this Long's value equals the specified's.
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
*/
|
||||
equals(other) {
|
||||
if (!isLong(other))
|
||||
other = fromValue(other);
|
||||
if (this.unsigned !== other.unsigned && (this.high >>> 31) === 1 && (other.high >>> 31) === 1)
|
||||
return false;
|
||||
return this.high === other.high && this.low === other.low;
|
||||
}
|
||||
/**
|
||||
* Tests if this Long's value differs from the specified's.
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
*/
|
||||
notEquals(other) {
|
||||
return !this.eq(/* validates */ other);
|
||||
}
|
||||
/**
|
||||
* Tests if this Long's value is less than the specified's.
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
*/
|
||||
lessThan(other) {
|
||||
return this.comp(/* validates */ 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}
|
||||
*/
|
||||
lessThanOrEqual(other) {
|
||||
return this.comp(/* validates */ other) <= 0;
|
||||
}
|
||||
/**
|
||||
* Tests if this Long's value is greater than the specified's.
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
*/
|
||||
greaterThan(other) {
|
||||
return this.comp(/* validates */ 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}
|
||||
*/
|
||||
greaterThanOrEqual(other) {
|
||||
return this.comp(/* validates */ 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
|
||||
*/
|
||||
compare(other) {
|
||||
if (!isLong(other))
|
||||
other = fromValue(other);
|
||||
if (this.eq(other))
|
||||
return 0;
|
||||
const thisNeg = this.isNegative();
|
||||
const otherNeg = other.isNegative();
|
||||
if (thisNeg && !otherNeg)
|
||||
return -1;
|
||||
if (!thisNeg && otherNeg)
|
||||
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
|
||||
*/
|
||||
negate() {
|
||||
if (!this.unsigned && this.eq(MIN_VALUE))
|
||||
return MIN_VALUE;
|
||||
return this.not().add(ONE);
|
||||
}
|
||||
/**
|
||||
* Returns this Long's absolute value.
|
||||
* @returns {!Long} Absolute Long
|
||||
*/
|
||||
absolute() {
|
||||
if (!this.unsigned && this.isNegative())
|
||||
return this.negate();
|
||||
else
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Returns the sum of this and the specified
|
||||
* @param {!Long|number|string} addend Addend
|
||||
* @returns {!Long} Sum
|
||||
*/
|
||||
add(addend) {
|
||||
if (!isLong(addend))
|
||||
addend = fromValue(addend);
|
||||
// Divide each number into 4 chunks of 16 bits, and then sum the chunks.
|
||||
const a48 = this.high >>> 16;
|
||||
const a32 = this.high & 0xFFFF;
|
||||
const a16 = this.low >>> 16;
|
||||
const a00 = this.low & 0xFFFF;
|
||||
const b48 = addend.high >>> 16;
|
||||
const b32 = addend.high & 0xFFFF;
|
||||
const b16 = addend.low >>> 16;
|
||||
const b00 = addend.low & 0xFFFF;
|
||||
let c48 = 0;
|
||||
let c32 = 0;
|
||||
let c16 = 0;
|
||||
let c00 = 0;
|
||||
c00 += a00 + b00;
|
||||
c16 += c00 >>> 16;
|
||||
c00 &= 0xFFFF;
|
||||
c16 += a16 + b16;
|
||||
c32 += c16 >>> 16;
|
||||
c16 &= 0xFFFF;
|
||||
c32 += a32 + b32;
|
||||
c48 += c32 >>> 16;
|
||||
c32 &= 0xFFFF;
|
||||
c48 += a48 + b48;
|
||||
c48 &= 0xFFFF;
|
||||
return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
|
||||
}
|
||||
/**
|
||||
* Returns the difference of this and the specified
|
||||
* @param {!Long|number|string} subtrahend Subtrahend
|
||||
* @returns {!Long} Difference
|
||||
*/
|
||||
subtract(subtrahend) {
|
||||
if (!isLong(subtrahend))
|
||||
subtrahend = fromValue(subtrahend);
|
||||
return this.add(subtrahend.neg());
|
||||
}
|
||||
/**
|
||||
* Returns the product of this and the specified
|
||||
* @param {!Long|number|string} multiplier Multiplier
|
||||
* @returns {!Long} Product
|
||||
*/
|
||||
multiply(multiplier) {
|
||||
if (this.isZero())
|
||||
return ZERO;
|
||||
if (!isLong(multiplier))
|
||||
multiplier = fromValue(multiplier);
|
||||
if (multiplier.isZero())
|
||||
return ZERO;
|
||||
if (this.eq(MIN_VALUE))
|
||||
return multiplier.isOdd() ? MIN_VALUE : ZERO;
|
||||
if (multiplier.eq(MIN_VALUE))
|
||||
return this.isOdd() ? MIN_VALUE : ZERO;
|
||||
if (this.isNegative()) {
|
||||
if (multiplier.isNegative())
|
||||
return this.neg().mul(multiplier.neg());
|
||||
else
|
||||
return this.neg().mul(multiplier).neg();
|
||||
}
|
||||
else if (multiplier.isNegative())
|
||||
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.
|
||||
const a48 = this.high >>> 16;
|
||||
const a32 = this.high & 0xFFFF;
|
||||
const a16 = this.low >>> 16;
|
||||
const a00 = this.low & 0xFFFF;
|
||||
const b48 = multiplier.high >>> 16;
|
||||
const b32 = multiplier.high & 0xFFFF;
|
||||
const b16 = multiplier.low >>> 16;
|
||||
const b00 = multiplier.low & 0xFFFF;
|
||||
let c48 = 0;
|
||||
let c32 = 0;
|
||||
let c16 = 0;
|
||||
let c00 = 0;
|
||||
c00 += a00 * b00;
|
||||
c16 += c00 >>> 16;
|
||||
c00 &= 0xFFFF;
|
||||
c16 += a16 * b00;
|
||||
c32 += c16 >>> 16;
|
||||
c16 &= 0xFFFF;
|
||||
c16 += a00 * b16;
|
||||
c32 += c16 >>> 16;
|
||||
c16 &= 0xFFFF;
|
||||
c32 += a32 * b00;
|
||||
c48 += c32 >>> 16;
|
||||
c32 &= 0xFFFF;
|
||||
c32 += a16 * b16;
|
||||
c48 += c32 >>> 16;
|
||||
c32 &= 0xFFFF;
|
||||
c32 += a00 * b32;
|
||||
c48 += c32 >>> 16;
|
||||
c32 &= 0xFFFF;
|
||||
c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
|
||||
c48 &= 0xFFFF;
|
||||
return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
divide(divisor) {
|
||||
if (!isLong(divisor))
|
||||
divisor = fromValue(divisor);
|
||||
if (divisor.isZero())
|
||||
throw Error("division by zero");
|
||||
if (this.isZero())
|
||||
return this.unsigned ? UZERO : ZERO;
|
||||
let rem = ZERO;
|
||||
let res = ZERO;
|
||||
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
|
||||
else if (divisor.eq(MIN_VALUE))
|
||||
return ONE;
|
||||
else {
|
||||
// At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.
|
||||
const halfThis = this.shr(1);
|
||||
const approx = halfThis.div(divisor).shl(1);
|
||||
if (approx.eq(ZERO)) {
|
||||
return divisor.isNegative() ? ONE : NEG_ONE;
|
||||
}
|
||||
else {
|
||||
rem = this.sub(divisor.mul(approx));
|
||||
res = approx.add(rem.div(divisor));
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (divisor.eq(MIN_VALUE))
|
||||
return this.unsigned ? UZERO : ZERO;
|
||||
if (this.isNegative()) {
|
||||
if (divisor.isNegative())
|
||||
return this.neg().div(divisor.neg());
|
||||
return this.neg().div(divisor).neg();
|
||||
}
|
||||
else if (divisor.isNegative())
|
||||
return this.div(divisor.neg()).neg();
|
||||
res = ZERO;
|
||||
}
|
||||
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)
|
||||
divisor = divisor.toUnsigned();
|
||||
if (divisor.gt(this))
|
||||
return UZERO;
|
||||
if (divisor.gt(this.shru(1)))
|
||||
return UONE;
|
||||
res = UZERO;
|
||||
}
|
||||
// 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.
|
||||
let 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.
|
||||
// tslint:disable-next-line:prefer-const
|
||||
// tslint:disable-next-line:semicolon
|
||||
const log2 = Math.ceil(Math.log(approx) / Math.LN2);
|
||||
const 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.
|
||||
let approxRes = fromNumber(approx);
|
||||
let approxRem = approxRes.mul(divisor);
|
||||
while (approxRem.isNegative() || approxRem.gt(rem)) {
|
||||
approx -= delta;
|
||||
approxRes = fromNumber(approx, this.unsigned);
|
||||
approxRem = approxRes.mul(divisor);
|
||||
}
|
||||
// We know the answer can't be zero... and actually, zero would cause
|
||||
// infinite recursion since we would make no progress.
|
||||
if (approxRes.isZero())
|
||||
approxRes = ONE;
|
||||
res = res.add(approxRes);
|
||||
rem = rem.sub(approxRem);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
/**
|
||||
* Returns this Long modulo the specified.
|
||||
* @param {!Long|number|string} divisor Divisor
|
||||
* @returns {!Long} Remainder
|
||||
*/
|
||||
modulo(divisor) {
|
||||
if (!isLong(divisor))
|
||||
divisor = fromValue(divisor);
|
||||
return this.sub(this.div(divisor).mul(divisor));
|
||||
}
|
||||
/**
|
||||
* Returns the bitwise NOT of this
|
||||
* @returns {!Long}
|
||||
*/
|
||||
not() {
|
||||
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}
|
||||
*/
|
||||
and(other) {
|
||||
if (!isLong(other))
|
||||
other = fromValue(other);
|
||||
return fromBits(this.low & other.low, this.high & other.high, this.unsigned);
|
||||
}
|
||||
/**
|
||||
* Returns the bitwise OR of this Long and the specified.
|
||||
* @param {!Long|number|string} other Other Long
|
||||
* @returns {!Long}
|
||||
*/
|
||||
or(other) {
|
||||
if (!isLong(other))
|
||||
other = fromValue(other);
|
||||
return fromBits(this.low | other.low, this.high | other.high, this.unsigned);
|
||||
}
|
||||
/**
|
||||
* Returns the bitwise XOR of this Long and the given one.
|
||||
* @param {!Long|number|string} other Other Long
|
||||
* @returns {!Long}
|
||||
*/
|
||||
xor(other) {
|
||||
if (!isLong(other))
|
||||
other = fromValue(other);
|
||||
return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
|
||||
}
|
||||
/**
|
||||
* Returns this Long with bits shifted to the left by the given amount.
|
||||
* @param {number|!Long} numBits Number of bits
|
||||
* @returns {!Long} Shifted Long
|
||||
*/
|
||||
shiftLeft(numBits) {
|
||||
if (isLong(numBits))
|
||||
numBits = numBits.toInt();
|
||||
numBits = numBits & 63;
|
||||
if (numBits === 0)
|
||||
return this;
|
||||
else if (numBits < 32)
|
||||
return fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned);
|
||||
else
|
||||
return fromBits(0, this.low << (numBits - 32), this.unsigned);
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
shiftRight(numBits) {
|
||||
if (isLong(numBits))
|
||||
numBits = numBits.toInt();
|
||||
numBits = numBits & 63;
|
||||
if (numBits === 0)
|
||||
return this;
|
||||
else if (numBits < 32)
|
||||
return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned);
|
||||
else
|
||||
return fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned);
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
shiftRightUnsigned(numBits) {
|
||||
if (isLong(numBits))
|
||||
numBits = numBits.toInt();
|
||||
numBits = numBits & 63;
|
||||
if (numBits === 0)
|
||||
return this;
|
||||
else {
|
||||
const high = this.high;
|
||||
if (numBits < 32) {
|
||||
const low = this.low;
|
||||
return fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned);
|
||||
}
|
||||
else if (numBits === 32)
|
||||
return fromBits(high, 0, this.unsigned);
|
||||
else
|
||||
return fromBits(high >>> (numBits - 32), 0, this.unsigned);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Converts this Long to signed.
|
||||
* @returns {!Long} Signed long
|
||||
*/
|
||||
toSigned() {
|
||||
if (!this.unsigned)
|
||||
return this;
|
||||
return fromBits(this.low, this.high, false);
|
||||
}
|
||||
/**
|
||||
* Converts this Long to unsigned.
|
||||
* @returns {!Long} Unsigned long
|
||||
*/
|
||||
toUnsigned() {
|
||||
if (this.unsigned)
|
||||
return this;
|
||||
return fromBits(this.low, this.high, true);
|
||||
}
|
||||
/**
|
||||
* Converts this Long to its byte representation.
|
||||
* @param {boolean=} le Whether little or big endian, defaults to big endian
|
||||
* @returns {!Array.<number>} Byte representation
|
||||
*/
|
||||
toBytes(le) {
|
||||
return le ? this.toBytesLE() : this.toBytesBE();
|
||||
}
|
||||
/**
|
||||
* Converts this Long to its little endian byte representation.
|
||||
* @returns {!Array.<number>} Little endian byte representation
|
||||
*/
|
||||
toBytesLE() {
|
||||
const hi = this.high;
|
||||
const lo = this.low;
|
||||
return [
|
||||
lo & 0xff,
|
||||
(lo >>> 8) & 0xff,
|
||||
(lo >>> 16) & 0xff,
|
||||
(lo >>> 24) & 0xff,
|
||||
hi & 0xff,
|
||||
(hi >>> 8) & 0xff,
|
||||
(hi >>> 16) & 0xff,
|
||||
(hi >>> 24) & 0xff,
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Converts this Long to its big endian byte representation.
|
||||
* @returns {!Array.<number>} Big endian byte representation
|
||||
*/
|
||||
toBytesBE() {
|
||||
const hi = this.high;
|
||||
const lo = this.low;
|
||||
return [
|
||||
(hi >>> 24) & 0xff,
|
||||
(hi >>> 16) & 0xff,
|
||||
(hi >>> 8) & 0xff,
|
||||
hi & 0xff,
|
||||
(lo >>> 24) & 0xff,
|
||||
(lo >>> 16) & 0xff,
|
||||
(lo >>> 8) & 0xff,
|
||||
lo & 0xff,
|
||||
];
|
||||
}
|
||||
toJSON() {
|
||||
return (!this.unsigned && !this.lessThan(0) ? "+" : "") + this.toString();
|
||||
}
|
||||
static ofJSON(str) {
|
||||
return fromString(str, !/^[+-]/.test(str));
|
||||
}
|
||||
[_Symbol.reflection]() {
|
||||
return {
|
||||
type: this.unsigned ? "System.UInt64" : "System.Int64",
|
||||
interfaces: ["FSharpRecord", "System.IComparable"],
|
||||
properties: {
|
||||
low: "number",
|
||||
high: "number",
|
||||
unsigned: "boolean",
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
// A cache of the Long representations of small integer values.
|
||||
const INT_CACHE = {};
|
||||
// A cache of the Long representations of small unsigned integer values.
|
||||
const 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 = false) {
|
||||
let obj;
|
||||
let cachedObj;
|
||||
let cache = false;
|
||||
if (unsigned) {
|
||||
value >>>= 0;
|
||||
if (0 <= value && value < 256) {
|
||||
cache = true;
|
||||
cachedObj = UINT_CACHE[value];
|
||||
if (cachedObj)
|
||||
return cachedObj;
|
||||
}
|
||||
obj = fromBits(value, (value | 0) < 0 ? -1 : 0, true);
|
||||
if (cache)
|
||||
UINT_CACHE[value] = obj;
|
||||
return obj;
|
||||
}
|
||||
else {
|
||||
value |= 0;
|
||||
if (-128 <= value && value < 128) {
|
||||
cache = true;
|
||||
cachedObj = INT_CACHE[value];
|
||||
if (cachedObj)
|
||||
return cachedObj;
|
||||
}
|
||||
obj = fromBits(value, value < 0 ? -1 : 0, false);
|
||||
if (cache)
|
||||
INT_CACHE[value] = obj;
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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 = false) {
|
||||
if (isNaN(value) || !isFinite(value)) {
|
||||
// TODO FormatException ?
|
||||
throw new Error("Input string was not in a correct format.");
|
||||
}
|
||||
if (unsigned) {
|
||||
if (value < 0)
|
||||
return UZERO;
|
||||
if (value >= TWO_PWR_64_DBL)
|
||||
return MAX_UNSIGNED_VALUE;
|
||||
}
|
||||
else {
|
||||
if (value <= -TWO_PWR_63_DBL)
|
||||
return MIN_VALUE;
|
||||
if (value + 1 >= TWO_PWR_63_DBL)
|
||||
return MAX_VALUE;
|
||||
}
|
||||
if (value < 0)
|
||||
return fromNumber(-value, unsigned).neg();
|
||||
return fromBits((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
|
||||
}
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
const 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
|
||||
*/
|
||||
export function fromString(str, unsigned = false, radix = 10) {
|
||||
if (isValid(str, radix) === null) {
|
||||
// TODO FormatException ?
|
||||
throw new Error("Input string was not in a correct format.");
|
||||
}
|
||||
if (str.length === 0)
|
||||
throw Error("empty string");
|
||||
if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")
|
||||
return ZERO;
|
||||
if (typeof unsigned === "number") {
|
||||
// For goog.math.long compatibility
|
||||
radix = unsigned,
|
||||
unsigned = false;
|
||||
}
|
||||
else {
|
||||
unsigned = !!unsigned;
|
||||
}
|
||||
radix = radix || 10;
|
||||
if (radix < 2 || 36 < radix)
|
||||
throw RangeError("radix");
|
||||
const p = str.indexOf("-");
|
||||
if (p > 0)
|
||||
throw Error("interior hyphen");
|
||||
else if (p === 0) {
|
||||
return fromString(str.substring(1), unsigned, radix).neg();
|
||||
}
|
||||
// Do several (8) digits each time through the loop, so as to
|
||||
// minimize the calls to the very expensive emulated div.
|
||||
const radixToPower = fromNumber(pow_dbl(radix, 8));
|
||||
let result = ZERO;
|
||||
for (let i = 0; i < str.length; i += 8) {
|
||||
const size = Math.min(8, str.length - i);
|
||||
const value = parseInt(str.substring(i, i + size), radix);
|
||||
if (size < 8) {
|
||||
const power = fromNumber(pow_dbl(radix, size));
|
||||
result = result.mul(power).add(fromNumber(value));
|
||||
}
|
||||
else {
|
||||
result = result.mul(radixToPower);
|
||||
result = result.add(fromNumber(value));
|
||||
}
|
||||
}
|
||||
result.unsigned = unsigned;
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* 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)
|
||||
return val;
|
||||
if (typeof val === "number")
|
||||
return fromNumber(val);
|
||||
if (typeof val === "string")
|
||||
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.
|
||||
const TWO_PWR_16_DBL = 1 << 16;
|
||||
const TWO_PWR_24_DBL = 1 << 24;
|
||||
const TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
|
||||
const TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
|
||||
const TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
|
||||
const TWO_PWR_24 = fromInt(TWO_PWR_24_DBL);
|
||||
/**
|
||||
* Signed zero.
|
||||
* @type {!Long}
|
||||
*/
|
||||
export const ZERO = fromInt(0);
|
||||
/**
|
||||
* Unsigned zero.
|
||||
* @type {!Long}
|
||||
*/
|
||||
export const UZERO = fromInt(0, true);
|
||||
/**
|
||||
* Signed one.
|
||||
* @type {!Long}
|
||||
*/
|
||||
export const ONE = fromInt(1);
|
||||
/**
|
||||
* Unsigned one.
|
||||
* @type {!Long}
|
||||
*/
|
||||
export const UONE = fromInt(1, true);
|
||||
/**
|
||||
* Signed negative one.
|
||||
* @type {!Long}
|
||||
*/
|
||||
export const NEG_ONE = fromInt(-1);
|
||||
/**
|
||||
* Maximum signed value.
|
||||
* @type {!Long}
|
||||
*/
|
||||
export const MAX_VALUE = fromBits(0xFFFFFFFF | 0, 0x7FFFFFFF | 0, false);
|
||||
/**
|
||||
* Maximum unsigned value.
|
||||
* @type {!Long}
|
||||
*/
|
||||
export const MAX_UNSIGNED_VALUE = fromBits(0xFFFFFFFF | 0, 0xFFFFFFFF | 0, true);
|
||||
/**
|
||||
* Minimum signed value.
|
||||
* @type {!Long}
|
||||
*/
|
||||
export const MIN_VALUE = fromBits(0, 0x80000000 | 0, false);
|
||||
export function unixEpochMillisecondsToTicks(ms, offset) {
|
||||
return fromNumber(ms).add(62135596800000).add(offset).mul(10000);
|
||||
}
|
||||
export function ticksToUnixEpochMilliseconds(ticks) {
|
||||
return ticks.div(10000).sub(62135596800000).toNumber();
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
import { defaultCancellationToken } from "./Async";
|
||||
import { fromContinuations } from "./Async";
|
||||
import { startImmediate } from "./Async";
|
||||
class QueueCell {
|
||||
constructor(message) {
|
||||
this.value = message;
|
||||
}
|
||||
}
|
||||
class MailboxQueue {
|
||||
add(message) {
|
||||
const itCell = new QueueCell(message);
|
||||
if (this.firstAndLast) {
|
||||
this.firstAndLast[1].next = itCell;
|
||||
this.firstAndLast = [this.firstAndLast[0], itCell];
|
||||
}
|
||||
else {
|
||||
this.firstAndLast = [itCell, itCell];
|
||||
}
|
||||
}
|
||||
tryGet() {
|
||||
if (this.firstAndLast) {
|
||||
const value = this.firstAndLast[0].value;
|
||||
if (this.firstAndLast[0].next) {
|
||||
this.firstAndLast = [this.firstAndLast[0].next, this.firstAndLast[1]];
|
||||
}
|
||||
else {
|
||||
delete this.firstAndLast;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
}
|
||||
export default class MailboxProcessor {
|
||||
constructor(body, cancellationToken) {
|
||||
this.body = body;
|
||||
this.cancellationToken = cancellationToken || defaultCancellationToken;
|
||||
this.messages = new MailboxQueue();
|
||||
}
|
||||
__processEvents() {
|
||||
if (this.continuation) {
|
||||
const value = this.messages.tryGet();
|
||||
if (value) {
|
||||
const cont = this.continuation;
|
||||
delete this.continuation;
|
||||
cont(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
start() {
|
||||
startImmediate(this.body(this), this.cancellationToken);
|
||||
}
|
||||
receive() {
|
||||
return fromContinuations((conts) => {
|
||||
if (this.continuation) {
|
||||
throw new Error("Receive can only be called once!");
|
||||
}
|
||||
this.continuation = conts[0];
|
||||
this.__processEvents();
|
||||
});
|
||||
}
|
||||
post(message) {
|
||||
this.messages.add(message);
|
||||
this.__processEvents();
|
||||
}
|
||||
postAndAsyncReply(buildMessage) {
|
||||
let result;
|
||||
let continuation;
|
||||
function checkCompletion() {
|
||||
if (result && continuation) {
|
||||
continuation(result);
|
||||
}
|
||||
}
|
||||
const reply = {
|
||||
reply: (res) => {
|
||||
result = res;
|
||||
checkCompletion();
|
||||
},
|
||||
};
|
||||
this.messages.add(buildMessage(reply));
|
||||
this.__processEvents();
|
||||
return fromContinuations((conts) => {
|
||||
continuation = conts[0];
|
||||
checkCompletion();
|
||||
});
|
||||
}
|
||||
}
|
||||
export function start(body, cancellationToken) {
|
||||
const mbox = new MailboxProcessor(body, cancellationToken);
|
||||
mbox.start();
|
||||
return mbox;
|
||||
}
|
||||
-610
@@ -1,610 +0,0 @@
|
||||
import Comparer from "./Comparer";
|
||||
import List from "./ListClass";
|
||||
import { ofArray as listOfArray } from "./ListClass";
|
||||
import { getValue, makeSome } from "./Option";
|
||||
import { map as seqMap } from "./Seq";
|
||||
import { fold as seqFold } from "./Seq";
|
||||
import { pick as seqPick } from "./Seq";
|
||||
import { tryPick as seqTryPick } from "./Seq";
|
||||
import { compareWith as seqCompareWith } from "./Seq";
|
||||
import FSymbol from "./Symbol";
|
||||
import { toString } from "./Util";
|
||||
import { equals } from "./Util";
|
||||
import { compare } from "./Util";
|
||||
// ----------------------------------------------
|
||||
// These functions belong to Seq.ts but are
|
||||
// implemented here to prevent cyclic dependencies
|
||||
export function groupBy(f, xs) {
|
||||
const keys = [];
|
||||
const iter = xs[Symbol.iterator]();
|
||||
let acc = create();
|
||||
let cur = iter.next();
|
||||
while (!cur.done) {
|
||||
const k = f(cur.value);
|
||||
const vs = tryFind(k, acc);
|
||||
if (vs == null) {
|
||||
keys.push(k);
|
||||
acc = add(k, [cur.value], acc);
|
||||
}
|
||||
else {
|
||||
getValue(vs).push(cur.value);
|
||||
}
|
||||
cur = iter.next();
|
||||
}
|
||||
return keys.map((k) => [k, acc.get(k)]);
|
||||
}
|
||||
export function countBy(f, xs) {
|
||||
return groupBy(f, xs).map((kv) => [kv[0], kv[1].length]);
|
||||
}
|
||||
export class MapTree {
|
||||
constructor(tag, data) {
|
||||
this.tag = tag | 0;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
function tree_sizeAux(acc, m) {
|
||||
sizeAux: while (true) {
|
||||
if (m.tag === 1) {
|
||||
return acc + 1 | 0;
|
||||
}
|
||||
else if (m.tag === 2) {
|
||||
acc = tree_sizeAux(acc + 1, m.data[2]);
|
||||
m = m.data[3];
|
||||
continue sizeAux;
|
||||
}
|
||||
else {
|
||||
return acc | 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
function tree_size(x) {
|
||||
return tree_sizeAux(0, x);
|
||||
}
|
||||
function tree_empty() {
|
||||
return new MapTree(0);
|
||||
}
|
||||
function tree_height(_arg1) {
|
||||
return _arg1.tag === 1 ? 1 : _arg1.tag === 2 ? _arg1.data[4] : 0;
|
||||
}
|
||||
function tree_isEmpty(m) {
|
||||
return m.tag === 0 ? true : false;
|
||||
}
|
||||
function tree_mk(l, k, v, r) {
|
||||
const matchValue = l.tag === 0 ? r.tag === 0 ? 0 : 1 : 1;
|
||||
switch (matchValue) {
|
||||
case 0:
|
||||
return new MapTree(1, [k, v]);
|
||||
case 1:
|
||||
const hl = tree_height(l) | 0;
|
||||
const hr = tree_height(r) | 0;
|
||||
const m = (hl < hr ? hr : hl) | 0;
|
||||
return new MapTree(2, [k, v, l, r, m + 1]);
|
||||
}
|
||||
throw new Error("internal error: Map.tree_mk");
|
||||
}
|
||||
function tree_rebalance(t1, k, v, t2) {
|
||||
const t1h = tree_height(t1);
|
||||
const t2h = tree_height(t2);
|
||||
if (t2h > t1h + 2) {
|
||||
if (t2.tag === 2) {
|
||||
if (tree_height(t2.data[2]) > t1h + 1) {
|
||||
if (t2.data[2].tag === 2) {
|
||||
return tree_mk(tree_mk(t1, k, v, t2.data[2].data[2]), t2.data[2].data[0], t2.data[2].data[1], tree_mk(t2.data[2].data[3], t2.data[0], t2.data[1], t2.data[3]));
|
||||
}
|
||||
else {
|
||||
throw new Error("rebalance");
|
||||
}
|
||||
}
|
||||
else {
|
||||
return tree_mk(tree_mk(t1, k, v, t2.data[2]), t2.data[0], t2.data[1], t2.data[3]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("rebalance");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (t1h > t2h + 2) {
|
||||
if (t1.tag === 2) {
|
||||
if (tree_height(t1.data[3]) > t2h + 1) {
|
||||
if (t1.data[3].tag === 2) {
|
||||
return tree_mk(tree_mk(t1.data[2], t1.data[0], t1.data[1], t1.data[3].data[2]), t1.data[3].data[0], t1.data[3].data[1], tree_mk(t1.data[3].data[3], k, v, t2));
|
||||
}
|
||||
else {
|
||||
throw new Error("rebalance");
|
||||
}
|
||||
}
|
||||
else {
|
||||
return tree_mk(t1.data[2], t1.data[0], t1.data[1], tree_mk(t1.data[3], k, v, t2));
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("rebalance");
|
||||
}
|
||||
}
|
||||
else {
|
||||
return tree_mk(t1, k, v, t2);
|
||||
}
|
||||
}
|
||||
}
|
||||
function tree_add(comparer, k, v, m) {
|
||||
if (m.tag === 1) {
|
||||
const c = comparer.Compare(k, m.data[0]);
|
||||
if (c < 0) {
|
||||
return new MapTree(2, [k, v, new MapTree(0), m, 2]);
|
||||
}
|
||||
else if (c === 0) {
|
||||
return new MapTree(1, [k, v]);
|
||||
}
|
||||
return new MapTree(2, [k, v, m, new MapTree(0), 2]);
|
||||
}
|
||||
else if (m.tag === 2) {
|
||||
const c = comparer.Compare(k, m.data[0]);
|
||||
if (c < 0) {
|
||||
return tree_rebalance(tree_add(comparer, k, v, m.data[2]), m.data[0], m.data[1], m.data[3]);
|
||||
}
|
||||
else if (c === 0) {
|
||||
return new MapTree(2, [k, v, m.data[2], m.data[3], m.data[4]]);
|
||||
}
|
||||
return tree_rebalance(m.data[2], m.data[0], m.data[1], tree_add(comparer, k, v, m.data[3]));
|
||||
}
|
||||
return new MapTree(1, [k, v]);
|
||||
}
|
||||
function tree_find(comparer, k, m) {
|
||||
const res = tree_tryFind(comparer, k, m);
|
||||
if (res == null) {
|
||||
throw new Error("key not found: " + k);
|
||||
}
|
||||
return getValue(res);
|
||||
}
|
||||
function tree_tryFind(comparer, k, m) {
|
||||
tryFind: while (true) {
|
||||
if (m.tag === 1) {
|
||||
const c = comparer.Compare(k, m.data[0]) | 0;
|
||||
if (c === 0) {
|
||||
return makeSome(m.data[1]);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (m.tag === 2) {
|
||||
const c_1 = comparer.Compare(k, m.data[0]) | 0;
|
||||
if (c_1 < 0) {
|
||||
comparer = comparer;
|
||||
k = k;
|
||||
m = m.data[2];
|
||||
continue tryFind;
|
||||
}
|
||||
else if (c_1 === 0) {
|
||||
return makeSome(m.data[1]);
|
||||
}
|
||||
else {
|
||||
comparer = comparer;
|
||||
k = k;
|
||||
m = m.data[3];
|
||||
continue tryFind;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
function tree_partition1(comparer, f, k, v, acc1, acc2) {
|
||||
return f(k, v) ? [tree_add(comparer, k, v, acc1), acc2] : [acc1, tree_add(comparer, k, v, acc2)];
|
||||
}
|
||||
function tree_partitionAux(comparer, f, s, acc_0, acc_1) {
|
||||
const acc = [acc_0, acc_1];
|
||||
if (s.tag === 1) {
|
||||
return tree_partition1(comparer, f, s.data[0], s.data[1], acc[0], acc[1]);
|
||||
}
|
||||
else if (s.tag === 2) {
|
||||
const acc_2 = tree_partitionAux(comparer, f, s.data[3], acc[0], acc[1]);
|
||||
const acc_3 = tree_partition1(comparer, f, s.data[0], s.data[1], acc_2[0], acc_2[1]);
|
||||
return tree_partitionAux(comparer, f, s.data[2], acc_3[0], acc_3[1]);
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
function tree_partition(comparer, f, s) {
|
||||
return tree_partitionAux(comparer, f, s, tree_empty(), tree_empty());
|
||||
}
|
||||
function tree_filter1(comparer, f, k, v, acc) {
|
||||
return f(k, v) ? tree_add(comparer, k, v, acc) : acc;
|
||||
}
|
||||
function tree_filterAux(comparer, f, s, acc) {
|
||||
return s.tag === 1 ? tree_filter1(comparer, f, s.data[0], s.data[1], acc) : s.tag === 2 ?
|
||||
tree_filterAux(comparer, f, s.data[3], tree_filter1(comparer, f, s.data[0], s.data[1], tree_filterAux(comparer, f, s.data[2], acc))) : acc;
|
||||
}
|
||||
function tree_filter(comparer, f, s) {
|
||||
return tree_filterAux(comparer, f, s, tree_empty());
|
||||
}
|
||||
function tree_spliceOutSuccessor(m) {
|
||||
if (m.tag === 1) {
|
||||
return [m.data[0], m.data[1], new MapTree(0)];
|
||||
}
|
||||
else if (m.tag === 2) {
|
||||
if (m.data[2].tag === 0) {
|
||||
return [m.data[0], m.data[1], m.data[3]];
|
||||
}
|
||||
else {
|
||||
const kvl = tree_spliceOutSuccessor(m.data[2]);
|
||||
return [kvl[0], kvl[1], tree_mk(kvl[2], m.data[0], m.data[1], m.data[3])];
|
||||
}
|
||||
}
|
||||
throw new Error("internal error: Map.spliceOutSuccessor");
|
||||
}
|
||||
function tree_remove(comparer, k, m) {
|
||||
if (m.tag === 1) {
|
||||
const c = comparer.Compare(k, m.data[0]);
|
||||
if (c === 0) {
|
||||
return new MapTree(0);
|
||||
}
|
||||
else {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
else if (m.tag === 2) {
|
||||
const c = comparer.Compare(k, m.data[0]);
|
||||
if (c < 0) {
|
||||
return tree_rebalance(tree_remove(comparer, k, m.data[2]), m.data[0], m.data[1], m.data[3]);
|
||||
}
|
||||
else if (c === 0) {
|
||||
if (m.data[2].tag === 0) {
|
||||
return m.data[3];
|
||||
}
|
||||
else {
|
||||
if (m.data[3].tag === 0) {
|
||||
return m.data[2];
|
||||
}
|
||||
else {
|
||||
const input = tree_spliceOutSuccessor(m.data[3]);
|
||||
return tree_mk(m.data[2], input[0], input[1], input[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return tree_rebalance(m.data[2], m.data[0], m.data[1], tree_remove(comparer, k, m.data[3]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
return tree_empty();
|
||||
}
|
||||
}
|
||||
function tree_mem(comparer, k, m) {
|
||||
mem: while (true) {
|
||||
if (m.tag === 1) {
|
||||
return comparer.Compare(k, m.data[0]) === 0;
|
||||
}
|
||||
else if (m.tag === 2) {
|
||||
const c = comparer.Compare(k, m.data[0]) | 0;
|
||||
if (c < 0) {
|
||||
comparer = comparer;
|
||||
k = k;
|
||||
m = m.data[2];
|
||||
continue mem;
|
||||
}
|
||||
else if (c === 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
comparer = comparer;
|
||||
k = k;
|
||||
m = m.data[3];
|
||||
continue mem;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
function tree_iter(f, m) {
|
||||
if (m.tag === 1) {
|
||||
f(m.data[0], m.data[1]);
|
||||
}
|
||||
else if (m.tag === 2) {
|
||||
tree_iter(f, m.data[2]);
|
||||
f(m.data[0], m.data[1]);
|
||||
tree_iter(f, m.data[3]);
|
||||
}
|
||||
}
|
||||
function tree_tryPick(f, m) {
|
||||
if (m.tag === 1) {
|
||||
return f(m.data[0], m.data[1]);
|
||||
}
|
||||
else if (m.tag === 2) {
|
||||
const matchValue = tree_tryPick(f, m.data[2]);
|
||||
if (matchValue == null) {
|
||||
const matchValue_1 = f(m.data[0], m.data[1]);
|
||||
if (matchValue_1 == null) {
|
||||
return tree_tryPick(f, m.data[3]);
|
||||
}
|
||||
else {
|
||||
const res = matchValue_1;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return matchValue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
function tree_exists(f, m) {
|
||||
return m.tag === 1 ? f(m.data[0], m.data[1]) : m.tag === 2 ? (tree_exists(f, m.data[2]) ?
|
||||
true : f(m.data[0], m.data[1])) ? true : tree_exists(f, m.data[3]) : false;
|
||||
}
|
||||
function tree_forall(f, m) {
|
||||
return m.tag === 1 ? f(m.data[0], m.data[1]) : m.tag === 2 ? (tree_forall(f, m.data[2]) ?
|
||||
f(m.data[0], m.data[1]) : false) ? tree_forall(f, m.data[3]) : false : true;
|
||||
}
|
||||
function tree_mapi(f, m) {
|
||||
return m.tag === 1 ? new MapTree(1, [m.data[0], f(m.data[0], m.data[1])]) : m.tag === 2 ?
|
||||
new MapTree(2, [m.data[0], f(m.data[0], m.data[1]), tree_mapi(f, m.data[2]),
|
||||
tree_mapi(f, m.data[3]), m.data[4]]) : tree_empty();
|
||||
}
|
||||
function tree_foldBack(f, m, x) {
|
||||
return m.tag === 1 ? f(m.data[0], m.data[1], x) : m.tag === 2 ?
|
||||
tree_foldBack(f, m.data[2], f(m.data[0], m.data[1], tree_foldBack(f, m.data[3], x))) : x;
|
||||
}
|
||||
function tree_fold(f, x, m) {
|
||||
return m.tag === 1 ? f(x, m.data[0], m.data[1]) : m.tag === 2 ?
|
||||
tree_fold(f, f(tree_fold(f, x, m.data[2]), m.data[0], m.data[1]), m.data[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.tag === 1) {
|
||||
// var cLoKey = comparer.Compare(lo, m.data[0]);
|
||||
// var cKeyHi = comparer.Compare(m.data[0], hi);
|
||||
// var x_1 = (cLoKey <= 0 ? cKeyHi <= 0 : false) ? f(m.data[0], m.data[1], x) : x;
|
||||
// return x_1;
|
||||
// } else if (m.tag === 2) {
|
||||
// var cLoKey = comparer.Compare(lo, m.data[0]);
|
||||
// var cKeyHi = comparer.Compare(m.data[0], hi);
|
||||
// var x_1 = cLoKey < 0 ? tree_foldFromTo(comparer, lo, hi, f, m.data[2], x) : x;
|
||||
// var x_2 = (cLoKey <= 0 ? cKeyHi <= 0 : false) ? f(m.data[0], m.data[1], x_1) : x_1;
|
||||
// var x_3 = cKeyHi < 0 ? tree_foldFromTo(comparer, lo, hi, f, m.data[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.tag === 1
|
||||
// ? new List([m.data[0], m.data[1]], acc)
|
||||
// : m.tag === 2
|
||||
// ? tree_loop(m.data[2], new List([m.data[0], m.data[1]], tree_loop(m.data[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) {
|
||||
let cur = e.next();
|
||||
while (!cur.done) {
|
||||
acc = tree_add(comparer, cur.value[0], cur.value[1], acc);
|
||||
cur = e.next();
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
// 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) {
|
||||
const ie = c[Symbol.iterator]();
|
||||
return tree_mkFromEnumerator(comparer, tree_empty(), ie);
|
||||
}
|
||||
// function tree_copyToArray(s: MapTree, arr: ArrayLike<any>, i: number) {
|
||||
// tree_iter((x, y) => { arr[i++] = [x, y]; }, s);
|
||||
// }
|
||||
function tree_collapseLHS(stack) {
|
||||
if (stack.tail != null) {
|
||||
if (stack.head.tag === 1) {
|
||||
return stack;
|
||||
}
|
||||
else if (stack.head.tag === 2) {
|
||||
return tree_collapseLHS(listOfArray([
|
||||
stack.head.data[2],
|
||||
new MapTree(1, [stack.head.data[0], stack.head.data[1]]),
|
||||
stack.head.data[3],
|
||||
], stack.tail));
|
||||
}
|
||||
else {
|
||||
return tree_collapseLHS(stack.tail);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return new List();
|
||||
}
|
||||
}
|
||||
function tree_mkIterator(s) {
|
||||
return { stack: tree_collapseLHS(new List(s, new List())), started: false };
|
||||
}
|
||||
function tree_moveNext(i) {
|
||||
function current(it) {
|
||||
if (it.stack.tail == null) {
|
||||
return null;
|
||||
}
|
||||
else if (it.stack.head.tag === 1) {
|
||||
return [it.stack.head.data[0], it.stack.head.data[1]];
|
||||
}
|
||||
throw new Error("Please report error: Map iterator, unexpected stack for current");
|
||||
}
|
||||
if (i.started) {
|
||||
if (i.stack.tail == null) {
|
||||
return { done: true, value: null };
|
||||
}
|
||||
else {
|
||||
if (i.stack.head.tag === 1) {
|
||||
i.stack = tree_collapseLHS(i.stack.tail);
|
||||
return {
|
||||
done: i.stack.tail == null,
|
||||
value: current(i),
|
||||
};
|
||||
}
|
||||
else {
|
||||
throw new Error("Please report error: Map iterator, unexpected stack for moveNext");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
i.started = true;
|
||||
return {
|
||||
done: i.stack.tail == null,
|
||||
value: current(i),
|
||||
};
|
||||
}
|
||||
}
|
||||
export default class FableMap {
|
||||
/** Do not call, use Map.create instead. */
|
||||
constructor() { return; }
|
||||
ToString() {
|
||||
return "map [" + Array.from(this).map((x) => toString(x)).join("; ") + "]";
|
||||
}
|
||||
Equals(m2) {
|
||||
return this.CompareTo(m2) === 0;
|
||||
}
|
||||
CompareTo(m2) {
|
||||
return this === m2 ? 0 : seqCompareWith((kvp1, kvp2) => {
|
||||
const c = this.comparer.Compare(kvp1[0], kvp2[0]);
|
||||
return c !== 0 ? c : compare(kvp1[1], kvp2[1]);
|
||||
}, this, m2);
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
const i = tree_mkIterator(this.tree);
|
||||
return {
|
||||
next: () => tree_moveNext(i),
|
||||
};
|
||||
}
|
||||
entries() {
|
||||
return this[Symbol.iterator]();
|
||||
}
|
||||
keys() {
|
||||
return seqMap((kv) => kv[0], this);
|
||||
}
|
||||
values() {
|
||||
return seqMap((kv) => kv[1], this);
|
||||
}
|
||||
get(k) {
|
||||
return tree_find(this.comparer, k, this.tree);
|
||||
}
|
||||
has(k) {
|
||||
return tree_mem(this.comparer, k, this.tree);
|
||||
}
|
||||
/** Mutating method */
|
||||
set(k, v) {
|
||||
this.tree = tree_add(this.comparer, k, v, this.tree);
|
||||
}
|
||||
/** Mutating method */
|
||||
delete(k) {
|
||||
// TODO: Is calculating the size twice is more performant than calling tree_mem?
|
||||
const oldSize = tree_size(this.tree);
|
||||
this.tree = tree_remove(this.comparer, k, this.tree);
|
||||
return oldSize > tree_size(this.tree);
|
||||
}
|
||||
/** Mutating method */
|
||||
clear() {
|
||||
this.tree = tree_empty();
|
||||
}
|
||||
get size() {
|
||||
return tree_size(this.tree);
|
||||
}
|
||||
[FSymbol.reflection]() {
|
||||
return {
|
||||
type: "Microsoft.FSharp.Collections.FSharpMap",
|
||||
interfaces: ["System.IEquatable", "System.IComparable", "System.Collections.Generic.IDictionary"],
|
||||
};
|
||||
}
|
||||
}
|
||||
function from(comparer, tree) {
|
||||
const map = new FableMap();
|
||||
map.tree = tree;
|
||||
map.comparer = comparer || new Comparer();
|
||||
return map;
|
||||
}
|
||||
export function create(ie, comparer) {
|
||||
comparer = comparer || new Comparer();
|
||||
return from(comparer, ie ? tree_ofSeq(comparer, ie) : tree_empty());
|
||||
}
|
||||
export function add(k, v, map) {
|
||||
return from(map.comparer, tree_add(map.comparer, k, v, map.tree));
|
||||
}
|
||||
export function remove(item, map) {
|
||||
return from(map.comparer, tree_remove(map.comparer, item, map.tree));
|
||||
}
|
||||
export function containsValue(v, map) {
|
||||
return seqFold((acc, k) => acc || equals(map.get(k), v), false, map.keys());
|
||||
}
|
||||
export function tryGetValue(map, key, defaultValue) {
|
||||
return map.has(key) ? [true, map.get(key)] : [false, defaultValue];
|
||||
}
|
||||
export function exists(f, map) {
|
||||
return tree_exists(f, map.tree);
|
||||
}
|
||||
export function find(k, map) {
|
||||
return tree_find(map.comparer, k, map.tree);
|
||||
}
|
||||
export function tryFind(k, map) {
|
||||
return tree_tryFind(map.comparer, k, map.tree);
|
||||
}
|
||||
export function filter(f, map) {
|
||||
return from(map.comparer, tree_filter(map.comparer, f, map.tree));
|
||||
}
|
||||
export function fold(f, seed, map) {
|
||||
return tree_fold(f, seed, map.tree);
|
||||
}
|
||||
export function foldBack(f, map, seed) {
|
||||
return tree_foldBack(f, map.tree, seed);
|
||||
}
|
||||
export function forAll(f, map) {
|
||||
return tree_forall(f, map.tree);
|
||||
}
|
||||
export function isEmpty(map) {
|
||||
return tree_isEmpty(map.tree);
|
||||
}
|
||||
export function iterate(f, map) {
|
||||
tree_iter(f, map.tree);
|
||||
}
|
||||
export function map(f, map) {
|
||||
return from(map.comparer, tree_mapi(f, map.tree));
|
||||
}
|
||||
export function partition(f, map) {
|
||||
const rs = tree_partition(map.comparer, f, map.tree);
|
||||
return [from(map.comparer, rs[0]), from(map.comparer, rs[1])];
|
||||
}
|
||||
export function findKey(f, map) {
|
||||
return seqPick((kv) => f(kv[0], kv[1]) ? makeSome(kv[0]) : null, map);
|
||||
}
|
||||
export function tryFindKey(f, map) {
|
||||
return seqTryPick((kv) => f(kv[0], kv[1]) ? makeSome(kv[0]) : null, map);
|
||||
}
|
||||
export function pick(f, map) {
|
||||
const res = tryPick(f, map);
|
||||
if (res != null) {
|
||||
return getValue(res);
|
||||
}
|
||||
throw new Error("key not found");
|
||||
}
|
||||
export function tryPick(f, map) {
|
||||
return tree_tryPick(f, map.tree);
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
import { getValue } from "./Option";
|
||||
import FSymbol from "./Symbol";
|
||||
import { createDisposable } from "./Util";
|
||||
export class Observer {
|
||||
constructor(onNext, onError, onCompleted) {
|
||||
this.OnNext = onNext;
|
||||
this.OnError = onError || ((e) => { return; });
|
||||
this.OnCompleted = onCompleted || (() => { return; });
|
||||
}
|
||||
[FSymbol.reflection]() {
|
||||
return { interfaces: ["System.IObserver"] };
|
||||
}
|
||||
}
|
||||
class Observable {
|
||||
constructor(subscribe) {
|
||||
this.Subscribe = subscribe;
|
||||
}
|
||||
[FSymbol.reflection]() {
|
||||
return { interfaces: ["System.IObservable"] };
|
||||
}
|
||||
}
|
||||
export function protect(f, succeed, fail) {
|
||||
try {
|
||||
return succeed(f());
|
||||
}
|
||||
catch (e) {
|
||||
fail(e);
|
||||
}
|
||||
}
|
||||
export function add(callback, source) {
|
||||
source.Subscribe(new Observer(callback));
|
||||
}
|
||||
export function choose(chooser, source) {
|
||||
return new Observable((observer) => source.Subscribe(new Observer((t) => protect(() => chooser(t), (u) => { if (u != null) {
|
||||
observer.OnNext(getValue(u));
|
||||
} }, observer.OnError), observer.OnError, observer.OnCompleted)));
|
||||
}
|
||||
export function filter(predicate, source) {
|
||||
return choose((x) => predicate(x) ? x : null, source);
|
||||
}
|
||||
export function map(mapping, source) {
|
||||
return new Observable((observer) => source.Subscribe(new Observer((t) => {
|
||||
protect(() => mapping(t), observer.OnNext, observer.OnError);
|
||||
}, observer.OnError, observer.OnCompleted)));
|
||||
}
|
||||
export function merge(source1, source2) {
|
||||
return new Observable((observer) => {
|
||||
let stopped = false;
|
||||
let completed1 = false;
|
||||
let completed2 = false;
|
||||
const h1 = source1.Subscribe(new Observer((v) => { if (!stopped) {
|
||||
observer.OnNext(v);
|
||||
} }, (e) => {
|
||||
if (!stopped) {
|
||||
stopped = true;
|
||||
observer.OnError(e);
|
||||
}
|
||||
}, () => {
|
||||
if (!stopped) {
|
||||
completed1 = true;
|
||||
if (completed2) {
|
||||
stopped = true;
|
||||
observer.OnCompleted();
|
||||
}
|
||||
}
|
||||
}));
|
||||
const h2 = source2.Subscribe(new Observer((v) => { if (!stopped) {
|
||||
observer.OnNext(v);
|
||||
} }, (e) => {
|
||||
if (!stopped) {
|
||||
stopped = true;
|
||||
observer.OnError(e);
|
||||
}
|
||||
}, () => {
|
||||
if (!stopped) {
|
||||
completed2 = true;
|
||||
if (completed1) {
|
||||
stopped = true;
|
||||
observer.OnCompleted();
|
||||
}
|
||||
}
|
||||
}));
|
||||
return createDisposable(() => {
|
||||
h1.Dispose();
|
||||
h2.Dispose();
|
||||
});
|
||||
});
|
||||
}
|
||||
export function pairwise(source) {
|
||||
return new Observable((observer) => {
|
||||
let last = null;
|
||||
return source.Subscribe(new Observer((next) => {
|
||||
if (last != null) {
|
||||
observer.OnNext([last, next]);
|
||||
}
|
||||
last = next;
|
||||
}, observer.OnError, observer.OnCompleted));
|
||||
});
|
||||
}
|
||||
export function partition(predicate, source) {
|
||||
return [filter(predicate, source), filter((x) => !predicate(x), source)];
|
||||
}
|
||||
export function scan(collector, state, source) {
|
||||
return new Observable((observer) => {
|
||||
return source.Subscribe(new Observer((t) => {
|
||||
protect(() => collector(state, t), (u) => { state = u; observer.OnNext(u); }, observer.OnError);
|
||||
}, observer.OnError, observer.OnCompleted));
|
||||
});
|
||||
}
|
||||
export function split(splitter, source) {
|
||||
return [choose((v) => splitter(v).valueIfChoice1, source), choose((v) => splitter(v).valueIfChoice2, source)];
|
||||
}
|
||||
export function subscribe(callback, source) {
|
||||
return source.Subscribe(new Observer(callback));
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
import { compare, equals, toString } from "./Util";
|
||||
export class Some {
|
||||
constructor(value) {
|
||||
this.value = value;
|
||||
}
|
||||
// We don't prefix it with "Some" for consistency with erased options
|
||||
ToString() {
|
||||
return toString(this.value);
|
||||
}
|
||||
Equals(other) {
|
||||
if (other == null) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return equals(this.value, other instanceof Some
|
||||
? other.value : other);
|
||||
}
|
||||
}
|
||||
CompareTo(other) {
|
||||
if (other == null) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return compare(this.value, other instanceof Some
|
||||
? other.value : other);
|
||||
}
|
||||
}
|
||||
}
|
||||
export function makeSome(x) {
|
||||
return x == null || x instanceof Some ? new Some(x) : x;
|
||||
}
|
||||
export function getValue(x, acceptNull) {
|
||||
if (x == null) {
|
||||
if (!acceptNull) {
|
||||
throw new Error("Option has no value");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return x instanceof Some ? x.value : x;
|
||||
}
|
||||
}
|
||||
export function defaultArg(arg, defaultValue, f) {
|
||||
return arg == null ? defaultValue : (f != null ? f(getValue(arg)) : getValue(arg));
|
||||
}
|
||||
export function defaultArgWith(arg, defThunk) {
|
||||
return arg == null ? defThunk() : getValue(arg);
|
||||
}
|
||||
export function filter(predicate, arg) {
|
||||
return arg != null ? (!predicate(getValue(arg)) ? null : arg) : arg;
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
import List from "./List";
|
||||
import FSymbol from "./Symbol";
|
||||
import { getDefinition, getPropertyNames, NonDeclaredType } from "./Util";
|
||||
export class MemberInfo {
|
||||
constructor(name, index, declaringType, propertyType, unionFields) {
|
||||
this.name = name;
|
||||
this.index = index;
|
||||
this.declaringType = declaringType;
|
||||
this.propertyType = propertyType;
|
||||
this.unionFields = unionFields;
|
||||
}
|
||||
getUnionFields() {
|
||||
return this.unionFields.map((fi, i) => new MemberInfo("unknown", i, this.declaringType, fi));
|
||||
}
|
||||
}
|
||||
export function resolveGeneric(idx, enclosing) {
|
||||
try {
|
||||
const t = enclosing.head;
|
||||
if (t.generics == null) {
|
||||
return resolveGeneric(idx, enclosing.tail);
|
||||
}
|
||||
else {
|
||||
const name = typeof idx === "string"
|
||||
? idx : Object.getOwnPropertyNames(t.generics)[idx];
|
||||
const resolved = t.generics[name];
|
||||
if (resolved == null) {
|
||||
return resolveGeneric(idx, enclosing.tail);
|
||||
}
|
||||
else if (resolved instanceof NonDeclaredType && resolved.kind === "GenericParam") {
|
||||
return resolveGeneric(resolved.definition, enclosing.tail);
|
||||
}
|
||||
else {
|
||||
return new List(resolved, enclosing);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
throw new Error(`Cannot resolve generic argument ${idx}: ${err}`);
|
||||
}
|
||||
}
|
||||
export function getType(obj) {
|
||||
const t = typeof obj;
|
||||
switch (t) {
|
||||
case "boolean":
|
||||
case "number":
|
||||
case "string":
|
||||
case "function":
|
||||
return t;
|
||||
default:
|
||||
return Object.getPrototypeOf(obj).constructor;
|
||||
}
|
||||
}
|
||||
// TODO: This needs improvement, check namespace for non-custom types?
|
||||
export function getTypeFullName(typ, option) {
|
||||
function trim(fullName, opt) {
|
||||
if (typeof fullName !== "string") {
|
||||
return "unknown";
|
||||
}
|
||||
if (opt === "name") {
|
||||
const i = fullName.lastIndexOf(".");
|
||||
return fullName.substr(i + 1);
|
||||
}
|
||||
if (opt === "namespace") {
|
||||
const i = fullName.lastIndexOf(".");
|
||||
return i > -1 ? fullName.substr(0, i) : "";
|
||||
}
|
||||
return fullName;
|
||||
}
|
||||
if (typeof typ === "string") {
|
||||
return typ;
|
||||
}
|
||||
else if (typ instanceof NonDeclaredType) {
|
||||
switch (typ.kind) {
|
||||
case "Unit":
|
||||
return "unit";
|
||||
case "Option":
|
||||
return getTypeFullName(typ.generics[0], option) + " option";
|
||||
case "Array":
|
||||
return getTypeFullName(typ.generics[0], option) + "[]";
|
||||
case "Tuple":
|
||||
return typ.generics.map((x) => getTypeFullName(x, option)).join(" * ");
|
||||
case "Function":
|
||||
return "Func<" + typ.generics.map((x) => getTypeFullName(x, option)).join(", ") + ">";
|
||||
case "GenericParam":
|
||||
case "Interface":
|
||||
return typ.definition;
|
||||
case "GenericType":
|
||||
return getTypeFullName(typ.definition, option);
|
||||
case "Any":
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Attention: this doesn't work with Object.getPrototypeOf
|
||||
const proto = typ.prototype;
|
||||
return trim(typeof proto[FSymbol.reflection] === "function"
|
||||
? proto[FSymbol.reflection]().type : null, option);
|
||||
}
|
||||
}
|
||||
export function getName(x) {
|
||||
if (x instanceof MemberInfo) {
|
||||
return x.name;
|
||||
}
|
||||
return getTypeFullName(x, "name");
|
||||
}
|
||||
export function getPrototypeOfType(typ) {
|
||||
if (typeof typ === "string") {
|
||||
return null;
|
||||
}
|
||||
else if (typ instanceof NonDeclaredType) {
|
||||
return typ.kind === "GenericType" ? typ.definition.prototype : null;
|
||||
}
|
||||
else {
|
||||
return typ.prototype;
|
||||
}
|
||||
}
|
||||
export function getProperties(typ) {
|
||||
const proto = getPrototypeOfType(typ);
|
||||
if (proto != null && typeof proto[FSymbol.reflection] === "function") {
|
||||
const info = proto[FSymbol.reflection]();
|
||||
if (info.properties) {
|
||||
return Object.getOwnPropertyNames(info.properties)
|
||||
.map((k, i) => new MemberInfo(k, i, typ, info.properties[k]));
|
||||
}
|
||||
}
|
||||
throw new Error("Type " + getTypeFullName(typ) + " doesn't contain property info.");
|
||||
}
|
||||
export function getUnionCases(typ) {
|
||||
const proto = getPrototypeOfType(typ);
|
||||
if (proto != null && typeof proto[FSymbol.reflection] === "function") {
|
||||
const info = proto[FSymbol.reflection]();
|
||||
if (info.cases) {
|
||||
return info.cases.map((uci, i) => new MemberInfo(uci[0], i, typ, null, uci.slice(1)));
|
||||
}
|
||||
}
|
||||
throw new Error("Type " + getTypeFullName(typ) + " doesn't contain union case info.");
|
||||
}
|
||||
export function getPropertyValues(obj) {
|
||||
return getPropertyNames(obj).map((k) => obj[k]);
|
||||
}
|
||||
export function getUnionFields(obj, typ) {
|
||||
if (obj != null && typeof obj[FSymbol.reflection] === "function") {
|
||||
const info = obj[FSymbol.reflection]();
|
||||
if (info.cases) {
|
||||
const uci = info.cases[obj.tag];
|
||||
if (uci != null) {
|
||||
const fields = uci.length > 2 ? obj.data : (uci.length > 1 ? [obj.data] : []);
|
||||
return [new MemberInfo(uci[0], obj.tag, typ, null, uci.slice(1)), fields];
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error("Not an F# union type.");
|
||||
}
|
||||
export function makeUnion(caseInfo, args) {
|
||||
const Cons = getDefinition(caseInfo.declaringType);
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
return new Cons(caseInfo.index);
|
||||
case 1:
|
||||
return new Cons(caseInfo.index, args[0]);
|
||||
default:
|
||||
return new Cons(caseInfo.index, args);
|
||||
}
|
||||
}
|
||||
export function getTupleElements(typ) {
|
||||
if (typ instanceof NonDeclaredType && typ.kind === "Tuple") {
|
||||
return typ.generics;
|
||||
}
|
||||
throw new Error("Type " + getTypeFullName(typ) + " is not a tuple type.");
|
||||
}
|
||||
export function isTupleType(typ) {
|
||||
if (typ instanceof NonDeclaredType) {
|
||||
return typ.kind === "Tuple";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function getFunctionElements(typ) {
|
||||
if (typ === "function") {
|
||||
throw new Error("The type of the function must be known at compile time to get the elements.");
|
||||
}
|
||||
if (typ instanceof NonDeclaredType && typ.kind === "Function") {
|
||||
return typ.generics;
|
||||
}
|
||||
throw new Error("Type " + getTypeFullName(typ) + " is not a function type.");
|
||||
}
|
||||
export function isFunctionType(typ) {
|
||||
return typ === "function" || (typ instanceof NonDeclaredType && typ.kind === "Function");
|
||||
}
|
||||
export function getGenericArguments(typ) {
|
||||
if (typ instanceof NonDeclaredType) {
|
||||
if (Array.isArray(typ.generics)) {
|
||||
return typ.generics;
|
||||
}
|
||||
else {
|
||||
const dic = typ.generics;
|
||||
return Object.keys(dic).map((k) => dic[k]);
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
export function create(pattern, options) {
|
||||
let flags = "g";
|
||||
flags += options & 1 ? "i" : "";
|
||||
flags += options & 2 ? "m" : "";
|
||||
return new RegExp(pattern, flags);
|
||||
}
|
||||
// From http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
|
||||
export function escape(str) {
|
||||
return str.replace(/[\-\[\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
||||
}
|
||||
export function unescape(str) {
|
||||
return str.replace(/\\([\-\[\/\{\}\(\)\*\+\?\.\\\^\$\|])/g, "$1");
|
||||
}
|
||||
export function isMatch(str, pattern, options = 0) {
|
||||
let reg;
|
||||
reg = str instanceof RegExp
|
||||
? (reg = str, str = pattern, reg.lastIndex = options, reg)
|
||||
: reg = create(pattern, options);
|
||||
return reg.test(str);
|
||||
}
|
||||
export function match(str, pattern, options = 0) {
|
||||
let reg;
|
||||
reg = str instanceof RegExp
|
||||
? (reg = str, str = pattern, reg.lastIndex = options, reg)
|
||||
: reg = create(pattern, options);
|
||||
return reg.exec(str);
|
||||
}
|
||||
export function matches(str, pattern, options = 0) {
|
||||
let reg;
|
||||
reg = str instanceof RegExp
|
||||
? (reg = str, str = pattern, reg.lastIndex = options, reg)
|
||||
: reg = create(pattern, options);
|
||||
if (!reg.global) {
|
||||
throw new Error("Non-global RegExp"); // Prevent infinite loop
|
||||
}
|
||||
let m = reg.exec(str);
|
||||
const matches = [];
|
||||
while (m !== null) {
|
||||
matches.push(m);
|
||||
m = reg.exec(str);
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
export function options(reg) {
|
||||
let options = 256; // ECMAScript
|
||||
options |= reg.ignoreCase ? 1 : 0;
|
||||
options |= reg.multiline ? 2 : 0;
|
||||
return options;
|
||||
}
|
||||
export function replace(reg, input, replacement, limit, offset = 0) {
|
||||
function replacer() {
|
||||
let res = arguments[0];
|
||||
if (limit !== 0) {
|
||||
limit--;
|
||||
const match = [];
|
||||
const len = arguments.length;
|
||||
for (let i = 0; i < len - 2; i++) {
|
||||
match.push(arguments[i]);
|
||||
}
|
||||
match.index = arguments[len - 2];
|
||||
match.input = arguments[len - 1];
|
||||
res = replacement(match);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
if (typeof reg === "string") {
|
||||
const tmp = reg;
|
||||
reg = create(input, limit);
|
||||
input = tmp;
|
||||
limit = undefined;
|
||||
}
|
||||
if (typeof replacement === "function") {
|
||||
limit = limit == null ? -1 : limit;
|
||||
return input.substring(0, offset) + input.substring(offset).replace(reg, replacer);
|
||||
}
|
||||
else {
|
||||
// $0 doesn't work with JS regex, see #1155
|
||||
replacement = replacement.replace(/\$0/g, (s) => "$&");
|
||||
if (limit != null) {
|
||||
let m;
|
||||
const sub1 = input.substring(offset);
|
||||
const _matches = matches(reg, sub1);
|
||||
const sub2 = matches.length > limit ? (m = _matches[limit - 1], sub1.substring(0, m.index + m[0].length)) : sub1;
|
||||
return input.substring(0, offset) + sub2.replace(reg, replacement)
|
||||
+ input.substring(offset + sub2.length);
|
||||
}
|
||||
else {
|
||||
return input.replace(reg, replacement);
|
||||
}
|
||||
}
|
||||
}
|
||||
export function split(reg, input, limit, offset = 0) {
|
||||
if (typeof reg === "string") {
|
||||
const tmp = reg;
|
||||
reg = create(input, limit);
|
||||
input = tmp;
|
||||
limit = undefined;
|
||||
}
|
||||
input = input.substring(offset);
|
||||
return input.split(reg, limit);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import FSymbol from "./Symbol";
|
||||
import { GenericParam } from "./Util";
|
||||
import { compareUnions, equalsUnions } from "./Util";
|
||||
export default class Result {
|
||||
constructor(tag, data) {
|
||||
this.tag = tag | 0;
|
||||
this.data = data;
|
||||
}
|
||||
Equals(other) {
|
||||
return equalsUnions(this, other);
|
||||
}
|
||||
CompareTo(other) {
|
||||
return compareUnions(this, other);
|
||||
}
|
||||
[FSymbol.reflection]() {
|
||||
return {
|
||||
type: "Microsoft.FSharp.Core.FSharpResult",
|
||||
interfaces: ["FSharpUnion", "System.IEquatable", "System.IComparable"],
|
||||
cases: [["Ok", GenericParam("T")], ["Error", GenericParam("TError")]],
|
||||
};
|
||||
}
|
||||
}
|
||||
export function map(f, result) {
|
||||
return result.tag === 0 ? new Result(0, f(result.data)) : result;
|
||||
}
|
||||
export function mapError(f, result) {
|
||||
return result.tag === 1 ? new Result(1, f(result.data)) : result;
|
||||
}
|
||||
export function bind(f, result) {
|
||||
return result.tag === 0 ? f(result.data) : result;
|
||||
}
|
||||
-708
@@ -1,708 +0,0 @@
|
||||
import { permute as arrayPermute } from "./Array";
|
||||
import { chunkBySize as arrayChunkBySize } from "./Array";
|
||||
import List from "./ListClass";
|
||||
import { getValue, makeSome } from "./Option";
|
||||
import { compare, equals } from "./Util";
|
||||
export class Enumerator {
|
||||
constructor(iter) {
|
||||
this.iter = iter;
|
||||
}
|
||||
MoveNext() {
|
||||
const cur = this.iter.next();
|
||||
this.current = cur.value;
|
||||
return !cur.done;
|
||||
}
|
||||
get Current() { return this.current; }
|
||||
get get_Current() { return this.current; }
|
||||
Reset() {
|
||||
throw new Error("JS iterators cannot be reset");
|
||||
}
|
||||
Dispose() { return; }
|
||||
}
|
||||
export function getEnumerator(o) {
|
||||
return typeof o.GetEnumerator === "function"
|
||||
? o.GetEnumerator() : new Enumerator(o[Symbol.iterator]());
|
||||
}
|
||||
export function toIterator(en) {
|
||||
return {
|
||||
next() {
|
||||
return en.MoveNext()
|
||||
? { done: false, value: en.Current }
|
||||
: { done: true, value: null };
|
||||
},
|
||||
};
|
||||
}
|
||||
function __failIfNone(res) {
|
||||
if (res == null) {
|
||||
throw new Error("Seq did not contain any matching element");
|
||||
}
|
||||
return getValue(res);
|
||||
}
|
||||
export function toList(xs) {
|
||||
return foldBack((x, acc) => new List(x, acc), xs, new List());
|
||||
}
|
||||
export function ofList(xs) {
|
||||
return delay(() => unfold((x) => x.tail != null ? [x.head, x.tail] : null, xs));
|
||||
}
|
||||
export function ofArray(xs) {
|
||||
return delay(() => unfold((i) => i < xs.length ? [xs[i], i + 1] : null, 0));
|
||||
}
|
||||
export function append(xs, ys) {
|
||||
return delay(() => {
|
||||
let firstDone = false;
|
||||
const i = xs[Symbol.iterator]();
|
||||
let iters = [i, null];
|
||||
return unfold(() => {
|
||||
let cur;
|
||||
if (!firstDone) {
|
||||
cur = iters[0].next();
|
||||
if (!cur.done) {
|
||||
return [cur.value, iters];
|
||||
}
|
||||
else {
|
||||
firstDone = true;
|
||||
iters = [null, ys[Symbol.iterator]()];
|
||||
}
|
||||
}
|
||||
cur = iters[1].next();
|
||||
return !cur.done ? [cur.value, iters] : null;
|
||||
}, iters);
|
||||
});
|
||||
}
|
||||
export function average(xs) {
|
||||
let count = 1;
|
||||
const sum = reduce((acc, x) => {
|
||||
count++;
|
||||
return acc + x;
|
||||
}, xs);
|
||||
return sum / count;
|
||||
}
|
||||
export function averageBy(f, xs) {
|
||||
let count = 1;
|
||||
const sum = reduce((acc, x) => {
|
||||
count++;
|
||||
return (count === 2 ? f(acc) : acc) + f(x);
|
||||
}, xs);
|
||||
return sum / count;
|
||||
}
|
||||
export function concat(xs) {
|
||||
return delay(() => {
|
||||
const iter = xs[Symbol.iterator]();
|
||||
let output = { value: null };
|
||||
return unfold((innerIter) => {
|
||||
let hasFinished = false;
|
||||
while (!hasFinished) {
|
||||
if (innerIter == null) {
|
||||
const cur = iter.next();
|
||||
if (!cur.done) {
|
||||
innerIter = cur.value[Symbol.iterator]();
|
||||
}
|
||||
else {
|
||||
hasFinished = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
const cur = innerIter.next();
|
||||
if (!cur.done) {
|
||||
output = { value: cur.value };
|
||||
hasFinished = true;
|
||||
}
|
||||
else {
|
||||
innerIter = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return innerIter != null && output != null ? [output.value, innerIter] : null;
|
||||
}, null);
|
||||
});
|
||||
}
|
||||
export function collect(f, xs) {
|
||||
return concat(map(f, xs));
|
||||
}
|
||||
export function choose(f, xs) {
|
||||
return delay(() => unfold((iter) => {
|
||||
let cur = iter.next();
|
||||
while (!cur.done) {
|
||||
const y = f(cur.value);
|
||||
if (y != null) {
|
||||
return [getValue(y), iter];
|
||||
}
|
||||
cur = iter.next();
|
||||
}
|
||||
return null;
|
||||
}, xs[Symbol.iterator]()));
|
||||
}
|
||||
export function compareWith(f, xs, ys) {
|
||||
const nonZero = tryFind((i) => i !== 0, map2((x, y) => f(x, y), xs, ys));
|
||||
return nonZero != null ? getValue(nonZero) : count(xs) - count(ys);
|
||||
}
|
||||
export function delay(f) {
|
||||
return {
|
||||
[Symbol.iterator]: () => f()[Symbol.iterator](),
|
||||
};
|
||||
}
|
||||
export function empty() {
|
||||
return unfold(() => void 0);
|
||||
}
|
||||
export function enumerateWhile(cond, xs) {
|
||||
return concat(unfold(() => cond() ? [xs, true] : null));
|
||||
}
|
||||
export function enumerateThenFinally(xs, finalFn) {
|
||||
return delay(() => {
|
||||
let iter;
|
||||
try {
|
||||
iter = xs[Symbol.iterator]();
|
||||
}
|
||||
catch (err) {
|
||||
return void 0;
|
||||
}
|
||||
finally {
|
||||
finalFn();
|
||||
}
|
||||
return unfold((it) => {
|
||||
try {
|
||||
const cur = it.next();
|
||||
return !cur.done ? [cur.value, it] : null;
|
||||
}
|
||||
catch (err) {
|
||||
return void 0;
|
||||
}
|
||||
finally {
|
||||
finalFn();
|
||||
}
|
||||
}, iter);
|
||||
});
|
||||
}
|
||||
export function enumerateUsing(disp, work) {
|
||||
let isDisposed = false;
|
||||
const disposeOnce = () => {
|
||||
if (!isDisposed) {
|
||||
isDisposed = true;
|
||||
disp.Dispose();
|
||||
}
|
||||
};
|
||||
try {
|
||||
return enumerateThenFinally(work(disp), disposeOnce);
|
||||
}
|
||||
catch (err) {
|
||||
return void 0;
|
||||
}
|
||||
finally {
|
||||
disposeOnce();
|
||||
}
|
||||
}
|
||||
export function exactlyOne(xs) {
|
||||
const iter = xs[Symbol.iterator]();
|
||||
const fst = iter.next();
|
||||
if (fst.done) {
|
||||
throw new Error("Seq was empty");
|
||||
}
|
||||
const snd = iter.next();
|
||||
if (!snd.done) {
|
||||
throw new Error("Seq had multiple items");
|
||||
}
|
||||
return fst.value;
|
||||
}
|
||||
export function except(itemsToExclude, source) {
|
||||
const exclusionItems = Array.from(itemsToExclude);
|
||||
const testIsNotInExclusionItems = (element) => !exclusionItems.some((excludedItem) => equals(excludedItem, element));
|
||||
return filter(testIsNotInExclusionItems, source);
|
||||
}
|
||||
export function exists(f, xs) {
|
||||
let cur;
|
||||
for (const iter = xs[Symbol.iterator]();;) {
|
||||
cur = iter.next();
|
||||
if (cur.done) {
|
||||
break;
|
||||
}
|
||||
if (f(cur.value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function exists2(f, xs, ys) {
|
||||
let cur1;
|
||||
let cur2;
|
||||
for (const iter1 = xs[Symbol.iterator](), iter2 = ys[Symbol.iterator]();;) {
|
||||
cur1 = iter1.next();
|
||||
cur2 = iter2.next();
|
||||
if (cur1.done || cur2.done) {
|
||||
break;
|
||||
}
|
||||
if (f(cur1.value, cur2.value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function filter(f, xs) {
|
||||
return delay(() => unfold((iter) => {
|
||||
let cur = iter.next();
|
||||
while (!cur.done) {
|
||||
if (f(cur.value)) {
|
||||
return [cur.value, iter];
|
||||
}
|
||||
cur = iter.next();
|
||||
}
|
||||
return null;
|
||||
}, xs[Symbol.iterator]()));
|
||||
}
|
||||
export function where(f, xs) {
|
||||
return filter(f, xs);
|
||||
}
|
||||
export function fold(f, acc, xs) {
|
||||
if (Array.isArray(xs) || ArrayBuffer.isView(xs)) {
|
||||
return xs.reduce(f, acc);
|
||||
}
|
||||
else {
|
||||
let cur;
|
||||
for (let i = 0, iter = xs[Symbol.iterator]();; i++) {
|
||||
cur = iter.next();
|
||||
if (cur.done) {
|
||||
break;
|
||||
}
|
||||
acc = f(acc, cur.value, i);
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
}
|
||||
export function foldBack(f, xs, acc) {
|
||||
const arr = Array.isArray(xs) || ArrayBuffer.isView(xs) ? xs : Array.from(xs);
|
||||
for (let i = arr.length - 1; i >= 0; i--) {
|
||||
acc = f(arr[i], acc, i);
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
export function fold2(f, acc, xs, ys) {
|
||||
const iter1 = xs[Symbol.iterator]();
|
||||
const iter2 = ys[Symbol.iterator]();
|
||||
let cur1;
|
||||
let cur2;
|
||||
for (let i = 0;; i++) {
|
||||
cur1 = iter1.next();
|
||||
cur2 = iter2.next();
|
||||
if (cur1.done || cur2.done) {
|
||||
break;
|
||||
}
|
||||
acc = f(acc, cur1.value, cur2.value, i);
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
export function foldBack2(f, xs, ys, acc) {
|
||||
const ar1 = Array.isArray(xs) || ArrayBuffer.isView(xs) ? xs : Array.from(xs);
|
||||
const ar2 = Array.isArray(ys) || ArrayBuffer.isView(ys) ? ys : Array.from(ys);
|
||||
for (let i = ar1.length - 1; i >= 0; i--) {
|
||||
acc = f(ar1[i], ar2[i], acc, i);
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
export function forAll(f, xs) {
|
||||
return fold((acc, x) => acc && f(x), true, xs);
|
||||
}
|
||||
export function forAll2(f, xs, ys) {
|
||||
return fold2((acc, x, y) => acc && f(x, y), true, xs, ys);
|
||||
}
|
||||
export function tryHead(xs) {
|
||||
const iter = xs[Symbol.iterator]();
|
||||
const cur = iter.next();
|
||||
return cur.done ? null : makeSome(cur.value);
|
||||
}
|
||||
export function head(xs) {
|
||||
return __failIfNone(tryHead(xs));
|
||||
}
|
||||
export function initialize(n, f) {
|
||||
return delay(() => unfold((i) => i < n ? [f(i), i + 1] : null, 0));
|
||||
}
|
||||
export function initializeInfinite(f) {
|
||||
return delay(() => unfold((i) => [f(i), i + 1], 0));
|
||||
}
|
||||
export function tryItem(i, xs) {
|
||||
if (i < 0) {
|
||||
return null;
|
||||
}
|
||||
if (Array.isArray(xs) || ArrayBuffer.isView(xs)) {
|
||||
return i < xs.length ? makeSome(xs[i]) : null;
|
||||
}
|
||||
for (let j = 0, iter = xs[Symbol.iterator]();; j++) {
|
||||
const cur = iter.next();
|
||||
if (cur.done) {
|
||||
break;
|
||||
}
|
||||
if (j === i) {
|
||||
return makeSome(cur.value);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
export function item(i, xs) {
|
||||
return __failIfNone(tryItem(i, xs));
|
||||
}
|
||||
export function iterate(f, xs) {
|
||||
fold((_, x) => f(x), null, xs);
|
||||
}
|
||||
export function iterate2(f, xs, ys) {
|
||||
fold2((_, x, y) => f(x, y), null, xs, ys);
|
||||
}
|
||||
export function iterateIndexed(f, xs) {
|
||||
fold((_, x, i) => f(i, x), null, xs);
|
||||
}
|
||||
export function iterateIndexed2(f, xs, ys) {
|
||||
fold2((_, x, y, i) => f(i, x, y), null, xs, ys);
|
||||
}
|
||||
export function isEmpty(xs) {
|
||||
const i = xs[Symbol.iterator]();
|
||||
return i.next().done;
|
||||
}
|
||||
export function tryLast(xs) {
|
||||
try {
|
||||
return makeSome(reduce((_, x) => x, xs));
|
||||
}
|
||||
catch (err) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
export function last(xs) {
|
||||
return __failIfNone(tryLast(xs));
|
||||
}
|
||||
// A export function 'length' method causes problems in JavaScript -- https://github.com/Microsoft/TypeScript/issues/442
|
||||
export function count(xs) {
|
||||
return Array.isArray(xs) || ArrayBuffer.isView(xs)
|
||||
? xs.length
|
||||
: fold((acc, x) => acc + 1, 0, xs);
|
||||
}
|
||||
export function map(f, xs) {
|
||||
return delay(() => unfold((iter) => {
|
||||
const cur = iter.next();
|
||||
return !cur.done ? [f(cur.value), iter] : null;
|
||||
}, xs[Symbol.iterator]()));
|
||||
}
|
||||
export function mapIndexed(f, xs) {
|
||||
return delay(() => {
|
||||
let i = 0;
|
||||
return unfold((iter) => {
|
||||
const cur = iter.next();
|
||||
return !cur.done ? [f(i++, cur.value), iter] : null;
|
||||
}, xs[Symbol.iterator]());
|
||||
});
|
||||
}
|
||||
export function indexed(xs) {
|
||||
return mapIndexed((i, x) => [i, x], xs);
|
||||
}
|
||||
export function map2(f, xs, ys) {
|
||||
return delay(() => {
|
||||
const iter1 = xs[Symbol.iterator]();
|
||||
const iter2 = ys[Symbol.iterator]();
|
||||
return unfold(() => {
|
||||
const cur1 = iter1.next();
|
||||
const cur2 = iter2.next();
|
||||
return !cur1.done && !cur2.done ? [f(cur1.value, cur2.value), null] : null;
|
||||
});
|
||||
});
|
||||
}
|
||||
export function mapIndexed2(f, xs, ys) {
|
||||
return delay(() => {
|
||||
let i = 0;
|
||||
const iter1 = xs[Symbol.iterator]();
|
||||
const iter2 = ys[Symbol.iterator]();
|
||||
return unfold(() => {
|
||||
const cur1 = iter1.next();
|
||||
const cur2 = iter2.next();
|
||||
return !cur1.done && !cur2.done ? [f(i++, cur1.value, cur2.value), null] : null;
|
||||
});
|
||||
});
|
||||
}
|
||||
export function map3(f, xs, ys, zs) {
|
||||
return delay(() => {
|
||||
const iter1 = xs[Symbol.iterator]();
|
||||
const iter2 = ys[Symbol.iterator]();
|
||||
const iter3 = zs[Symbol.iterator]();
|
||||
return unfold(() => {
|
||||
const cur1 = iter1.next();
|
||||
const cur2 = iter2.next();
|
||||
const cur3 = iter3.next();
|
||||
return !cur1.done && !cur2.done && !cur3.done ? [f(cur1.value, cur2.value, cur3.value), null] : null;
|
||||
});
|
||||
});
|
||||
}
|
||||
export function chunkBySize(size, xs) {
|
||||
const result = arrayChunkBySize(size, Array.from(xs));
|
||||
return ofArray(result);
|
||||
}
|
||||
export function mapFold(f, acc, xs, transform) {
|
||||
const result = [];
|
||||
let r;
|
||||
let cur;
|
||||
for (let i = 0, iter = xs[Symbol.iterator]();; i++) {
|
||||
cur = iter.next();
|
||||
if (cur.done) {
|
||||
break;
|
||||
}
|
||||
[r, acc] = f(acc, cur.value);
|
||||
result.push(r);
|
||||
}
|
||||
return transform !== void 0 ? [transform(result), acc] : [result, acc];
|
||||
}
|
||||
export function mapFoldBack(f, xs, acc, transform) {
|
||||
const arr = Array.isArray(xs) || ArrayBuffer.isView(xs) ? xs : Array.from(xs);
|
||||
const result = [];
|
||||
let r;
|
||||
for (let i = arr.length - 1; i >= 0; i--) {
|
||||
[r, acc] = f(arr[i], acc);
|
||||
result.push(r);
|
||||
}
|
||||
return transform !== void 0 ? [transform(result), acc] : [result, acc];
|
||||
}
|
||||
export function max(xs) {
|
||||
return reduce((acc, x) => compare(acc, x) === 1 ? acc : x, xs);
|
||||
}
|
||||
export function maxBy(f, xs) {
|
||||
return reduce((acc, x) => compare(f(acc), f(x)) === 1 ? acc : x, xs);
|
||||
}
|
||||
export function min(xs) {
|
||||
return reduce((acc, x) => compare(acc, x) === -1 ? acc : x, xs);
|
||||
}
|
||||
export function minBy(f, xs) {
|
||||
return reduce((acc, x) => compare(f(acc), f(x)) === -1 ? acc : x, xs);
|
||||
}
|
||||
export function pairwise(xs) {
|
||||
return skip(2, scan((last, next) => [last[1], next], [0, 0], xs));
|
||||
}
|
||||
export function permute(f, xs) {
|
||||
return ofArray(arrayPermute(f, Array.from(xs)));
|
||||
}
|
||||
export function rangeStep(first, step, last) {
|
||||
if (step === 0) {
|
||||
throw new Error("Step cannot be 0");
|
||||
}
|
||||
return delay(() => unfold((x) => step > 0 && x <= last || step < 0 && x >= last ? [x, x + step] : null, first));
|
||||
}
|
||||
export function rangeChar(first, last) {
|
||||
return delay(() => unfold((x) => x <= last ? [x, String.fromCharCode(x.charCodeAt(0) + 1)] : null, first));
|
||||
}
|
||||
export function range(first, last) {
|
||||
return rangeStep(first, 1, last);
|
||||
}
|
||||
export function readOnly(xs) {
|
||||
return map((x) => x, xs);
|
||||
}
|
||||
export function reduce(f, xs) {
|
||||
if (Array.isArray(xs) || ArrayBuffer.isView(xs)) {
|
||||
return xs.reduce(f);
|
||||
}
|
||||
const iter = xs[Symbol.iterator]();
|
||||
let cur = iter.next();
|
||||
if (cur.done) {
|
||||
throw new Error("Seq was empty");
|
||||
}
|
||||
let acc = cur.value;
|
||||
while (true) {
|
||||
cur = iter.next();
|
||||
if (cur.done) {
|
||||
break;
|
||||
}
|
||||
acc = f(acc, cur.value);
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
export function reduceBack(f, xs) {
|
||||
const ar = Array.isArray(xs) || ArrayBuffer.isView(xs) ? xs : Array.from(xs);
|
||||
if (ar.length === 0) {
|
||||
throw new Error("Seq was empty");
|
||||
}
|
||||
let acc = ar[ar.length - 1];
|
||||
for (let i = ar.length - 2; i >= 0; i--) {
|
||||
acc = f(ar[i], acc, i);
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
export function replicate(n, x) {
|
||||
return initialize(n, () => x);
|
||||
}
|
||||
export function reverse(xs) {
|
||||
const ar = Array.isArray(xs) || ArrayBuffer.isView(xs) ? xs.slice(0) : Array.from(xs);
|
||||
return ofArray(ar.reverse());
|
||||
}
|
||||
export function scan(f, seed, xs) {
|
||||
return delay(() => {
|
||||
const iter = xs[Symbol.iterator]();
|
||||
return unfold((acc) => {
|
||||
if (acc == null) {
|
||||
return [seed, seed];
|
||||
}
|
||||
const cur = iter.next();
|
||||
if (!cur.done) {
|
||||
acc = f(acc, cur.value);
|
||||
return [acc, acc];
|
||||
}
|
||||
return void 0;
|
||||
}, null);
|
||||
});
|
||||
}
|
||||
export function scanBack(f, xs, seed) {
|
||||
return reverse(scan((acc, x) => f(x, acc), seed, reverse(xs)));
|
||||
}
|
||||
export function singleton(y) {
|
||||
return unfold((x) => x != null ? [x, null] : null, y);
|
||||
}
|
||||
export function skip(n, xs) {
|
||||
return {
|
||||
[Symbol.iterator]: () => {
|
||||
const iter = xs[Symbol.iterator]();
|
||||
for (let i = 1; i <= n; i++) {
|
||||
if (iter.next().done) {
|
||||
throw new Error("Seq has not enough elements");
|
||||
}
|
||||
}
|
||||
return iter;
|
||||
},
|
||||
};
|
||||
}
|
||||
export function skipWhile(f, xs) {
|
||||
return delay(() => {
|
||||
let hasPassed = false;
|
||||
return filter((x) => hasPassed || (hasPassed = !f(x)), xs);
|
||||
});
|
||||
}
|
||||
export function sortWith(f, xs) {
|
||||
const ys = Array.from(xs);
|
||||
return ofArray(ys.sort(f));
|
||||
}
|
||||
export function sum(xs) {
|
||||
return fold((acc, x) => acc + x, 0, xs);
|
||||
}
|
||||
export function sumBy(f, xs) {
|
||||
return fold((acc, x) => acc + f(x), 0, xs);
|
||||
}
|
||||
export function tail(xs) {
|
||||
const iter = xs[Symbol.iterator]();
|
||||
const cur = iter.next();
|
||||
if (cur.done) {
|
||||
throw new Error("Seq was empty");
|
||||
}
|
||||
return {
|
||||
[Symbol.iterator]: () => iter,
|
||||
};
|
||||
}
|
||||
export function take(n, xs, truncate = false) {
|
||||
return delay(() => {
|
||||
const iter = xs[Symbol.iterator]();
|
||||
return unfold((i) => {
|
||||
if (i < n) {
|
||||
const cur = iter.next();
|
||||
if (!cur.done) {
|
||||
return [cur.value, i + 1];
|
||||
}
|
||||
if (!truncate) {
|
||||
throw new Error("Seq has not enough elements");
|
||||
}
|
||||
}
|
||||
return void 0;
|
||||
}, 0);
|
||||
});
|
||||
}
|
||||
export function truncate(n, xs) {
|
||||
return take(n, xs, true);
|
||||
}
|
||||
export function takeWhile(f, xs) {
|
||||
return delay(() => {
|
||||
const iter = xs[Symbol.iterator]();
|
||||
return unfold((i) => {
|
||||
const cur = iter.next();
|
||||
if (!cur.done && f(cur.value)) {
|
||||
return [cur.value, null];
|
||||
}
|
||||
return void 0;
|
||||
}, 0);
|
||||
});
|
||||
}
|
||||
export function tryFind(f, xs, defaultValue) {
|
||||
for (let i = 0, iter = xs[Symbol.iterator]();; i++) {
|
||||
const cur = iter.next();
|
||||
if (cur.done) {
|
||||
break;
|
||||
}
|
||||
if (f(cur.value, i)) {
|
||||
return makeSome(cur.value);
|
||||
}
|
||||
}
|
||||
return defaultValue === void 0 ? null : makeSome(defaultValue);
|
||||
}
|
||||
export function find(f, xs) {
|
||||
return __failIfNone(tryFind(f, xs));
|
||||
}
|
||||
export function tryFindBack(f, xs, defaultValue) {
|
||||
const arr = Array.isArray(xs) || ArrayBuffer.isView(xs) ? xs.slice(0) : Array.from(xs);
|
||||
return tryFind(f, arr.reverse(), defaultValue);
|
||||
}
|
||||
export function findBack(f, xs) {
|
||||
return __failIfNone(tryFindBack(f, xs));
|
||||
}
|
||||
export function tryFindIndex(f, xs) {
|
||||
for (let i = 0, iter = xs[Symbol.iterator]();; i++) {
|
||||
const cur = iter.next();
|
||||
if (cur.done) {
|
||||
break;
|
||||
}
|
||||
if (f(cur.value, i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
export function findIndex(f, xs) {
|
||||
return __failIfNone(tryFindIndex(f, xs));
|
||||
}
|
||||
export function tryFindIndexBack(f, xs) {
|
||||
const arr = Array.isArray(xs) || ArrayBuffer.isView(xs) ? xs.slice(0) : Array.from(xs);
|
||||
for (let i = arr.length - 1; i >= 0; i--) {
|
||||
if (f(arr[i], i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
export function findIndexBack(f, xs) {
|
||||
return __failIfNone(tryFindIndexBack(f, xs));
|
||||
}
|
||||
export function tryPick(f, xs) {
|
||||
for (let i = 0, iter = xs[Symbol.iterator]();; i++) {
|
||||
const cur = iter.next();
|
||||
if (cur.done) {
|
||||
break;
|
||||
}
|
||||
const y = f(cur.value, i);
|
||||
if (y != null) {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
export function pick(f, xs) {
|
||||
return __failIfNone(tryPick(f, xs));
|
||||
}
|
||||
export function unfold(f, fst) {
|
||||
return {
|
||||
[Symbol.iterator]: () => {
|
||||
// Capture a copy of the first value in the closure
|
||||
// so the sequence is restarted every time, see #1230
|
||||
let acc = fst;
|
||||
return {
|
||||
next: () => {
|
||||
const res = f(acc);
|
||||
if (res != null) {
|
||||
acc = res[1];
|
||||
return { done: false, value: res[0] };
|
||||
}
|
||||
return { done: true };
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
export function zip(xs, ys) {
|
||||
return map2((x, y) => [x, y], xs, ys);
|
||||
}
|
||||
export function zip3(xs, ys, zs) {
|
||||
return map3((x, y, z) => [x, y, z], xs, ys, zs);
|
||||
}
|
||||
@@ -1,433 +0,0 @@
|
||||
// tslint:disable:ban-types
|
||||
import { parse as dateParse, toString as dateToString } from "./Date";
|
||||
import { parse as dateOffsetParse } from "./DateOffset";
|
||||
import List from "./List";
|
||||
import { ofArray as listOfArray } from "./List";
|
||||
import { create as mapCreate } from "./Map";
|
||||
import FableMap from "./Map";
|
||||
import { Some } from "./Option";
|
||||
import { getTypeFullName, resolveGeneric } from "./Reflection";
|
||||
import { fold } from "./Seq";
|
||||
import FableSet from "./Set";
|
||||
import { create as setCreate } from "./Set";
|
||||
import { printf, toText } from "./String";
|
||||
import { getType } from "./Symbol";
|
||||
import FableSymbol from "./Symbol";
|
||||
import { getDefinition, NonDeclaredType } from "./Util";
|
||||
function isDate(v) {
|
||||
return v instanceof Date;
|
||||
}
|
||||
function deflateDate(v) {
|
||||
return dateToString(v, "O");
|
||||
}
|
||||
function deflateValue(v) {
|
||||
if (isDate(v)) {
|
||||
return deflateDate(v);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
export function deflate(v) {
|
||||
if (Array.isArray(v)) {
|
||||
return v.map(deflateValue);
|
||||
}
|
||||
else if (ArrayBuffer.isView(v)) {
|
||||
return Array.from(v).map(deflateValue);
|
||||
}
|
||||
else if (isDate(v)) {
|
||||
return deflateDate(v);
|
||||
}
|
||||
else if (v != null && typeof v === "object") {
|
||||
if (v instanceof List || v instanceof FableSet || v instanceof Set) {
|
||||
return Array.from(v).map(deflateValue);
|
||||
}
|
||||
else if (v instanceof FableMap || v instanceof Map) {
|
||||
let stringKeys = null;
|
||||
return fold((o, kv) => {
|
||||
if (stringKeys === null) {
|
||||
stringKeys = typeof kv[0] === "string";
|
||||
}
|
||||
o[stringKeys ? kv[0] : toJson(kv[0])] = deflateValue(kv[1]);
|
||||
return o;
|
||||
}, {}, v);
|
||||
}
|
||||
else if (v instanceof Some) {
|
||||
return deflateValue(v.value);
|
||||
}
|
||||
const reflectionInfo = typeof v[FableSymbol.reflection] === "function" ? v[FableSymbol.reflection]() : {};
|
||||
if (reflectionInfo.properties) {
|
||||
return fold((o, prop) => {
|
||||
return o[prop] = deflateValue(v[prop]), o;
|
||||
}, {}, Object.getOwnPropertyNames(reflectionInfo.properties));
|
||||
}
|
||||
else if (reflectionInfo.cases) {
|
||||
const caseInfo = reflectionInfo.cases[v.tag];
|
||||
const caseName = caseInfo[0];
|
||||
const fieldsLength = caseInfo.length - 1;
|
||||
if (fieldsLength === 0) {
|
||||
return caseName;
|
||||
}
|
||||
else {
|
||||
// Prevent undefined assignment from removing case property; see #611:
|
||||
return { [caseName]: (v.data !== void 0 ? deflate(v.data) : null) };
|
||||
}
|
||||
}
|
||||
else {
|
||||
return fold((o, prop) => {
|
||||
return o[prop] = deflateValue(v[prop]), o;
|
||||
}, {}, Object.getOwnPropertyNames(v));
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
export function toJson(o) {
|
||||
return JSON.stringify(deflateValue(o), (k, v) => deflate(v));
|
||||
}
|
||||
function combine(path1, path2) {
|
||||
return typeof path2 === "number"
|
||||
? path1 + "[" + path2 + "]"
|
||||
: (path1 ? path1 + "." : "") + path2;
|
||||
}
|
||||
function isNullable(typ) {
|
||||
if (typeof typ === "string") {
|
||||
return typ !== "boolean" && typ !== "number";
|
||||
}
|
||||
else if (typ instanceof NonDeclaredType) {
|
||||
return typ.kind !== "Array" && typ.kind !== "Tuple";
|
||||
}
|
||||
else {
|
||||
const info = typeof typ.prototype[FableSymbol.reflection] === "function"
|
||||
? typ.prototype[FableSymbol.reflection]() : null;
|
||||
return info ? info.nullable : true;
|
||||
}
|
||||
}
|
||||
function invalidate(val, typ, path) {
|
||||
const str = toText(printf("%A"))(val);
|
||||
throw new Error(`${str} ${path ? "(" + path + ")" : ""} is not of type ${getTypeFullName(typ)}`);
|
||||
}
|
||||
function needsInflate(enclosing) {
|
||||
const typ = enclosing.head;
|
||||
if (typeof typ === "string") {
|
||||
return false;
|
||||
}
|
||||
if (typ instanceof NonDeclaredType) {
|
||||
switch (typ.kind) {
|
||||
case "Option":
|
||||
case "Array":
|
||||
return typ.definition != null || needsInflate(new List(typ.generics[0], enclosing));
|
||||
case "Tuple":
|
||||
return typ.generics.some((x) => needsInflate(new List(x, enclosing)));
|
||||
case "Function":
|
||||
return false;
|
||||
case "GenericParam":
|
||||
return needsInflate(resolveGeneric(typ.definition, enclosing.tail));
|
||||
case "GenericType":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function inflateArray(arr, enclosing, path) {
|
||||
if (!Array.isArray) {
|
||||
invalidate(arr, "array", path);
|
||||
}
|
||||
// TODO: Validate non-inflated elements
|
||||
return needsInflate(enclosing)
|
||||
? arr.map((x, i) => inflate(x, enclosing, combine(path, i)))
|
||||
: arr;
|
||||
}
|
||||
function inflateMap(obj, keyEnclosing, valEnclosing, path) {
|
||||
const inflateKey = keyEnclosing.head !== "string";
|
||||
const inflateVal = needsInflate(valEnclosing);
|
||||
return Object
|
||||
.getOwnPropertyNames(obj)
|
||||
.map((k) => {
|
||||
const key = inflateKey ? inflate(JSON.parse(k), keyEnclosing, combine(path, k)) : k;
|
||||
const val = inflateVal ? inflate(obj[k], valEnclosing, combine(path, k)) : obj[k];
|
||||
return [key, val];
|
||||
});
|
||||
}
|
||||
function inflateList(val, enclosing, path) {
|
||||
const ar = [];
|
||||
let li = new List();
|
||||
let cur = val;
|
||||
const inf = needsInflate(enclosing);
|
||||
while (cur.tail != null) {
|
||||
ar.push(inf ? inflate(cur.head, enclosing, path) : cur.head);
|
||||
cur = cur.tail;
|
||||
}
|
||||
ar.reverse();
|
||||
for (const a of ar) {
|
||||
li = new List(a, li);
|
||||
}
|
||||
return li;
|
||||
}
|
||||
function inflateUnion(val, typ, info, path, inflateField) {
|
||||
let caseName;
|
||||
// Same shape as runtime DUs, for example, if they've been serialized with `JSON.stringify`
|
||||
if (typeof val.tag === "number") {
|
||||
return Object.assign(new typ(), val);
|
||||
}
|
||||
else if (typeof val === "string") {
|
||||
// Cases without fields are serialized as strings by `toJson`
|
||||
caseName = val;
|
||||
}
|
||||
else {
|
||||
// Non-empty cases are serialized as `{ "MyCase": [1, 2] }` by `toJson`
|
||||
caseName = Object.getOwnPropertyNames(val)[0];
|
||||
}
|
||||
// Locate case index
|
||||
let tag = -1;
|
||||
for (let i = 0; info.cases[i] != null; i++) {
|
||||
if (info.cases[i][0] === caseName) {
|
||||
tag = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Validate
|
||||
if (tag === -1) {
|
||||
invalidate(val, typ, path);
|
||||
}
|
||||
const caseInfo = info.cases[tag];
|
||||
let inflatedData = void 0;
|
||||
if (caseInfo.length > 2) {
|
||||
inflatedData = [];
|
||||
const data = val[caseName];
|
||||
path = combine(path, caseName);
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
inflatedData.push(inflateField
|
||||
? inflateField(data[i], caseInfo[i + 1], combine(path, i))
|
||||
: data[i]);
|
||||
}
|
||||
}
|
||||
else if (caseInfo.length > 1) {
|
||||
inflatedData = inflateField
|
||||
? inflateField(val[caseName], caseInfo[1], combine(path, caseName))
|
||||
: val[caseName];
|
||||
}
|
||||
return new typ(tag, inflatedData);
|
||||
}
|
||||
function inflate(val, typ, path) {
|
||||
let enclosing = null;
|
||||
if (typ instanceof List) {
|
||||
enclosing = typ;
|
||||
typ = typ.head;
|
||||
}
|
||||
else {
|
||||
enclosing = new List(typ, new List());
|
||||
}
|
||||
if (val == null) {
|
||||
if (!isNullable(typ)) {
|
||||
invalidate(val, typ, path);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
else if (typeof typ === "string") {
|
||||
if ((typ === "boolean" || typ === "number" || typ === "string") && (typeof val !== typ)) {
|
||||
invalidate(val, typ, path);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
else if (typ instanceof NonDeclaredType) {
|
||||
switch (typ.kind) {
|
||||
case "Unit":
|
||||
return null;
|
||||
case "Option":
|
||||
return inflate(val, new List(typ.generics[0], enclosing), path);
|
||||
case "Array":
|
||||
if (typ.definition != null) {
|
||||
return new typ.definition(val);
|
||||
}
|
||||
else {
|
||||
return inflateArray(val, new List(typ.generics[0], enclosing), path);
|
||||
}
|
||||
case "Tuple":
|
||||
return typ.generics.map((x, i) => inflate(val[i], new List(x, enclosing), combine(path, i)));
|
||||
case "Function":
|
||||
return val;
|
||||
case "GenericParam":
|
||||
return inflate(val, resolveGeneric(typ.definition, enclosing.tail), path);
|
||||
case "GenericType":
|
||||
const def = typ.definition;
|
||||
if (def === List) {
|
||||
return Array.isArray(val)
|
||||
? listOfArray(inflateArray(val, resolveGeneric(0, enclosing), path))
|
||||
: inflateList(val, resolveGeneric(0, enclosing), path);
|
||||
}
|
||||
// TODO: Should we try to inflate also sets and maps serialized with `JSON.stringify`?
|
||||
if (def === FableSet) {
|
||||
return setCreate(inflateArray(val, resolveGeneric(0, enclosing), path));
|
||||
}
|
||||
if (def === Set) {
|
||||
return new Set(inflateArray(val, resolveGeneric(0, enclosing), path));
|
||||
}
|
||||
if (def === FableMap) {
|
||||
return mapCreate(inflateMap(val, resolveGeneric(0, enclosing), resolveGeneric(1, enclosing), path));
|
||||
}
|
||||
if (def === Map) {
|
||||
return new Map(inflateMap(val, resolveGeneric(0, enclosing), resolveGeneric(1, enclosing), path));
|
||||
}
|
||||
return inflate(val, new List(typ.definition, enclosing), path);
|
||||
case "Interface":
|
||||
return typ.definition === "System.DateTimeOffset"
|
||||
? dateOffsetParse(val) : val;
|
||||
default:// case "Interface": // case "Any":
|
||||
return val;
|
||||
}
|
||||
}
|
||||
else if (typeof typ === "function") {
|
||||
if (typ === Date) {
|
||||
return dateParse(val, true);
|
||||
}
|
||||
if (typeof typ.ofJSON === "function") {
|
||||
return typ.ofJSON(val);
|
||||
}
|
||||
const info = typeof typ.prototype[FableSymbol.reflection] === "function" ?
|
||||
typ.prototype[FableSymbol.reflection]() : {};
|
||||
// Union types
|
||||
if (info.cases) {
|
||||
return inflateUnion(val, typ, info, path, (fi, t, p) => inflate(fi, new List(t, enclosing), path));
|
||||
}
|
||||
if (info.properties) {
|
||||
const newObj = new typ();
|
||||
const properties = info.properties;
|
||||
const ks = Object.getOwnPropertyNames(properties);
|
||||
for (const k of ks) {
|
||||
newObj[k] = inflate(val[k], new List(properties[k], enclosing), combine(path, k));
|
||||
}
|
||||
return newObj;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
throw new Error("Unexpected type when deserializing JSON: " + typ);
|
||||
}
|
||||
function inflatePublic(val, genArgs) {
|
||||
return inflate(val, genArgs ? genArgs.T : null, "");
|
||||
}
|
||||
export { inflatePublic as inflate };
|
||||
export function ofJson(json, genArgs) {
|
||||
function raise(msg, err, json, targetType) {
|
||||
let fullMsg = "Cannot deserialize";
|
||||
if (targetType != null) {
|
||||
fullMsg += " into " + getTypeFullName(targetType);
|
||||
}
|
||||
fullMsg += " - Error (" + msg + "): " + err.message + " - Data: '" + json + "'";
|
||||
throw new Error(fullMsg);
|
||||
}
|
||||
let value = null;
|
||||
const targetType = genArgs ? genArgs.T : null;
|
||||
try {
|
||||
value = JSON.parse(json);
|
||||
}
|
||||
catch (e) {
|
||||
raise("JSON.parse", e, json, targetType);
|
||||
}
|
||||
try {
|
||||
value = inflate(value, targetType, "");
|
||||
}
|
||||
catch (e) {
|
||||
raise("inflate", e, json, targetType);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
// TODO: Dates and types with `toJSON` are not adding the $type field
|
||||
export function toJsonWithTypeInfo(val) {
|
||||
return JSON.stringify(val, (k, v) => {
|
||||
if (ArrayBuffer.isView(v)) {
|
||||
return Array.from(v);
|
||||
}
|
||||
else if (v != null && typeof v === "object") {
|
||||
const info = typeof v[FableSymbol.reflection] === "function" ? v[FableSymbol.reflection]() : {};
|
||||
if (v instanceof List || v instanceof FableSet || v instanceof Set) {
|
||||
return {
|
||||
$type: info.type || "System.Collections.Generic.HashSet",
|
||||
$values: Array.from(v),
|
||||
};
|
||||
}
|
||||
else if (v instanceof FableMap || v instanceof Map) {
|
||||
return fold((o, kv) => { o[kv[0]] = kv[1]; return o; }, { $type: info.type || "System.Collections.Generic.Dictionary" }, v);
|
||||
}
|
||||
else if (info.properties) {
|
||||
return fold((o, prop) => {
|
||||
return o[prop] = v[prop], o;
|
||||
}, { $type: info.type }, Object.getOwnPropertyNames(info.properties));
|
||||
}
|
||||
else if (info.cases) {
|
||||
const uci = info.cases[v.tag];
|
||||
return {
|
||||
// Prevent undefined assignment from removing case property; see #611:
|
||||
[uci[0]]: (v.data !== void 0 ? v.data : null),
|
||||
$type: info.type,
|
||||
};
|
||||
}
|
||||
}
|
||||
return v;
|
||||
});
|
||||
}
|
||||
export function ofJsonWithTypeInfo(json, genArgs) {
|
||||
const parsed = JSON.parse(json, (key, v) => {
|
||||
if (v == null) {
|
||||
return v;
|
||||
}
|
||||
else if (typeof v === "object" && typeof v.$type === "string") {
|
||||
// Remove generic args and assembly info added by Newtonsoft.Json
|
||||
let type = v.$type.replace("+", ".");
|
||||
let i = type.indexOf("`");
|
||||
delete v.$type;
|
||||
if (i > -1) {
|
||||
type = type.substr(0, i);
|
||||
}
|
||||
else {
|
||||
i = type.indexOf(",");
|
||||
type = i > -1 ? type.substr(0, i) : type;
|
||||
}
|
||||
if (type === "System.Collections.Generic.List" || (type.indexOf("[]") === type.length - 2)) {
|
||||
return v.$values;
|
||||
}
|
||||
if (type === "Microsoft.FSharp.Collections.FSharpList") {
|
||||
return listOfArray(v.$values);
|
||||
}
|
||||
else if (type === "Microsoft.FSharp.Collections.FSharpSet") {
|
||||
return setCreate(v.$values);
|
||||
}
|
||||
else if (type === "System.Collections.Generic.HashSet") {
|
||||
return new Set(v.$values);
|
||||
}
|
||||
else if (type === "Microsoft.FSharp.Collections.FSharpMap") {
|
||||
return mapCreate(Object.getOwnPropertyNames(v)
|
||||
.map((k) => [k, v[k]]));
|
||||
}
|
||||
else if (type === "System.Collections.Generic.Dictionary") {
|
||||
return new Map(Object.getOwnPropertyNames(v)
|
||||
.map((k) => [k, v[k]]));
|
||||
}
|
||||
else {
|
||||
const typ = getType(type);
|
||||
if (typ) {
|
||||
if (typeof typ.ofJSON === "function") {
|
||||
return typ.ofJSON(v);
|
||||
}
|
||||
const info = typeof typ.prototype[FableSymbol.reflection] === "function" ?
|
||||
typ.prototype[FableSymbol.reflection]() : {};
|
||||
if (info.cases) {
|
||||
return inflateUnion(v, typ, info, key);
|
||||
}
|
||||
return Object.assign(new typ(), v);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[+-]\d{2}:\d{2}|Z)$/.test(v)) {
|
||||
return dateParse(v, true);
|
||||
}
|
||||
else {
|
||||
return v;
|
||||
}
|
||||
});
|
||||
const expected = genArgs ? genArgs.T : null;
|
||||
if (parsed != null && typeof expected === "function"
|
||||
&& !(parsed instanceof getDefinition(expected))) {
|
||||
throw new Error("JSON is not of type " + expected.name + ": " + json);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
-866
@@ -1,866 +0,0 @@
|
||||
// tslint:disable:max-line-length
|
||||
import Comparer from "./Comparer";
|
||||
import List from "./List";
|
||||
import { ofArray as listOfArray } from "./List";
|
||||
import { exists as seqExists } from "./Seq";
|
||||
import { forAll as seqForAll } from "./Seq";
|
||||
import { reduce as seqReduce } from "./Seq";
|
||||
import { scan as seqScan } from "./Seq";
|
||||
import { choose as seqChoose } from "./Seq";
|
||||
import { iterate as seqIterate } from "./Seq";
|
||||
import { fold as seqFold } from "./Seq";
|
||||
import FSymbol from "./Symbol";
|
||||
import { toString } from "./Util";
|
||||
// ----------------------------------------------
|
||||
// These functions belong to Seq.ts but are
|
||||
// implemented here to prevent cyclic dependencies
|
||||
export function distinctBy(f, xs) {
|
||||
return seqChoose((tup) => tup[0], seqScan((tup, x) => {
|
||||
const acc = tup[1];
|
||||
const k = f(x);
|
||||
return acc.has(k) ? [null, acc] : [x, add(k, acc)];
|
||||
}, [null, create()], xs));
|
||||
}
|
||||
export function distinct(xs) {
|
||||
return distinctBy((x) => x, xs);
|
||||
}
|
||||
export class SetTree {
|
||||
constructor(tag, data) {
|
||||
this.tag = tag | 0;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
const tree_tolerance = 2;
|
||||
function tree_countAux(s, acc) {
|
||||
countAux: while (true) {
|
||||
if (s.tag === 1) {
|
||||
return acc + 1 | 0;
|
||||
}
|
||||
else if (s.tag === 0) {
|
||||
return acc | 0;
|
||||
}
|
||||
else {
|
||||
const _var5 = s.data[1];
|
||||
acc = tree_countAux(s.data[2], acc + 1);
|
||||
s = _var5;
|
||||
continue countAux;
|
||||
}
|
||||
}
|
||||
}
|
||||
function tree_count(s) {
|
||||
return tree_countAux(s, 0);
|
||||
}
|
||||
function tree_SetOne(n) {
|
||||
return new SetTree(1, [n]);
|
||||
}
|
||||
function tree_SetNode(x, l, r, h) {
|
||||
return new SetTree(2, [x, l, r, h]);
|
||||
}
|
||||
function tree_height(t) {
|
||||
return t.tag === 1 ? 1 : t.tag === 2 ? t.data[3] : 0;
|
||||
}
|
||||
function tree_mk(l, k, r) {
|
||||
const matchValue = l.tag === 0 ? r.tag === 0 ? 0 : 1 : 1;
|
||||
switch (matchValue) {
|
||||
case 0:
|
||||
return tree_SetOne(k);
|
||||
case 1:
|
||||
const hl = tree_height(l) | 0;
|
||||
const hr = tree_height(r) | 0;
|
||||
const m = (hl < hr ? hr : hl) | 0;
|
||||
return tree_SetNode(k, l, r, m + 1);
|
||||
}
|
||||
throw new Error("internal error: Set.tree_mk");
|
||||
}
|
||||
function tree_rebalance(t1, k, t2) {
|
||||
const t1h = tree_height(t1);
|
||||
const t2h = tree_height(t2);
|
||||
if (t2h > t1h + tree_tolerance) {
|
||||
if (t2.tag === 2) {
|
||||
if (tree_height(t2.data[1]) > t1h + 1) {
|
||||
if (t2.data[1].tag === 2) {
|
||||
return tree_mk(tree_mk(t1, k, t2.data[1].data[1]), t2.data[1].data[0], tree_mk(t2.data[1].data[2], t2.data[0], t2.data[2]));
|
||||
}
|
||||
else {
|
||||
throw new Error("rebalance");
|
||||
}
|
||||
}
|
||||
else {
|
||||
return tree_mk(tree_mk(t1, k, t2.data[1]), t2.data[0], t2.data[2]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("rebalance");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (t1h > t2h + tree_tolerance) {
|
||||
if (t1.tag === 2) {
|
||||
if (tree_height(t1.data[2]) > t2h + 1) {
|
||||
if (t1.data[2].tag === 2) {
|
||||
return tree_mk(tree_mk(t1.data[1], t1.data[0], t1.data[2].data[1]), t1.data[2].data[0], tree_mk(t1.data[2].data[2], k, t2));
|
||||
}
|
||||
else {
|
||||
throw new Error("rebalance");
|
||||
}
|
||||
}
|
||||
else {
|
||||
return tree_mk(t1.data[1], t1.data[0], tree_mk(t1.data[2], k, t2));
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("rebalance");
|
||||
}
|
||||
}
|
||||
else {
|
||||
return tree_mk(t1, k, t2);
|
||||
}
|
||||
}
|
||||
}
|
||||
function tree_add(comparer, k, t) {
|
||||
if (t.tag === 1) {
|
||||
const c = comparer.Compare(k, t.data[0]);
|
||||
if (c < 0) {
|
||||
return tree_SetNode(k, new SetTree(0), t, 2);
|
||||
}
|
||||
else if (c === 0) {
|
||||
return t;
|
||||
}
|
||||
else {
|
||||
return tree_SetNode(k, t, new SetTree(0), 2);
|
||||
}
|
||||
}
|
||||
else if (t.tag === 0) {
|
||||
return tree_SetOne(k);
|
||||
}
|
||||
else {
|
||||
const c = comparer.Compare(k, t.data[0]);
|
||||
if (c < 0) {
|
||||
return tree_rebalance(tree_add(comparer, k, t.data[1]), t.data[0], t.data[2]);
|
||||
}
|
||||
else if (c === 0) {
|
||||
return t;
|
||||
}
|
||||
else {
|
||||
return tree_rebalance(t.data[1], t.data[0], tree_add(comparer, k, t.data[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
function tree_balance(comparer, t1, k, t2) {
|
||||
const matchValue = t1.tag === 1 ? t2.tag === 0 ? [1, t1] : t2.tag === 1 ? [2, t1.data[0], t2] : [2, t1.data[0], t2] : t1.tag === 2 ? t2.tag === 1 ? [3, t2.data[0], t1] : t2.tag === 2 ? [4, t1.data[3], t2.data[3], t1.data[0], t2.data[0], t1.data[1], t1.data[2], t2.data[1], t2.data[2]] : [1, t1] : [0, t2];
|
||||
switch (matchValue[0]) {
|
||||
case 0:
|
||||
return tree_add(comparer, k, matchValue[1]);
|
||||
case 1:
|
||||
return tree_add(comparer, k, matchValue[1]);
|
||||
case 2:
|
||||
return tree_add(comparer, k, tree_add(comparer, matchValue[1], matchValue[2]));
|
||||
case 3:
|
||||
return tree_add(comparer, k, tree_add(comparer, matchValue[1], matchValue[2]));
|
||||
case 4:
|
||||
if (matchValue[1] + tree_tolerance < matchValue[2]) {
|
||||
return tree_rebalance(tree_balance(comparer, t1, k, matchValue[7]), matchValue[4], matchValue[8]);
|
||||
}
|
||||
else if (matchValue[2] + tree_tolerance < matchValue[1]) {
|
||||
return tree_rebalance(matchValue[5], matchValue[3], tree_balance(comparer, matchValue[6], k, t2));
|
||||
}
|
||||
else {
|
||||
return tree_mk(t1, k, t2);
|
||||
}
|
||||
}
|
||||
throw new Error("internal error: Set.tree_balance");
|
||||
}
|
||||
function tree_split(comparer, pivot, t) {
|
||||
if (t.tag === 1) {
|
||||
const c = comparer.Compare(t.data[0], pivot);
|
||||
if (c < 0) {
|
||||
return [t, false, new SetTree(0)];
|
||||
}
|
||||
else if (c === 0) {
|
||||
return [new SetTree(0), true, new SetTree(0)];
|
||||
}
|
||||
else {
|
||||
return [new SetTree(0), false, t];
|
||||
}
|
||||
}
|
||||
else if (t.tag === 0) {
|
||||
return [new SetTree(0), false, new SetTree(0)];
|
||||
}
|
||||
else {
|
||||
const c = comparer.Compare(pivot, t.data[0]);
|
||||
if (c < 0) {
|
||||
const patternInput = tree_split(comparer, pivot, t.data[1]);
|
||||
return [patternInput[0], patternInput[1], tree_balance(comparer, patternInput[2], t.data[0], t.data[2])];
|
||||
}
|
||||
else if (c === 0) {
|
||||
return [t.data[1], true, t.data[2]];
|
||||
}
|
||||
else {
|
||||
const patternInput = tree_split(comparer, pivot, t.data[2]);
|
||||
return [tree_balance(comparer, t.data[1], t.data[0], patternInput[0]), patternInput[1], patternInput[2]];
|
||||
}
|
||||
}
|
||||
}
|
||||
function tree_spliceOutSuccessor(t) {
|
||||
if (t.tag === 1) {
|
||||
return [t.data[0], new SetTree(0)];
|
||||
}
|
||||
else if (t.tag === 2) {
|
||||
if (t.data[1].tag === 0) {
|
||||
return [t.data[0], t.data[2]];
|
||||
}
|
||||
else {
|
||||
const patternInput = tree_spliceOutSuccessor(t.data[1]);
|
||||
return [patternInput[0], tree_mk(patternInput[1], t.data[0], t.data[2])];
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("internal error: Map.spliceOutSuccessor");
|
||||
}
|
||||
}
|
||||
function tree_remove(comparer, k, t) {
|
||||
if (t.tag === 1) {
|
||||
const c = comparer.Compare(k, t.data[0]);
|
||||
if (c === 0) {
|
||||
return new SetTree(0);
|
||||
}
|
||||
else {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
else if (t.tag === 2) {
|
||||
const c = comparer.Compare(k, t.data[0]);
|
||||
if (c < 0) {
|
||||
return tree_rebalance(tree_remove(comparer, k, t.data[1]), t.data[0], t.data[2]);
|
||||
}
|
||||
else if (c === 0) {
|
||||
const matchValue = [t.data[1], t.data[2]];
|
||||
if (matchValue[0].tag === 0) {
|
||||
return t.data[2];
|
||||
}
|
||||
else if (matchValue[1].tag === 0) {
|
||||
return t.data[1];
|
||||
}
|
||||
else {
|
||||
const patternInput = tree_spliceOutSuccessor(t.data[2]);
|
||||
return tree_mk(t.data[1], patternInput[0], patternInput[1]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return tree_rebalance(t.data[1], t.data[0], tree_remove(comparer, k, t.data[2]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
function tree_mem(comparer, k, t) {
|
||||
mem: while (true) {
|
||||
if (t.tag === 1) {
|
||||
return comparer.Compare(k, t.data[0]) === 0;
|
||||
}
|
||||
else if (t.tag === 0) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
const c = comparer.Compare(k, t.data[0]) | 0;
|
||||
if (c < 0) {
|
||||
comparer = comparer;
|
||||
k = k;
|
||||
t = t.data[1];
|
||||
continue mem;
|
||||
}
|
||||
else if (c === 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
comparer = comparer;
|
||||
k = k;
|
||||
t = t.data[2];
|
||||
continue mem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function tree_iter(f, t) {
|
||||
if (t.tag === 1) {
|
||||
f(t.data[0]);
|
||||
}
|
||||
else if (t.tag !== 0) {
|
||||
tree_iter(f, t.data[1]);
|
||||
f(t.data[0]);
|
||||
tree_iter(f, t.data[2]);
|
||||
}
|
||||
}
|
||||
function tree_foldBack(f, m, x) {
|
||||
return m.tag === 1 ? f(m.data[0], x) : m.tag === 0 ?
|
||||
x : tree_foldBack(f, m.data[1], f(m.data[0], tree_foldBack(f, m.data[2], x)));
|
||||
}
|
||||
function tree_fold(f, x, m) {
|
||||
if (m.tag === 1) {
|
||||
return f(x, m.data[0]);
|
||||
}
|
||||
else if (m.tag === 0) {
|
||||
return x;
|
||||
}
|
||||
else {
|
||||
const x_1 = tree_fold(f, x, m.data[1]);
|
||||
const x_2 = f(x_1, m.data[0]);
|
||||
return tree_fold(f, x_2, m.data[2]);
|
||||
}
|
||||
}
|
||||
function tree_forall(f, m) {
|
||||
return m.tag === 1 ? f(m.data[0]) : m.tag === 0 ? true : (f(m.data[0]) ?
|
||||
tree_forall(f, m.data[1]) : false) ? tree_forall(f, m.data[2]) : false;
|
||||
}
|
||||
function tree_exists(f, m) {
|
||||
return m.tag === 1 ? f(m.data[0]) : m.tag === 0 ? false : (f(m.data[0]) ?
|
||||
true : tree_exists(f, m.data[1])) ? true : tree_exists(f, m.data[2]);
|
||||
}
|
||||
function tree_isEmpty(m) {
|
||||
return m.tag === 0 ? true : false;
|
||||
}
|
||||
function tree_subset(comparer, a, b) {
|
||||
return tree_forall((x) => tree_mem(comparer, x, b), a);
|
||||
}
|
||||
function tree_psubset(comparer, a, b) {
|
||||
return tree_forall((x) => tree_mem(comparer, x, b), a) ? tree_exists((x) => !tree_mem(comparer, x, a), b) : false;
|
||||
}
|
||||
function tree_filterAux(comparer, f, s, acc) {
|
||||
if (s.tag === 1) {
|
||||
if (f(s.data[0])) {
|
||||
return tree_add(comparer, s.data[0], acc);
|
||||
}
|
||||
else {
|
||||
return acc;
|
||||
}
|
||||
}
|
||||
else if (s.tag === 0) {
|
||||
return acc;
|
||||
}
|
||||
else {
|
||||
const acc_1 = f(s.data[0]) ? tree_add(comparer, s.data[0], acc) : acc;
|
||||
return tree_filterAux(comparer, f, s.data[1], tree_filterAux(comparer, f, s.data[2], acc_1));
|
||||
}
|
||||
}
|
||||
function tree_filter(comparer, f, s) {
|
||||
return tree_filterAux(comparer, f, s, new SetTree(0));
|
||||
}
|
||||
function tree_diffAux(comparer, m, acc) {
|
||||
diffAux: while (true) {
|
||||
if (m.tag === 1) {
|
||||
return tree_remove(comparer, m.data[0], acc);
|
||||
}
|
||||
else if (m.tag === 0) {
|
||||
return acc;
|
||||
}
|
||||
else {
|
||||
const _var6 = comparer;
|
||||
const _var7 = m.data[1];
|
||||
acc = tree_diffAux(comparer, m.data[2], tree_remove(comparer, m.data[0], acc));
|
||||
comparer = _var6;
|
||||
m = _var7;
|
||||
continue diffAux;
|
||||
}
|
||||
}
|
||||
}
|
||||
function tree_diff(comparer, a, b) {
|
||||
return tree_diffAux(comparer, b, a);
|
||||
}
|
||||
function tree_union(comparer, t1, t2) {
|
||||
const matchValue = t1.tag === 0 ? [1, t2] : t1.tag === 1 ? t2.tag === 0 ? [2, t1] : t2.tag === 1 ? [3, t1.data[0], t2] : [3, t1.data[0], t2] : t2.tag === 0 ? [2, t1] : t2.tag === 1 ? [4, t2.data[0], t1] : [0, t1.data[3], t2.data[3], t1.data[0], t2.data[0], t1.data[1], t1.data[2], t2.data[1], t2.data[2]];
|
||||
switch (matchValue[0]) {
|
||||
case 0:
|
||||
if (matchValue[1] > matchValue[2]) {
|
||||
const patternInput = tree_split(comparer, matchValue[3], t2);
|
||||
return tree_balance(comparer, tree_union(comparer, matchValue[5], patternInput[0]), matchValue[3], tree_union(comparer, matchValue[6], patternInput[2]));
|
||||
}
|
||||
else {
|
||||
const patternInput_1 = tree_split(comparer, matchValue[4], t1);
|
||||
return tree_balance(comparer, tree_union(comparer, matchValue[7], patternInput_1[0]), matchValue[4], tree_union(comparer, matchValue[8], patternInput_1[2]));
|
||||
}
|
||||
case 1:
|
||||
return matchValue[1];
|
||||
case 2:
|
||||
return matchValue[1];
|
||||
case 3:
|
||||
return tree_add(comparer, matchValue[1], matchValue[2]);
|
||||
case 4:
|
||||
return tree_add(comparer, matchValue[1], matchValue[2]);
|
||||
}
|
||||
throw new Error("internal error: Set.tree_union");
|
||||
}
|
||||
function tree_intersectionAux(comparer, b, m, acc) {
|
||||
intersectionAux: while (true) {
|
||||
if (m.tag === 1) {
|
||||
if (tree_mem(comparer, m.data[0], b)) {
|
||||
return tree_add(comparer, m.data[0], acc);
|
||||
}
|
||||
else {
|
||||
return acc;
|
||||
}
|
||||
}
|
||||
else if (m.tag === 0) {
|
||||
return acc;
|
||||
}
|
||||
else {
|
||||
const acc_1 = tree_intersectionAux(comparer, b, m.data[2], acc);
|
||||
const acc_2 = tree_mem(comparer, m.data[0], b) ? tree_add(comparer, m.data[0], acc_1) : acc_1;
|
||||
comparer = comparer;
|
||||
b = b;
|
||||
m = m.data[1];
|
||||
acc = acc_2;
|
||||
continue intersectionAux;
|
||||
}
|
||||
}
|
||||
}
|
||||
function tree_intersection(comparer, a, b) {
|
||||
return tree_intersectionAux(comparer, b, a, new SetTree(0));
|
||||
}
|
||||
function tree_partition1(comparer, f, k, acc1, acc2) {
|
||||
return f(k) ? [tree_add(comparer, k, acc1), acc2] : [acc1, tree_add(comparer, k, acc2)];
|
||||
}
|
||||
function tree_partitionAux(comparer, f, s, acc_0, acc_1) {
|
||||
const acc = [acc_0, acc_1];
|
||||
if (s.tag === 1) {
|
||||
return tree_partition1(comparer, f, s.data[0], acc[0], acc[1]);
|
||||
}
|
||||
else if (s.tag === 0) {
|
||||
return acc;
|
||||
}
|
||||
else {
|
||||
const acc_2 = tree_partitionAux(comparer, f, s.data[2], acc[0], acc[1]);
|
||||
const acc_3 = tree_partition1(comparer, f, s.data[0], acc_2[0], acc_2[1]);
|
||||
return tree_partitionAux(comparer, f, s.data[1], acc_3[0], acc_3[1]);
|
||||
}
|
||||
}
|
||||
function tree_partition(comparer, f, s) {
|
||||
return tree_partitionAux(comparer, f, s, new SetTree(0), new SetTree(0));
|
||||
}
|
||||
// function tree_$MatchSetNode$MatchSetEmpty$(s: SetTree) {
|
||||
// return s.tag === 1 ? new Choice("Choice1Of2", [[s.data[0], new SetTree(0), new SetTree(0)]]) : s.tag === 0 ? new Choice("Choice2Of2", [null]) : new Choice("Choice1Of2", [[s.data[0], s.data[1], s.data[2]]]);
|
||||
// }
|
||||
function tree_minimumElementAux(s, n) {
|
||||
return s.tag === 1 ? s.data[0] : s.tag === 0 ? n : tree_minimumElementAux(s.data[1], s.data[0]);
|
||||
}
|
||||
function tree_minimumElementOpt(s) {
|
||||
return s.tag === 1 ? s.data[0] : s.tag === 0 ? null : tree_minimumElementAux(s.data[1], s.data[0]);
|
||||
}
|
||||
function tree_maximumElementAux(s, n) {
|
||||
return s.tag === 1 ? s.data[0] : s.tag === 0 ? n : tree_maximumElementAux(s.data[2], s.data[0]);
|
||||
}
|
||||
function tree_maximumElementOpt(s) {
|
||||
return s.tag === 1 ? s.data[0] : s.tag === 0 ? null : tree_maximumElementAux(s.data[2], s.data[0]);
|
||||
}
|
||||
function tree_minimumElement(s) {
|
||||
const matchValue = tree_minimumElementOpt(s);
|
||||
if (matchValue == null) {
|
||||
throw new Error("Set contains no elements");
|
||||
}
|
||||
else {
|
||||
return matchValue;
|
||||
}
|
||||
}
|
||||
function tree_maximumElement(s) {
|
||||
const matchValue = tree_maximumElementOpt(s);
|
||||
if (matchValue == null) {
|
||||
throw new Error("Set contains no elements");
|
||||
}
|
||||
else {
|
||||
return matchValue;
|
||||
}
|
||||
}
|
||||
function tree_collapseLHS(stack) {
|
||||
collapseLHS: while (true) {
|
||||
if (stack.tail != null) {
|
||||
if (stack.head.tag === 1) {
|
||||
return stack;
|
||||
}
|
||||
else if (stack.head.tag === 2) {
|
||||
stack = listOfArray([stack.head.data[1], tree_SetOne(stack.head.data[0]), stack.head.data[2]], stack.tail);
|
||||
continue collapseLHS;
|
||||
}
|
||||
else {
|
||||
stack = stack.tail;
|
||||
continue collapseLHS;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return new List();
|
||||
}
|
||||
}
|
||||
}
|
||||
function tree_mkIterator(s) {
|
||||
return { stack: tree_collapseLHS(new List(s, new List())), started: false };
|
||||
}
|
||||
// function tree_notStarted() {
|
||||
// throw new Error("Enumeration not started");
|
||||
// };
|
||||
// var alreadyFinished = $exports.alreadyFinished = function () {
|
||||
// throw new Error("Enumeration already started");
|
||||
// };
|
||||
function tree_moveNext(i) {
|
||||
function current(it) {
|
||||
if (it.stack.tail == null) {
|
||||
return null;
|
||||
}
|
||||
else if (it.stack.head.tag === 1) {
|
||||
return it.stack.head.data[0];
|
||||
}
|
||||
throw new Error("Please report error: Set iterator, unexpected stack for current");
|
||||
}
|
||||
if (i.started) {
|
||||
if (i.stack.tail == null) {
|
||||
return { done: true, value: null };
|
||||
}
|
||||
else {
|
||||
if (i.stack.head.tag === 1) {
|
||||
i.stack = tree_collapseLHS(i.stack.tail);
|
||||
return {
|
||||
done: i.stack.tail == null,
|
||||
value: current(i),
|
||||
};
|
||||
}
|
||||
else {
|
||||
throw new Error("Please report error: Set iterator, unexpected stack for moveNext");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
i.started = true;
|
||||
return {
|
||||
done: i.stack.tail == null,
|
||||
value: current(i),
|
||||
};
|
||||
}
|
||||
}
|
||||
function tree_compareStacks(comparer, l1, l2) {
|
||||
compareStacks: while (true) {
|
||||
const matchValue = l1.tail != null ? l2.tail != null ? l2.head.tag === 1 ? l1.head.tag === 1 ? [4, l1.head.data[0], l2.head.data[0], l1.tail, l2.tail] : l1.head.tag === 2 ? l1.head.data[1].tag === 0 ? [6, l1.head.data[1], l1.head.data[0], l1.head.data[2], l2.head.data[0], l1.tail, l2.tail] : [9, l1.head.data[0], l1.head.data[1], l1.head.data[2], l1.tail] : [10, l2.head.data[0], l2.tail] : l2.head.tag === 2 ? l2.head.data[1].tag === 0 ? l1.head.tag === 1 ? [5, l1.head.data[0], l2.head.data[0], l2.head.data[2], l1.tail, l2.tail] : l1.head.tag === 2 ? l1.head.data[1].tag === 0 ? [7, l1.head.data[0], l1.head.data[2], l2.head.data[0], l2.head.data[2], l1.tail, l2.tail] : [9, l1.head.data[0], l1.head.data[1], l1.head.data[2], l1.tail] : [11, l2.head.data[0], l2.head.data[1], l2.head.data[2], l2.tail] : l1.head.tag === 1 ? [8, l1.head.data[0], l1.tail] : l1.head.tag === 2 ? [9, l1.head.data[0], l1.head.data[1], l1.head.data[2], l1.tail] : [11, l2.head.data[0], l2.head.data[1], l2.head.data[2], l2.tail] : l1.head.tag === 1 ? [8, l1.head.data[0], l1.tail] : l1.head.tag === 2 ? [9, l1.head.data[0], l1.head.data[1], l1.head.data[2], l1.tail] : [3, l1.tail, l2.tail] : [2] : l2.tail != null ? [1] : [0];
|
||||
switch (matchValue[0]) {
|
||||
case 0:
|
||||
return 0;
|
||||
case 1:
|
||||
return -1;
|
||||
case 2:
|
||||
return 1;
|
||||
case 3:
|
||||
comparer = comparer;
|
||||
l1 = matchValue[1];
|
||||
l2 = matchValue[2];
|
||||
continue compareStacks;
|
||||
case 4:
|
||||
const c = comparer.Compare(matchValue[1], matchValue[2]) | 0;
|
||||
if (c !== 0) {
|
||||
return c | 0;
|
||||
}
|
||||
else {
|
||||
comparer = comparer;
|
||||
l1 = matchValue[3];
|
||||
l2 = matchValue[4];
|
||||
continue compareStacks;
|
||||
}
|
||||
case 5:
|
||||
const c_1 = comparer.Compare(matchValue[1], matchValue[2]) | 0;
|
||||
if (c_1 !== 0) {
|
||||
return c_1 | 0;
|
||||
}
|
||||
else {
|
||||
comparer = comparer;
|
||||
l1 = new List(new SetTree(0), matchValue[4]);
|
||||
l2 = new List(matchValue[3], matchValue[5]);
|
||||
continue compareStacks;
|
||||
}
|
||||
case 6:
|
||||
const c_2 = comparer.Compare(matchValue[2], matchValue[4]) | 0;
|
||||
if (c_2 !== 0) {
|
||||
return c_2 | 0;
|
||||
}
|
||||
else {
|
||||
comparer = comparer;
|
||||
l1 = new List(matchValue[3], matchValue[5]);
|
||||
l2 = new List(matchValue[1], matchValue[6]);
|
||||
continue compareStacks;
|
||||
}
|
||||
case 7:
|
||||
const c_3 = comparer.Compare(matchValue[1], matchValue[3]) | 0;
|
||||
if (c_3 !== 0) {
|
||||
return c_3 | 0;
|
||||
}
|
||||
else {
|
||||
comparer = comparer;
|
||||
l1 = new List(matchValue[2], matchValue[5]);
|
||||
l2 = new List(matchValue[4], matchValue[6]);
|
||||
continue compareStacks;
|
||||
}
|
||||
case 8:
|
||||
comparer = comparer;
|
||||
l1 = listOfArray([new SetTree(0), tree_SetOne(matchValue[1])], matchValue[2]);
|
||||
l2 = l2;
|
||||
continue compareStacks;
|
||||
case 9:
|
||||
comparer = comparer;
|
||||
l1 = listOfArray([matchValue[2], tree_SetNode(matchValue[1], new SetTree(0), matchValue[3], 0)], matchValue[4]);
|
||||
l2 = l2;
|
||||
continue compareStacks;
|
||||
case 10:
|
||||
comparer = comparer;
|
||||
l1 = l1;
|
||||
l2 = listOfArray([new SetTree(0), tree_SetOne(matchValue[1])], matchValue[2]);
|
||||
continue compareStacks;
|
||||
case 11:
|
||||
comparer = comparer;
|
||||
l1 = l1;
|
||||
l2 = listOfArray([matchValue[2], tree_SetNode(matchValue[1], new SetTree(0), matchValue[3], 0)], matchValue[4]);
|
||||
continue compareStacks;
|
||||
}
|
||||
}
|
||||
}
|
||||
function tree_compare(comparer, s1, s2) {
|
||||
if (s1.tag === 0) {
|
||||
return s2.tag === 0 ? 0 : -1;
|
||||
}
|
||||
else {
|
||||
return s2.tag === 0 ? 1 : tree_compareStacks(comparer, listOfArray([s1]), listOfArray([s2]));
|
||||
}
|
||||
}
|
||||
function tree_mkFromEnumerator(comparer, acc, e) {
|
||||
let cur = e.next();
|
||||
while (!cur.done) {
|
||||
acc = tree_add(comparer, cur.value, acc);
|
||||
cur = e.next();
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
function tree_ofSeq(comparer, c) {
|
||||
const ie = c[Symbol.iterator]();
|
||||
return tree_mkFromEnumerator(comparer, new SetTree(0), ie);
|
||||
}
|
||||
export default class FableSet {
|
||||
/** Do not call, use Set.create instead. */
|
||||
constructor() { return; }
|
||||
ToString() {
|
||||
return "set [" + Array.from(this).map((x) => toString(x)).join("; ") + "]";
|
||||
}
|
||||
Equals(s2) {
|
||||
return this.CompareTo(s2) === 0;
|
||||
}
|
||||
CompareTo(s2) {
|
||||
return this === s2 ? 0 : tree_compare(this.comparer, this.tree, s2.tree);
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
const i = tree_mkIterator(this.tree);
|
||||
return {
|
||||
next: () => tree_moveNext(i),
|
||||
};
|
||||
}
|
||||
values() {
|
||||
return this[Symbol.iterator]();
|
||||
}
|
||||
has(v) {
|
||||
return tree_mem(this.comparer, v, this.tree);
|
||||
}
|
||||
/** Mutating method */
|
||||
add(v) {
|
||||
this.tree = tree_add(this.comparer, v, this.tree);
|
||||
return this;
|
||||
}
|
||||
/** Mutating method */
|
||||
delete(v) {
|
||||
// TODO: Is calculating the size twice is more performant than calling tree_mem?
|
||||
const oldSize = tree_count(this.tree);
|
||||
this.tree = tree_remove(this.comparer, v, this.tree);
|
||||
return oldSize > tree_count(this.tree);
|
||||
}
|
||||
/** Mutating method */
|
||||
clear() {
|
||||
this.tree = new SetTree(0);
|
||||
}
|
||||
get size() {
|
||||
return tree_count(this.tree);
|
||||
}
|
||||
[FSymbol.reflection]() {
|
||||
return {
|
||||
type: "Microsoft.FSharp.Collections.FSharpSet",
|
||||
interfaces: ["System.IEquatable", "System.IComparable"],
|
||||
};
|
||||
}
|
||||
}
|
||||
function from(comparer, tree) {
|
||||
const s = new FableSet();
|
||||
s.tree = tree;
|
||||
s.comparer = comparer || new Comparer();
|
||||
return s;
|
||||
}
|
||||
export function create(ie, comparer) {
|
||||
comparer = comparer || new Comparer();
|
||||
return from(comparer, ie ? tree_ofSeq(comparer, ie) : new SetTree(0));
|
||||
}
|
||||
export function isEmpty(s) {
|
||||
return tree_isEmpty(s.tree);
|
||||
}
|
||||
export function add(item, s) {
|
||||
return from(s.comparer, tree_add(s.comparer, item, s.tree));
|
||||
}
|
||||
export function addInPlace(item, s) {
|
||||
return s.has(item) ? false : (s.add(item), true);
|
||||
}
|
||||
export function remove(item, s) {
|
||||
return from(s.comparer, tree_remove(s.comparer, item, s.tree));
|
||||
}
|
||||
export function union(set1, set2) {
|
||||
return set2.tree.tag === 0
|
||||
? set1
|
||||
: set1.tree.tag === 0
|
||||
? set2
|
||||
: from(set1.comparer, tree_union(set1.comparer, set1.tree, set2.tree));
|
||||
}
|
||||
export function op_Addition(set1, set2) {
|
||||
return union(set1, set2);
|
||||
}
|
||||
export function unionInPlace(set1, set2) {
|
||||
seqIterate((x) => { set1.add(x); }, set2);
|
||||
}
|
||||
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((acc, s) => union(s, acc), create(), sets);
|
||||
}
|
||||
export function difference(set1, set2) {
|
||||
return set1.tree.tag === 0
|
||||
? set1
|
||||
: set2.tree.tag === 0
|
||||
? set1
|
||||
: from(set1.comparer, tree_diff(set1.comparer, set1.tree, set2.tree));
|
||||
}
|
||||
export function op_Subtraction(set1, set2) {
|
||||
return difference(set1, set2);
|
||||
}
|
||||
export function differenceInPlace(set1, set2) {
|
||||
seqIterate((x) => { set1.delete(x); }, set2);
|
||||
}
|
||||
export function intersect(set1, set2) {
|
||||
return set2.tree.tag === 0
|
||||
? set2
|
||||
: set1.tree.tag === 0
|
||||
? set1
|
||||
: from(set1.comparer, tree_intersection(set1.comparer, set1.tree, set2.tree));
|
||||
}
|
||||
export function intersectInPlace(set1, set2) {
|
||||
const set2_ = set2 instanceof Set ? set2 : new Set(set2);
|
||||
seqIterate((x) => { if (!set2_.has(x)) {
|
||||
set1.delete(x);
|
||||
} }, set1);
|
||||
}
|
||||
export function intersectMany(sets) {
|
||||
return seqReduce((s1, s2) => intersect(s1, s2), sets);
|
||||
}
|
||||
export function isProperSubsetOf(set1, set2) {
|
||||
if (set1 instanceof FableSet && set2 instanceof FableSet) {
|
||||
return tree_psubset(set1.comparer, set1.tree, set2.tree);
|
||||
}
|
||||
else {
|
||||
set2 = set2 instanceof Set ? set2 : new Set(set2);
|
||||
return seqForAll((x) => set2.has(x), set1) && seqExists((x) => !set1.has(x), set2);
|
||||
}
|
||||
}
|
||||
export function isProperSubset(set1, set2) {
|
||||
return isProperSubsetOf(set1, set2);
|
||||
}
|
||||
export function isSubsetOf(set1, set2) {
|
||||
if (set1 instanceof FableSet && set2 instanceof FableSet) {
|
||||
return tree_subset(set1.comparer, set1.tree, set2.tree);
|
||||
}
|
||||
else {
|
||||
set2 = set2 instanceof Set ? set2 : new Set(set2);
|
||||
return seqForAll((x) => set2.has(x), set1);
|
||||
}
|
||||
}
|
||||
export function isSubset(set1, set2) {
|
||||
return isSubsetOf(set1, set2);
|
||||
}
|
||||
export function isProperSupersetOf(set1, set2) {
|
||||
if (set1 instanceof FableSet && set2 instanceof FableSet) {
|
||||
return tree_psubset(set1.comparer, set2.tree, set1.tree);
|
||||
}
|
||||
else {
|
||||
return isProperSubset(set2 instanceof Set ? set2 : new Set(set2), set1);
|
||||
}
|
||||
}
|
||||
export function isProperSuperset(set1, set2) {
|
||||
return isProperSupersetOf(set1, set2);
|
||||
}
|
||||
export function isSupersetOf(set1, set2) {
|
||||
if (set1 instanceof FableSet && set2 instanceof FableSet) {
|
||||
return tree_subset(set1.comparer, set2.tree, set1.tree);
|
||||
}
|
||||
else {
|
||||
return isSubset(set2 instanceof Set ? set2 : new Set(set2), set1);
|
||||
}
|
||||
}
|
||||
export function isSuperset(set1, set2) {
|
||||
return isSupersetOf(set1, set2);
|
||||
}
|
||||
export function copyTo(xs, arr, arrayIndex, count) {
|
||||
if (!Array.isArray(arr) && !ArrayBuffer.isView(arr)) {
|
||||
throw new Error("Array is invalid");
|
||||
}
|
||||
count = count || arr.length;
|
||||
let i = arrayIndex || 0;
|
||||
const iter = xs[Symbol.iterator]();
|
||||
while (count--) {
|
||||
const el = iter.next();
|
||||
if (el.done) {
|
||||
break;
|
||||
}
|
||||
arr[i++] = el.value;
|
||||
}
|
||||
}
|
||||
export function partition(f, s) {
|
||||
if (s.tree.tag === 0) {
|
||||
return [s, s];
|
||||
}
|
||||
else {
|
||||
const tuple = tree_partition(s.comparer, f, s.tree);
|
||||
return [from(s.comparer, tuple[0]), from(s.comparer, tuple[1])];
|
||||
}
|
||||
}
|
||||
export function filter(f, s) {
|
||||
if (s.tree.tag === 0) {
|
||||
return s;
|
||||
}
|
||||
else {
|
||||
return from(s.comparer, tree_filter(s.comparer, f, s.tree));
|
||||
}
|
||||
}
|
||||
export function map(f, s) {
|
||||
const comparer = new Comparer();
|
||||
return from(comparer, tree_fold((acc, k) => tree_add(comparer, f(k), acc), new SetTree(0), s.tree));
|
||||
}
|
||||
export function exists(f, s) {
|
||||
return tree_exists(f, s.tree);
|
||||
}
|
||||
export function forAll(f, s) {
|
||||
return tree_forall(f, s.tree);
|
||||
}
|
||||
export function fold(f, seed, s) {
|
||||
return tree_fold(f, seed, s.tree);
|
||||
}
|
||||
export function foldBack(f, s, seed) {
|
||||
return tree_foldBack(f, s.tree, seed);
|
||||
}
|
||||
export function iterate(f, s) {
|
||||
tree_iter(f, s.tree);
|
||||
}
|
||||
export function minimumElement(s) {
|
||||
return tree_minimumElement(s.tree);
|
||||
}
|
||||
export function minElement(s) {
|
||||
return tree_minimumElement(s.tree);
|
||||
}
|
||||
export function maximumElement(s) {
|
||||
return tree_maximumElement(s.tree);
|
||||
}
|
||||
export function maxElement(s) {
|
||||
return tree_maximumElement(s.tree);
|
||||
}
|
||||
@@ -1,474 +0,0 @@
|
||||
import { toString as dateToString } from "./Date";
|
||||
import { escape } from "./RegExp";
|
||||
import { toString } from "./Util";
|
||||
const fsFormatRegExp = /(^|[^%])%([0+ ]*)(-?\d+)?(?:\.(\d+))?(\w)/;
|
||||
const formatRegExp = /\{(\d+)(,-?\d+)?(?:\:(.+?))?\}/g;
|
||||
// From https://stackoverflow.com/a/13653180/3922220
|
||||
const guidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
||||
const StringComparison = {
|
||||
CurrentCulture: 0,
|
||||
CurrentCultureIgnoreCase: 1,
|
||||
InvariantCulture: 2,
|
||||
InvariantCultureIgnoreCase: 3,
|
||||
Ordinal: 4,
|
||||
OrdinalIgnoreCase: 5,
|
||||
};
|
||||
function cmp(x, y, ic) {
|
||||
function isIgnoreCase(i) {
|
||||
return i === true ||
|
||||
i === StringComparison.CurrentCultureIgnoreCase ||
|
||||
i === StringComparison.InvariantCultureIgnoreCase ||
|
||||
i === StringComparison.OrdinalIgnoreCase;
|
||||
}
|
||||
function isOrdinal(i) {
|
||||
return i === StringComparison.Ordinal ||
|
||||
i === StringComparison.OrdinalIgnoreCase;
|
||||
}
|
||||
if (x == null) {
|
||||
return y == null ? 0 : -1;
|
||||
}
|
||||
if (y == null) {
|
||||
return 1;
|
||||
} // everything is bigger than null
|
||||
if (isOrdinal(ic)) {
|
||||
if (isIgnoreCase(ic)) {
|
||||
x = x.toLowerCase();
|
||||
y = y.toLowerCase();
|
||||
}
|
||||
return (x === y) ? 0 : (x < y ? -1 : 1);
|
||||
}
|
||||
else {
|
||||
if (isIgnoreCase(ic)) {
|
||||
x = x.toLocaleLowerCase();
|
||||
y = y.toLocaleLowerCase();
|
||||
}
|
||||
return x.localeCompare(y);
|
||||
}
|
||||
}
|
||||
export function compare(...args) {
|
||||
switch (args.length) {
|
||||
case 2: return cmp(args[0], args[1], false);
|
||||
case 3: return cmp(args[0], args[1], args[2]);
|
||||
case 4: return cmp(args[0], args[1], args[2] === true);
|
||||
case 5: return cmp(args[0].substr(args[1], args[4]), args[2].substr(args[3], args[4]), false);
|
||||
case 6: return cmp(args[0].substr(args[1], args[4]), args[2].substr(args[3], args[4]), args[5]);
|
||||
case 7: return cmp(args[0].substr(args[1], args[4]), args[2].substr(args[3], args[4]), args[5] === true);
|
||||
default: throw new Error("String.compare: Unsupported number of parameters");
|
||||
}
|
||||
}
|
||||
export function compareTo(x, y) {
|
||||
return cmp(x, y, false);
|
||||
}
|
||||
export function startsWith(str, pattern, ic) {
|
||||
if (str.length >= pattern.length) {
|
||||
return cmp(str.substr(0, pattern.length), pattern, ic) === 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function indexOfAny(str, anyOf, ...args) {
|
||||
if (str == null || str === "") {
|
||||
return -1;
|
||||
}
|
||||
const startIndex = (args.length > 0) ? args[0] : 0;
|
||||
if (startIndex < 0) {
|
||||
throw new Error("String.indexOfAny: Start index cannot be negative");
|
||||
}
|
||||
const length = (args.length > 1) ? args[1] : str.length - startIndex;
|
||||
if (length < 0) {
|
||||
throw new Error("String.indexOfAny: Length cannot be negative");
|
||||
}
|
||||
if (length > str.length - startIndex) {
|
||||
throw new Error("String.indexOfAny: Invalid startIndex and length");
|
||||
}
|
||||
str = str.substr(startIndex, length);
|
||||
for (const c of anyOf) {
|
||||
const index = str.indexOf(c);
|
||||
if (index > -1) {
|
||||
return index + startIndex;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
function toHex(value) {
|
||||
return value < 0
|
||||
? "ff" + (16777215 - (Math.abs(value) - 1)).toString(16)
|
||||
: value.toString(16);
|
||||
}
|
||||
export function printf(input) {
|
||||
return {
|
||||
input,
|
||||
cont: fsFormat(input),
|
||||
};
|
||||
}
|
||||
export function toConsole(arg) {
|
||||
// Don't remove the lambda here, see #1357
|
||||
return arg.cont((x) => { console.log(x); });
|
||||
}
|
||||
export function toConsoleError(arg) {
|
||||
return arg.cont((x) => { console.error(x); });
|
||||
}
|
||||
export function toText(arg) {
|
||||
return arg.cont((x) => x);
|
||||
}
|
||||
export function toFail(arg) {
|
||||
return arg.cont((x) => { throw new Error(x); });
|
||||
}
|
||||
function formatOnce(str2, rep) {
|
||||
return str2.replace(fsFormatRegExp, (_, prefix, flags, pad, precision, format) => {
|
||||
switch (format) {
|
||||
case "f":
|
||||
case "F":
|
||||
rep = rep.toFixed(precision || 6);
|
||||
break;
|
||||
case "g":
|
||||
case "G":
|
||||
rep = rep.toPrecision(precision);
|
||||
break;
|
||||
case "e":
|
||||
case "E":
|
||||
rep = rep.toExponential(precision);
|
||||
break;
|
||||
case "O":
|
||||
rep = toString(rep);
|
||||
break;
|
||||
case "A":
|
||||
rep = toString(rep, true);
|
||||
break;
|
||||
case "x":
|
||||
rep = toHex(Number(rep));
|
||||
break;
|
||||
case "X":
|
||||
rep = toHex(Number(rep)).toUpperCase();
|
||||
break;
|
||||
}
|
||||
const plusPrefix = flags.indexOf("+") >= 0 && parseInt(rep, 10) >= 0;
|
||||
pad = parseInt(pad, 10);
|
||||
if (!isNaN(pad)) {
|
||||
const ch = pad >= 0 && flags.indexOf("0") >= 0 ? "0" : " ";
|
||||
rep = padLeft(rep, Math.abs(pad) - (plusPrefix ? 1 : 0), ch, pad < 0);
|
||||
}
|
||||
const once = prefix + (plusPrefix ? "+" + rep : rep);
|
||||
return once.replace(/%/g, "%%");
|
||||
});
|
||||
}
|
||||
function createPrinter(str, cont) {
|
||||
const printer = (...args) => {
|
||||
// Make a copy as the function may be used several times
|
||||
let strCopy = str;
|
||||
for (const arg of args) {
|
||||
strCopy = formatOnce(strCopy, arg);
|
||||
}
|
||||
return fsFormatRegExp.test(strCopy)
|
||||
? createPrinter(strCopy, cont)
|
||||
: cont(strCopy.replace(/%%/g, "%"));
|
||||
};
|
||||
// Mark it as curried so it doesn't
|
||||
// get wrapped by CurriedLambda
|
||||
printer.curried = true;
|
||||
return printer;
|
||||
}
|
||||
export function fsFormat(str) {
|
||||
return (cont) => {
|
||||
return fsFormatRegExp.test(str)
|
||||
? createPrinter(str, cont)
|
||||
: cont(str);
|
||||
};
|
||||
}
|
||||
export function format(str, ...args) {
|
||||
return str.replace(formatRegExp, (match, idx, pad, pattern) => {
|
||||
let rep = args[idx];
|
||||
let padSymbol = " ";
|
||||
if (typeof rep === "number") {
|
||||
switch ((pattern || "").substring(0, 1)) {
|
||||
case "f":
|
||||
case "F":
|
||||
rep = pattern.length > 1 ? rep.toFixed(pattern.substring(1)) : rep.toFixed(2);
|
||||
break;
|
||||
case "g":
|
||||
case "G":
|
||||
rep = pattern.length > 1 ? rep.toPrecision(pattern.substring(1)) : rep.toPrecision();
|
||||
break;
|
||||
case "e":
|
||||
case "E":
|
||||
rep = pattern.length > 1 ? rep.toExponential(pattern.substring(1)) : rep.toExponential();
|
||||
break;
|
||||
case "p":
|
||||
case "P":
|
||||
rep = (pattern.length > 1 ? (rep * 100).toFixed(pattern.substring(1)) : (rep * 100).toFixed(2)) + " %";
|
||||
break;
|
||||
case "x":
|
||||
rep = toHex(Number(rep));
|
||||
break;
|
||||
case "X":
|
||||
rep = toHex(Number(rep)).toUpperCase();
|
||||
break;
|
||||
default:
|
||||
const m = /^(0+)(\.0+)?$/.exec(pattern);
|
||||
if (m != null) {
|
||||
let decs = 0;
|
||||
if (m[2] != null) {
|
||||
rep = rep.toFixed(decs = m[2].length - 1);
|
||||
}
|
||||
pad = "," + (m[1].length + (decs ? decs + 1 : 0)).toString();
|
||||
padSymbol = "0";
|
||||
}
|
||||
else if (pattern) {
|
||||
rep = pattern;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (typeof rep.ToString === "function") {
|
||||
rep = rep.ToString(pattern);
|
||||
}
|
||||
else if (rep instanceof Date) {
|
||||
rep = dateToString(rep, pattern);
|
||||
}
|
||||
pad = parseInt((pad || "").substring(1), 10);
|
||||
if (!isNaN(pad)) {
|
||||
rep = padLeft(rep, Math.abs(pad), padSymbol, pad < 0);
|
||||
}
|
||||
return rep;
|
||||
});
|
||||
}
|
||||
export function endsWith(str, search) {
|
||||
const idx = str.lastIndexOf(search);
|
||||
return idx >= 0 && idx === str.length - search.length;
|
||||
}
|
||||
export function initialize(n, f) {
|
||||
if (n < 0) {
|
||||
throw new Error("String length must be non-negative");
|
||||
}
|
||||
const xs = new Array(n);
|
||||
for (let i = 0; i < n; i++) {
|
||||
xs[i] = f(i);
|
||||
}
|
||||
return xs.join("");
|
||||
}
|
||||
export function insert(str, startIndex, value) {
|
||||
if (startIndex < 0 || startIndex > str.length) {
|
||||
throw new Error("startIndex is negative or greater than the length of this instance.");
|
||||
}
|
||||
return str.substring(0, startIndex) + value + str.substring(startIndex);
|
||||
}
|
||||
export function isNullOrEmpty(str) {
|
||||
return typeof str !== "string" || str.length === 0;
|
||||
}
|
||||
export function isNullOrWhiteSpace(str) {
|
||||
return typeof str !== "string" || /^\s*$/.test(str);
|
||||
}
|
||||
export function join(delimiter, xs) {
|
||||
let xs2 = typeof xs === "string" ? [xs] : xs;
|
||||
const len = arguments.length;
|
||||
if (len > 2) {
|
||||
xs2 = Array(len - 1);
|
||||
for (let key = 1; key < len; key++) {
|
||||
xs2[key - 1] = arguments[key];
|
||||
}
|
||||
}
|
||||
else if (!Array.isArray(xs2)) {
|
||||
xs2 = Array.from(xs2);
|
||||
}
|
||||
return xs2.map((x) => toString(x)).join(delimiter);
|
||||
}
|
||||
/** Validates UUID as specified in RFC4122 (versions 1-5). Trims braces. */
|
||||
export function validateGuid(str, doNotThrow) {
|
||||
const trimmed = trim(str, "both", "{", "}");
|
||||
if (guidRegex.test(trimmed)) {
|
||||
return doNotThrow ? [true, trimmed] : trimmed;
|
||||
}
|
||||
else if (doNotThrow) {
|
||||
return [false, "00000000-0000-0000-0000-000000000000"];
|
||||
}
|
||||
throw new Error("Guid should contain 32 digits with 4 dashes: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
|
||||
}
|
||||
/* tslint:disable */
|
||||
// From https://gist.github.com/LeverOne/1308368
|
||||
export function newGuid() {
|
||||
let b = '';
|
||||
for (let a = 0; a++ < 36; b += a * 51 & 52
|
||||
? (a ^ 15 ? 8 ^ Math.random() * (a ^ 20 ? 16 : 4) : 4).toString(16)
|
||||
: '-')
|
||||
;
|
||||
return b;
|
||||
}
|
||||
// Maps for number <-> hex string conversion
|
||||
let _convertMapsInitialized = false;
|
||||
let _byteToHex;
|
||||
let _hexToByte;
|
||||
function initConvertMaps() {
|
||||
_byteToHex = new Array(256);
|
||||
_hexToByte = {};
|
||||
for (var i = 0; i < 256; i++) {
|
||||
_byteToHex[i] = (i + 0x100).toString(16).substr(1);
|
||||
_hexToByte[_byteToHex[i]] = i;
|
||||
}
|
||||
_convertMapsInitialized = true;
|
||||
}
|
||||
/** Parse a UUID into it's component bytes */
|
||||
// Adapted from https://github.com/zefferus/uuid-parse
|
||||
export function guidToArray(s) {
|
||||
if (!_convertMapsInitialized) {
|
||||
initConvertMaps();
|
||||
}
|
||||
let i = 0;
|
||||
const buf = new Uint8Array(16);
|
||||
s.toLowerCase().replace(/[0-9a-f]{2}/g, (function (oct) {
|
||||
switch (i) {
|
||||
// .NET saves first three byte groups with differten endianness
|
||||
// See https://stackoverflow.com/a/16722909/3922220
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
buf[3 - i++] = _hexToByte[oct];
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
buf[9 - i++] = _hexToByte[oct];
|
||||
break;
|
||||
case 6:
|
||||
case 7:
|
||||
buf[13 - i++] = _hexToByte[oct];
|
||||
break;
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
buf[i++] = _hexToByte[oct];
|
||||
break;
|
||||
}
|
||||
}));
|
||||
// Zero out remaining bytes if string was short
|
||||
while (i < 16) {
|
||||
buf[i++] = 0;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
/** Convert UUID byte array into a string */
|
||||
export function arrayToGuid(buf) {
|
||||
if (buf.length !== 16) {
|
||||
throw new Error("Byte array for GUID must be exactly 16 bytes long");
|
||||
}
|
||||
if (!_convertMapsInitialized) {
|
||||
initConvertMaps();
|
||||
}
|
||||
return _byteToHex[buf[3]] + _byteToHex[buf[2]] +
|
||||
_byteToHex[buf[1]] + _byteToHex[buf[0]] + '-' +
|
||||
_byteToHex[buf[5]] + _byteToHex[buf[4]] + '-' +
|
||||
_byteToHex[buf[7]] + _byteToHex[buf[6]] + '-' +
|
||||
_byteToHex[buf[8]] + _byteToHex[buf[9]] + '-' +
|
||||
_byteToHex[buf[10]] + _byteToHex[buf[11]] +
|
||||
_byteToHex[buf[12]] + _byteToHex[buf[13]] +
|
||||
_byteToHex[buf[14]] + _byteToHex[buf[15]];
|
||||
}
|
||||
/* tslint:enable */
|
||||
function notSupported(name) {
|
||||
throw new Error("The environment doesn't support '" + name + "', please use a polyfill.");
|
||||
}
|
||||
export function toBase64String(inArray) {
|
||||
let str = "";
|
||||
for (let i = 0; i < inArray.length; i++) {
|
||||
str += String.fromCharCode(inArray[i]);
|
||||
}
|
||||
return typeof btoa === "function" ? btoa(str) : notSupported("btoa");
|
||||
}
|
||||
export function fromBase64String(b64Encoded) {
|
||||
const binary = typeof atob === "function" ? atob(b64Encoded) : notSupported("atob");
|
||||
const bytes = new Uint8Array(binary.length);
|
||||
for (let i = 0; i < binary.length; i++) {
|
||||
bytes[i] = binary.charCodeAt(i);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
export function padLeft(str, len, ch, isRight) {
|
||||
ch = ch || " ";
|
||||
str = String(str);
|
||||
len = len - str.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
str = isRight ? str + ch : ch + str;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
export function padRight(str, len, ch) {
|
||||
return padLeft(str, len, ch, true);
|
||||
}
|
||||
export function remove(str, startIndex, count) {
|
||||
if (startIndex >= str.length) {
|
||||
throw new Error("startIndex must be less than length of string");
|
||||
}
|
||||
if (typeof count === "number" && (startIndex + count) > str.length) {
|
||||
throw new Error("Index and count must refer to a location within the string.");
|
||||
}
|
||||
return str.slice(0, startIndex) + (typeof count === "number" ? str.substr(startIndex + count) : "");
|
||||
}
|
||||
export function replace(str, search, replace) {
|
||||
return str.replace(new RegExp(escape(search), "g"), replace);
|
||||
}
|
||||
export function replicate(n, x) {
|
||||
return initialize(n, () => x);
|
||||
}
|
||||
export function getCharAtIndex(input, index) {
|
||||
if (index < 0 || index > input.length) {
|
||||
throw new Error("System.IndexOutOfRangeException: Index was outside the bounds of the array.");
|
||||
}
|
||||
return input[index];
|
||||
}
|
||||
export function split(str, splitters, count, removeEmpty) {
|
||||
count = typeof count === "number" ? count : null;
|
||||
removeEmpty = typeof removeEmpty === "number" ? removeEmpty : null;
|
||||
if (count < 0) {
|
||||
throw new Error("Count cannot be less than zero");
|
||||
}
|
||||
if (count === 0) {
|
||||
return [];
|
||||
}
|
||||
let splitters2 = splitters;
|
||||
if (!Array.isArray(splitters)) {
|
||||
const len = arguments.length;
|
||||
splitters2 = Array(len - 1);
|
||||
for (let key = 1; key < len; key++) {
|
||||
splitters2[key - 1] = arguments[key];
|
||||
}
|
||||
}
|
||||
splitters2 = splitters2.map((x) => escape(x));
|
||||
splitters2 = splitters2.length > 0 ? splitters2 : [" "];
|
||||
let i = 0;
|
||||
const splits = [];
|
||||
const reg = new RegExp(splitters2.join("|"), "g");
|
||||
while (count == null || count > 1) {
|
||||
const m = reg.exec(str);
|
||||
if (m === null) {
|
||||
break;
|
||||
}
|
||||
if (!removeEmpty || (m.index - i) > 0) {
|
||||
count = count != null ? count - 1 : count;
|
||||
splits.push(str.substring(i, m.index));
|
||||
}
|
||||
i = reg.lastIndex;
|
||||
}
|
||||
if (!removeEmpty || (str.length - i) > 0) {
|
||||
splits.push(str.substring(i));
|
||||
}
|
||||
return splits;
|
||||
}
|
||||
export function trim(str, side, ...chars) {
|
||||
if (side === "both" && chars.length === 0) {
|
||||
return str.trim();
|
||||
}
|
||||
if (side === "start" || side === "both") {
|
||||
const reg = chars.length === 0 ? /^\s+/ : new RegExp("^[" + escape(chars.join("")) + "]+");
|
||||
str = str.replace(reg, "");
|
||||
}
|
||||
if (side === "end" || side === "both") {
|
||||
const reg = chars.length === 0 ? /\s+$/ : new RegExp("[" + escape(chars.join("")) + "]+$");
|
||||
str = str.replace(reg, "");
|
||||
}
|
||||
return str;
|
||||
}
|
||||
export function filter(pred, x) {
|
||||
return x.split("").filter(pred).join("");
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
const types = new Map();
|
||||
export function setType(fullName, cons) {
|
||||
types.set(fullName, cons);
|
||||
}
|
||||
export function getType(fullName) {
|
||||
return types.get(fullName);
|
||||
}
|
||||
export default {
|
||||
reflection: Symbol("reflection"),
|
||||
};
|
||||
@@ -1,81 +0,0 @@
|
||||
import { fromNumber } from "./Long";
|
||||
import { compare as utilCompare } from "./Util";
|
||||
// TimeSpan in runtime just becomes a number representing milliseconds
|
||||
export function create(d = 0, h = 0, m = 0, s = 0, ms = 0) {
|
||||
switch (arguments.length) {
|
||||
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
|
||||
break;
|
||||
}
|
||||
return d * 86400000 + h * 3600000 + m * 60000 + s * 1000 + ms;
|
||||
}
|
||||
export function fromTicks(ticks) {
|
||||
return ticks.div(10000).toNumber();
|
||||
}
|
||||
export function fromDays(d) {
|
||||
return create(d, 0, 0, 0);
|
||||
}
|
||||
export function fromHours(h) {
|
||||
return create(h, 0, 0);
|
||||
}
|
||||
export function fromMinutes(m) {
|
||||
return create(0, m, 0);
|
||||
}
|
||||
export function fromSeconds(s) {
|
||||
return create(0, 0, s);
|
||||
}
|
||||
export function days(ts) {
|
||||
return Math.floor(ts / 86400000);
|
||||
}
|
||||
export function hours(ts) {
|
||||
return Math.floor(ts % 86400000 / 3600000);
|
||||
}
|
||||
export function minutes(ts) {
|
||||
return Math.floor(ts % 3600000 / 60000);
|
||||
}
|
||||
export function seconds(ts) {
|
||||
return Math.floor(ts % 60000 / 1000);
|
||||
}
|
||||
export function milliseconds(ts) {
|
||||
return Math.floor(ts % 1000);
|
||||
}
|
||||
export function ticks(ts) {
|
||||
return fromNumber(ts).mul(10000);
|
||||
}
|
||||
export function totalDays(ts) {
|
||||
return ts / 86400000;
|
||||
}
|
||||
export function totalHours(ts) {
|
||||
return ts / 3600000;
|
||||
}
|
||||
export function totalMinutes(ts) {
|
||||
return ts / 60000;
|
||||
}
|
||||
export function totalSeconds(ts) {
|
||||
return ts / 1000;
|
||||
}
|
||||
export function negate(ts) {
|
||||
return ts * -1;
|
||||
}
|
||||
export function add(ts1, ts2) {
|
||||
return ts1 + ts2;
|
||||
}
|
||||
export function subtract(ts1, ts2) {
|
||||
return ts1 - ts2;
|
||||
}
|
||||
export function compare(x, y) {
|
||||
return utilCompare(x, y);
|
||||
}
|
||||
export function compareTo(x, y) {
|
||||
return utilCompare(x, y);
|
||||
}
|
||||
export function duration(x) {
|
||||
return Math.abs(x);
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
import Event from "./Event";
|
||||
import FSymbol from "./Symbol";
|
||||
export default class Timer {
|
||||
constructor(interval) {
|
||||
this.Interval = interval > 0 ? interval : 100;
|
||||
this.AutoReset = true;
|
||||
this._elapsed = new Event();
|
||||
}
|
||||
get Elapsed() {
|
||||
return this._elapsed;
|
||||
}
|
||||
get Enabled() {
|
||||
return this._enabled;
|
||||
}
|
||||
set Enabled(x) {
|
||||
if (!this._isDisposed && this._enabled !== x) {
|
||||
this._enabled = x;
|
||||
if (this._enabled) {
|
||||
if (this.AutoReset) {
|
||||
this._intervalId = setInterval(() => {
|
||||
if (!this.AutoReset) {
|
||||
this.Enabled = false;
|
||||
}
|
||||
this._elapsed.Trigger(new Date());
|
||||
}, this.Interval);
|
||||
}
|
||||
else {
|
||||
this._timeoutId = setTimeout(() => {
|
||||
this.Enabled = false;
|
||||
this._timeoutId = 0;
|
||||
if (this.AutoReset) {
|
||||
this.Enabled = true;
|
||||
}
|
||||
this._elapsed.Trigger(new Date());
|
||||
}, this.Interval);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this._timeoutId) {
|
||||
clearTimeout(this._timeoutId);
|
||||
this._timeoutId = 0;
|
||||
}
|
||||
if (this._intervalId) {
|
||||
clearInterval(this._intervalId);
|
||||
this._intervalId = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Dispose() {
|
||||
this.Enabled = false;
|
||||
this._isDisposed = true;
|
||||
}
|
||||
Close() {
|
||||
this.Dispose();
|
||||
}
|
||||
Start() {
|
||||
this.Enabled = true;
|
||||
}
|
||||
Stop() {
|
||||
this.Enabled = false;
|
||||
}
|
||||
[FSymbol.reflection]() {
|
||||
return {
|
||||
type: "System.Timers.Timer",
|
||||
interfaces: ["System.IDisposable"],
|
||||
};
|
||||
}
|
||||
}
|
||||
-553
@@ -1,553 +0,0 @@
|
||||
import { compare as compareDates, toString as dateToString } from "./Date";
|
||||
import FSymbol from "./Symbol";
|
||||
export class NonDeclaredType {
|
||||
constructor(kind, definition, generics) {
|
||||
this.kind = kind;
|
||||
this.definition = definition;
|
||||
this.generics = generics;
|
||||
}
|
||||
Equals(other) {
|
||||
if (this.kind === other.kind && this.definition === other.definition) {
|
||||
return typeof this.generics === "object"
|
||||
// equalsRecords should also work for Type[] (tuples)
|
||||
? equalsRecords(this.generics, other.generics)
|
||||
: this.generics === other.generics;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const Any = new NonDeclaredType("Any");
|
||||
export const Unit = new NonDeclaredType("Unit");
|
||||
export function Option(t) {
|
||||
return new NonDeclaredType("Option", null, [t]);
|
||||
}
|
||||
function FableArray(t, isTypedArray = false) {
|
||||
let def = null;
|
||||
let genArg = null;
|
||||
if (isTypedArray) {
|
||||
def = t;
|
||||
}
|
||||
else {
|
||||
genArg = t;
|
||||
}
|
||||
return new NonDeclaredType("Array", def, [genArg]);
|
||||
}
|
||||
export { FableArray as Array };
|
||||
export function Tuple(types) {
|
||||
return new NonDeclaredType("Tuple", null, types);
|
||||
}
|
||||
function FableFunction(types) {
|
||||
return new NonDeclaredType("Function", null, types);
|
||||
}
|
||||
export { FableFunction as Function };
|
||||
export function GenericParam(definition) {
|
||||
return new NonDeclaredType("GenericParam", definition);
|
||||
}
|
||||
export function Interface(definition) {
|
||||
return new NonDeclaredType("Interface", definition);
|
||||
}
|
||||
export function makeGeneric(typeDef, genArgs) {
|
||||
return new NonDeclaredType("GenericType", typeDef, genArgs);
|
||||
}
|
||||
export function isGeneric(typ) {
|
||||
return typ instanceof NonDeclaredType && typ.kind === "GenericType";
|
||||
}
|
||||
/**
|
||||
* 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) {
|
||||
return isGeneric(typ) ? typ.definition : typ;
|
||||
}
|
||||
export function extendInfo(cons, info) {
|
||||
const parent = Object.getPrototypeOf(cons.prototype);
|
||||
if (typeof parent[FSymbol.reflection] === "function") {
|
||||
const newInfo = {};
|
||||
const parentInfo = parent[FSymbol.reflection]();
|
||||
Object.getOwnPropertyNames(info).forEach((k) => {
|
||||
const i = info[k];
|
||||
if (typeof i === "object") {
|
||||
newInfo[k] = Array.isArray(i)
|
||||
? (parentInfo[k] || []).concat(i)
|
||||
: Object.assign(parentInfo[k] || {}, i);
|
||||
}
|
||||
else {
|
||||
newInfo[k] = i;
|
||||
}
|
||||
});
|
||||
return newInfo;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
export function hasInterface(obj, interfaceName) {
|
||||
if (interfaceName === "System.Collections.Generic.IEnumerable") {
|
||||
return typeof obj[Symbol.iterator] === "function";
|
||||
}
|
||||
else if (typeof obj[FSymbol.reflection] === "function") {
|
||||
const interfaces = obj[FSymbol.reflection]().interfaces;
|
||||
return Array.isArray(interfaces) && interfaces.indexOf(interfaceName) > -1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Returns:
|
||||
* - Records: array with names of fields
|
||||
* - Classes: array with names of getters
|
||||
* - Nulls and unions: empty array
|
||||
* - JS Objects: The result of calling Object.getOwnPropertyNames
|
||||
*/
|
||||
export function getPropertyNames(obj) {
|
||||
if (obj == null) {
|
||||
return [];
|
||||
}
|
||||
const propertyMap = typeof obj[FSymbol.reflection] === "function" ? obj[FSymbol.reflection]().properties || [] : obj;
|
||||
return Object.getOwnPropertyNames(propertyMap);
|
||||
}
|
||||
export function isArray(obj) {
|
||||
return Array.isArray(obj) || ArrayBuffer.isView(obj);
|
||||
}
|
||||
export function toString(obj, quoteStrings = false) {
|
||||
function isObject(x) {
|
||||
return x !== null && typeof x === "object" && !(x instanceof Number)
|
||||
&& !(x instanceof String) && !(x instanceof Boolean);
|
||||
}
|
||||
if (obj == null || typeof obj === "number") {
|
||||
return String(obj);
|
||||
}
|
||||
if (typeof obj === "string") {
|
||||
return quoteStrings ? JSON.stringify(obj) : obj;
|
||||
}
|
||||
if (obj instanceof Date) {
|
||||
return dateToString(obj);
|
||||
}
|
||||
if (typeof obj.ToString === "function") {
|
||||
return obj.ToString();
|
||||
}
|
||||
if (hasInterface(obj, "FSharpUnion")) {
|
||||
const info = obj[FSymbol.reflection]();
|
||||
const uci = info.cases[obj.tag];
|
||||
switch (uci.length) {
|
||||
case 1:
|
||||
return uci[0];
|
||||
case 2:
|
||||
// For simplicity let's always use parens, in .NET they're ommitted in some cases
|
||||
return uci[0] + " (" + toString(obj.data, true) + ")";
|
||||
default:
|
||||
return uci[0] + " (" + obj.data.map((x) => toString(x, true)).join(",") + ")";
|
||||
}
|
||||
}
|
||||
try {
|
||||
return JSON.stringify(obj, (k, v) => {
|
||||
return v && v[Symbol.iterator] && !Array.isArray(v) && isObject(v) ? Array.from(v)
|
||||
: v && typeof v.ToString === "function" ? toString(v) : v;
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
// Fallback for objects with circular references
|
||||
return "{" + Object.getOwnPropertyNames(obj).map((k) => k + ": " + String(obj[k])).join(", ") + "}";
|
||||
}
|
||||
}
|
||||
export class ObjectRef {
|
||||
static id(o) {
|
||||
if (!ObjectRef.idMap.has(o)) {
|
||||
ObjectRef.idMap.set(o, ++ObjectRef.count);
|
||||
}
|
||||
return ObjectRef.idMap.get(o);
|
||||
}
|
||||
}
|
||||
ObjectRef.idMap = new WeakMap();
|
||||
ObjectRef.count = 0;
|
||||
export function getHashCode(x) {
|
||||
return ObjectRef.id(x) * 2654435761 | 0;
|
||||
}
|
||||
export function hash(x) {
|
||||
if (typeof x === typeof 1) {
|
||||
return x * 2654435761 | 0;
|
||||
}
|
||||
if (x != null && typeof x.GetHashCode === "function") {
|
||||
return x.GetHashCode();
|
||||
}
|
||||
else {
|
||||
const s = toString(x);
|
||||
let h = 5381;
|
||||
let i = 0;
|
||||
const len = s.length;
|
||||
while (i < len) {
|
||||
h = (h * 33) ^ s.charCodeAt(i++);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
}
|
||||
export function equals(x, y) {
|
||||
// Optimization if they are referencially equal
|
||||
if (x === y) {
|
||||
return true;
|
||||
}
|
||||
else if (x == null) {
|
||||
return y == null;
|
||||
}
|
||||
else if (y == null) {
|
||||
return false;
|
||||
}
|
||||
else if (typeof x !== "object" || typeof y !== "object") {
|
||||
return x === y;
|
||||
// Equals override or IEquatable implementation
|
||||
}
|
||||
else if (typeof x.Equals === "function") {
|
||||
return x.Equals(y);
|
||||
}
|
||||
else if (typeof y.Equals === "function") {
|
||||
return y.Equals(x);
|
||||
}
|
||||
else if (Object.getPrototypeOf(x) !== Object.getPrototypeOf(y)) {
|
||||
return false;
|
||||
}
|
||||
else if (Array.isArray(x)) {
|
||||
if (x.length !== y.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < x.length; i++) {
|
||||
if (!equals(x[i], y[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (ArrayBuffer.isView(x)) {
|
||||
if (x.byteLength !== y.byteLength) {
|
||||
return false;
|
||||
}
|
||||
const dv1 = new DataView(x.buffer);
|
||||
const dv2 = new DataView(y.buffer);
|
||||
for (let i = 0; i < x.byteLength; i++) {
|
||||
if (dv1.getUint8(i) !== dv2.getUint8(i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (x instanceof Date) {
|
||||
return x.getTime() === y.getTime();
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export function comparePrimitives(x, y) {
|
||||
return x === y ? 0 : (x < y ? -1 : 1);
|
||||
}
|
||||
export function compare(x, y) {
|
||||
// Optimization if they are referencially equal
|
||||
if (x === y) {
|
||||
return 0;
|
||||
}
|
||||
else if (x == null) {
|
||||
return y == null ? 0 : -1;
|
||||
}
|
||||
else if (y == null) {
|
||||
return 1; // everything is bigger than null
|
||||
}
|
||||
else if (typeof x !== "object" || typeof y !== "object") {
|
||||
return x === y ? 0 : (x < y ? -1 : 1);
|
||||
// Some types (see Long.ts) may just implement the function and not the interface
|
||||
// else if (hasInterface(x, "System.IComparable"))
|
||||
}
|
||||
else if (typeof x.CompareTo === "function") {
|
||||
return x.CompareTo(y);
|
||||
}
|
||||
else if (typeof y.CompareTo === "function") {
|
||||
return y.CompareTo(x) * -1;
|
||||
}
|
||||
else if (Object.getPrototypeOf(x) !== Object.getPrototypeOf(y)) {
|
||||
return -1;
|
||||
}
|
||||
else if (Array.isArray(x)) {
|
||||
if (x.length !== y.length) {
|
||||
return x.length < y.length ? -1 : 1;
|
||||
}
|
||||
for (let i = 0, j = 0; i < x.length; i++) {
|
||||
j = compare(x[i], y[i]);
|
||||
if (j !== 0) {
|
||||
return j;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else if (ArrayBuffer.isView(x)) {
|
||||
if (x.byteLength !== y.byteLength) {
|
||||
return x.byteLength < y.byteLength ? -1 : 1;
|
||||
}
|
||||
const dv1 = new DataView(x.buffer);
|
||||
const dv2 = new DataView(y.buffer);
|
||||
for (let i = 0, b1 = 0, b2 = 0; i < x.byteLength; i++) {
|
||||
b1 = dv1.getUint8(i), b2 = dv2.getUint8(i);
|
||||
if (b1 < b2) {
|
||||
return -1;
|
||||
}
|
||||
if (b1 > b2) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else if (x instanceof Date) {
|
||||
return compareDates(x, y);
|
||||
}
|
||||
else if (typeof x === "object") {
|
||||
const xhash = hash(x);
|
||||
const yhash = hash(y);
|
||||
if (xhash === yhash) {
|
||||
return equals(x, y) ? 0 : -1;
|
||||
}
|
||||
else {
|
||||
return xhash < yhash ? -1 : 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return x < y ? -1 : 1;
|
||||
}
|
||||
}
|
||||
export function lessThan(x, y) {
|
||||
return compare(x, y) < 0;
|
||||
}
|
||||
export function lessOrEqual(x, y) {
|
||||
return compare(x, y) <= 0;
|
||||
}
|
||||
export function greaterThan(x, y) {
|
||||
return compare(x, y) > 0;
|
||||
}
|
||||
export function greaterOrEqual(x, y) {
|
||||
return compare(x, y) >= 0;
|
||||
}
|
||||
export function equalsRecords(x, y) {
|
||||
// Optimization if they are referencially equal
|
||||
if (x === y) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
const keys = getPropertyNames(x);
|
||||
for (const key of keys) {
|
||||
if (!equals(x[key], y[key])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
export function compareRecords(x, y) {
|
||||
// Optimization if they are referencially equal
|
||||
if (x === y) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
const keys = getPropertyNames(x);
|
||||
for (const key of keys) {
|
||||
const res = compare(x[key], y[key]);
|
||||
if (res !== 0) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
export function equalsUnions(x, y) {
|
||||
return x === y || (x.tag === y.tag && equals(x.data, y.data));
|
||||
}
|
||||
export function compareUnions(x, y) {
|
||||
if (x === y) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
const res = x.tag < y.tag ? -1 : (x.tag > y.tag ? 1 : 0);
|
||||
return res !== 0 ? res : compare(x.data, y.data);
|
||||
}
|
||||
}
|
||||
export function createDisposable(f) {
|
||||
return {
|
||||
Dispose: f,
|
||||
[FSymbol.reflection]() { return { interfaces: ["System.IDisposable"] }; },
|
||||
};
|
||||
}
|
||||
// tslint forbids non-arrow functions, but it's
|
||||
// necessary here to use the arguments object
|
||||
/* tslint:disable */
|
||||
export function createAtom(value) {
|
||||
let atom = value;
|
||||
return function () {
|
||||
return arguments.length === 0
|
||||
? atom
|
||||
: (atom = arguments[0], void 0);
|
||||
};
|
||||
}
|
||||
/* tslint:enable */
|
||||
const CaseRules = {
|
||||
None: 0,
|
||||
LowerFirst: 1,
|
||||
};
|
||||
function isList(o) {
|
||||
if (o != null) {
|
||||
if (typeof o[FSymbol.reflection] === "function") {
|
||||
return o[FSymbol.reflection]().type === "Microsoft.FSharp.Collections.FSharpList";
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function createObj(fields, caseRule = CaseRules.None, casesCache) {
|
||||
const iter = fields[Symbol.iterator]();
|
||||
let cur = iter.next();
|
||||
const o = {};
|
||||
while (!cur.done) {
|
||||
const value = cur.value;
|
||||
if (Array.isArray(value)) {
|
||||
o[value[0]] = value[1];
|
||||
}
|
||||
else {
|
||||
casesCache = casesCache || new Map();
|
||||
const proto = Object.getPrototypeOf(value);
|
||||
let cases = casesCache.get(proto);
|
||||
if (cases == null) {
|
||||
if (typeof proto[FSymbol.reflection] === "function") {
|
||||
cases = proto[FSymbol.reflection]().cases;
|
||||
casesCache.set(proto, cases);
|
||||
}
|
||||
}
|
||||
const caseInfo = (cases != null) ? cases[value.tag] : null;
|
||||
if (Array.isArray(caseInfo)) {
|
||||
let key = caseInfo[0];
|
||||
if (caseRule === CaseRules.LowerFirst) {
|
||||
key = key[0].toLowerCase() + key.substr(1);
|
||||
}
|
||||
o[key] = caseInfo.length === 1
|
||||
? true
|
||||
: (isList(value.data) ? createObj(value.data, caseRule, casesCache) : value.data);
|
||||
}
|
||||
else {
|
||||
throw new Error("Cannot infer key and value of " + value);
|
||||
}
|
||||
}
|
||||
cur = iter.next();
|
||||
}
|
||||
return o;
|
||||
}
|
||||
export function toPlainJsObj(source) {
|
||||
if (source != null && source.constructor !== Object) {
|
||||
const target = {};
|
||||
let props = Object.getOwnPropertyNames(source);
|
||||
for (const p of props) {
|
||||
target[p] = source[p];
|
||||
}
|
||||
// Copy also properties from prototype, see #192
|
||||
const proto = Object.getPrototypeOf(source);
|
||||
if (proto != null) {
|
||||
props = Object.getOwnPropertyNames(proto);
|
||||
for (const p of props) {
|
||||
const prop = Object.getOwnPropertyDescriptor(proto, p);
|
||||
if (prop.value) {
|
||||
target[p] = prop.value;
|
||||
}
|
||||
else if (prop.get) {
|
||||
target[p] = prop.get.apply(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
else {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
export function jsOptions(mutator) {
|
||||
const opts = {};
|
||||
mutator(opts);
|
||||
return opts;
|
||||
}
|
||||
export function round(value, digits = 0) {
|
||||
const m = Math.pow(10, digits);
|
||||
const n = +(digits ? value * m : value).toFixed(8);
|
||||
const i = Math.floor(n);
|
||||
const f = n - i;
|
||||
const e = 1e-8;
|
||||
const r = (f > 0.5 - e && f < 0.5 + e) ? ((i % 2 === 0) ? i : i + 1) : Math.round(n);
|
||||
return digits ? r / m : r;
|
||||
}
|
||||
export function sign(x) {
|
||||
return x > 0 ? 1 : x < 0 ? -1 : 0;
|
||||
}
|
||||
export function randomNext(min, max) {
|
||||
return Math.floor(Math.random() * (max - min)) + min;
|
||||
}
|
||||
export function applyOperator(x, y, operator) {
|
||||
function getMethod(obj) {
|
||||
if (typeof obj === "object") {
|
||||
const cons = Object.getPrototypeOf(obj).constructor;
|
||||
if (typeof cons[operator] === "function") {
|
||||
return cons[operator];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
let meth = getMethod(x);
|
||||
if (meth != null) {
|
||||
return meth(x, y);
|
||||
}
|
||||
meth = getMethod(y);
|
||||
if (meth != null) {
|
||||
return meth(x, y);
|
||||
}
|
||||
switch (operator) {
|
||||
case "op_Addition":
|
||||
return x + y;
|
||||
case "op_Subtraction":
|
||||
return x - y;
|
||||
case "op_Multiply":
|
||||
return x * y;
|
||||
case "op_Division":
|
||||
return x / y;
|
||||
case "op_Modulus":
|
||||
return x % y;
|
||||
case "op_LeftShift":
|
||||
return x << y;
|
||||
case "op_RightShift":
|
||||
return x >> y;
|
||||
case "op_BitwiseAnd":
|
||||
return x & y;
|
||||
case "op_BitwiseOr":
|
||||
return x | y;
|
||||
case "op_ExclusiveOr":
|
||||
return x ^ y;
|
||||
case "op_LogicalNot":
|
||||
return x + y;
|
||||
case "op_UnaryNegation":
|
||||
return !x;
|
||||
case "op_BooleanAnd":
|
||||
return x && y;
|
||||
case "op_BooleanOr":
|
||||
return x || y;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
export function unescapeDataString(s) {
|
||||
// https://stackoverflow.com/a/4458580/524236
|
||||
return decodeURIComponent((s).replace(/\+/g, "%20"));
|
||||
}
|
||||
export function escapeDataString(s) {
|
||||
return encodeURIComponent(s).replace(/!/g, "%21")
|
||||
.replace(/'/g, "%27")
|
||||
.replace(/\(/g, "%28")
|
||||
.replace(/\)/g, "%29")
|
||||
.replace(/\*/g, "%2A");
|
||||
}
|
||||
export function escapeUriString(s) {
|
||||
return encodeURI(s);
|
||||
}
|
||||
// ICollection.Clear method can be called on IDictionary
|
||||
// too so we need to make a runtime check (see #1120)
|
||||
export function clear(col) {
|
||||
if (Array.isArray(col)) {
|
||||
col.splice(0);
|
||||
}
|
||||
else {
|
||||
col.clear();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -1 +0,0 @@
|
||||
WRagBLZ/iP6vgK+UPg5AdzcA0Ek6LJJHfWI3Wzm/WTrXqgrnDX+TpuYCkV0qn++j1u6uYZ7qxD0rzezgJc/i4Q==
|
||||
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>Fable.Core</id>
|
||||
<version>1.3.12</version>
|
||||
<authors>Alfonso García-Caro Núñez</authors>
|
||||
<owners>Alfonso García-Caro Núñez</owners>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<licenseUrl>https://raw.githubusercontent.com/fable-compiler/Fable/master/LICENSE</licenseUrl>
|
||||
<projectUrl>http://fable.io/</projectUrl>
|
||||
<iconUrl>https://raw.githubusercontent.com/fable-compiler/Fable/master/docs/img/fable_logo.png</iconUrl>
|
||||
<description>Fable Core Library</description>
|
||||
<tags>fsharp fable javascript f# js</tags>
|
||||
<dependencies>
|
||||
<group targetFramework=".NETStandard1.6">
|
||||
<dependency id="FSharp.Core" version="4.2.3" exclude="Build,Analyzers" />
|
||||
<dependency id="NETStandard.Library" version="1.6.1" exclude="Build,Analyzers" />
|
||||
</group>
|
||||
</dependencies>
|
||||
</metadata>
|
||||
</package>
|
||||
Binary file not shown.
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"version": 1,
|
||||
"contentHash": "5BC6XE5F+0Kz9LQd0caB6GJpZX903nVEqeH2q8o6w8X2IdIVtn1IpqQ2UthB0Xlw9iDchsr/zbbus40Bez0BSQ=="
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
-1
@@ -1 +0,0 @@
|
||||
DADk2zD4ZIp5vDcJ7xm9W2mZmFCQT3bvP3gi0AzarH3+Yz7WroNTbm6SIA61+cjBzmHJh5990dBhtFrv34Scfg==
|
||||
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>Fable.Elmish.Browser</id>
|
||||
<version>1.0.0</version>
|
||||
<authors>Eugene Tolmachev</authors>
|
||||
<owners>Eugene Tolmachev</owners>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<licenseUrl>https://raw.githubusercontent.com/fable-elmish/browser/master/LICENSE.md</licenseUrl>
|
||||
<projectUrl>http://fable-elmish.github.io/browser</projectUrl>
|
||||
<iconUrl>https://raw.githubusercontent.com/fable-elmish/elmish/master/docs/files/img/logo.png</iconUrl>
|
||||
<description>Elmish extensions for Fable apps targeting web browsers</description>
|
||||
<tags>fable elmish fsharp</tags>
|
||||
<dependencies>
|
||||
<group targetFramework=".NETStandard1.6">
|
||||
<dependency id="FSharp.Core" version="4.2.3" exclude="Build,Analyzers" />
|
||||
<dependency id="Fable.Core" version="1.2.4" exclude="Build,Analyzers" />
|
||||
<dependency id="Fable.Import.Browser" version="0.1.0" exclude="Build,Analyzers" />
|
||||
<dependency id="Fable.Elmish" version="1.0.0" exclude="Build,Analyzers" />
|
||||
</group>
|
||||
</dependencies>
|
||||
</metadata>
|
||||
</package>
|
||||
@@ -1,15 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="..\Meta.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard1.6</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="prelude.fs" />
|
||||
<Compile Include="parser.fs" />
|
||||
<Compile Include="navigation.fs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="*.fsproj; *.fs" PackagePath="fable\" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\.paket\Paket.Restore.targets" />
|
||||
</Project>
|
||||
@@ -1,97 +0,0 @@
|
||||
(** Custom navigation
|
||||
------
|
||||
This port of the Elm library is about treating the address bar as an input to your program.
|
||||
It converts changes in the address bar into messages and provides functions for manipulation of the browser history.
|
||||
*)
|
||||
namespace Elmish.Browser.Navigation
|
||||
|
||||
open Fable.Import.Browser
|
||||
open Elmish
|
||||
|
||||
(**
|
||||
#### Parser
|
||||
A function to turn the string in the address bar into data that is easier for your app to handle.
|
||||
*)
|
||||
type Parser<'a> = Location -> 'a
|
||||
|
||||
type Navigable<'msg> =
|
||||
| Change of Location
|
||||
| UserMsg of 'msg
|
||||
|
||||
(**
|
||||
#### Direct history manipulation
|
||||
*)
|
||||
[<RequireQualifiedAccess>]
|
||||
module Navigation =
|
||||
let [<Literal>] internal NavigatedEvent = "NavigatedEvent"
|
||||
|
||||
/// Modify current location
|
||||
let modifyUrl (newUrl:string):Cmd<_> =
|
||||
[fun _ -> history.replaceState((), "", newUrl)]
|
||||
|
||||
/// Push new location into history and navigate there
|
||||
let newUrl (newUrl:string):Cmd<_> =
|
||||
[fun _ -> history.pushState((), "", newUrl)
|
||||
let ev = document.createEvent_CustomEvent()
|
||||
ev.initCustomEvent (NavigatedEvent, true, true, obj())
|
||||
window.dispatchEvent ev
|
||||
|> ignore ]
|
||||
|
||||
/// Jump to some point in history (positve=forward, nagative=backward)
|
||||
let jump (n:int):Cmd<_> =
|
||||
[fun _ -> history.go n]
|
||||
|
||||
|
||||
(**
|
||||
#### Program extensions
|
||||
Treat user's program as a child component, by wrapping it and handling navigation events.
|
||||
*)
|
||||
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
|
||||
[<RequireQualifiedAccess>]
|
||||
module Program =
|
||||
/// Add the navigation to a program made with `mkProgram` or `mkSimple`.
|
||||
/// urlUpdate: similar to `update` function, but receives parsed url instead of message as an input.
|
||||
let toNavigable (parser : Parser<'a>)
|
||||
(urlUpdate : 'a->'model->('model * Cmd<'msg>))
|
||||
(program : Program<'a,'model,'msg,'view>) =
|
||||
let map (model, cmd) =
|
||||
model, cmd |> Cmd.map UserMsg
|
||||
|
||||
let update msg model =
|
||||
match msg with
|
||||
| Change location ->
|
||||
urlUpdate (parser location) model
|
||||
| UserMsg userMsg ->
|
||||
program.update userMsg model
|
||||
|> map
|
||||
|
||||
let locationChanges (dispatch:Dispatch<_ Navigable>) =
|
||||
let mutable lastLocation = None
|
||||
let onChange _ =
|
||||
match lastLocation with
|
||||
| Some href when href = window.location.href -> ()
|
||||
| _ ->
|
||||
lastLocation <- Some window.location.href
|
||||
Change window.location |> dispatch
|
||||
|> box
|
||||
|
||||
window.addEventListener_popstate(unbox onChange)
|
||||
window.addEventListener_hashchange(unbox onChange)
|
||||
window.addEventListener(Navigation.NavigatedEvent, unbox onChange)
|
||||
|
||||
let subs model =
|
||||
Cmd.batch
|
||||
[ [locationChanges]
|
||||
program.subscribe model |> Cmd.map UserMsg ]
|
||||
|
||||
let init () =
|
||||
program.init (parser window.location) |> map
|
||||
|
||||
{ init = init
|
||||
update = update
|
||||
subscribe = subs
|
||||
onError = program.onError
|
||||
setState = fun model dispatch -> program.setState model (UserMsg >> dispatch)
|
||||
view = fun model dispatch -> program.view model (UserMsg >> dispatch) }
|
||||
|
||||
|
||||
@@ -1,359 +0,0 @@
|
||||
(** UrlParser
|
||||
------
|
||||
This port of the Elm library helps you turn URLs into nicely structured data.
|
||||
It is designed to be used with `Navigation` module to help folks create
|
||||
single-page applications (SPAs) where you manage browser navigation yourself.
|
||||
*)
|
||||
|
||||
module Elmish.Browser.UrlParser
|
||||
|
||||
|
||||
(**
|
||||
#### Types
|
||||
*)
|
||||
|
||||
type State<'v> =
|
||||
{ visited : string list
|
||||
unvisited : string list
|
||||
args : Map<string,string>
|
||||
value : 'v }
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
|
||||
module internal State =
|
||||
let mkState visited unvisited args value =
|
||||
{ visited = visited
|
||||
unvisited = unvisited
|
||||
args = args
|
||||
value = value }
|
||||
|
||||
let map f { visited = visited; unvisited = unvisited; args = args; value = value } =
|
||||
{ visited = visited
|
||||
unvisited = unvisited
|
||||
args = args
|
||||
value = f value }
|
||||
|
||||
|
||||
/// Turn URLs like `/blog/42/cat-herding-techniques` into nice data.
|
||||
type Parser<'a,'b> = State<'a> -> State<'b> list
|
||||
|
||||
|
||||
(**
|
||||
#### Parse segements
|
||||
Create a custom path segment parser. You can use it to define something like “only CSS files” like this:
|
||||
```
|
||||
let css =
|
||||
custom "CSS_FILE" <| fun segment ->
|
||||
if String.EndsWith ".css" then
|
||||
Ok segment
|
||||
else
|
||||
Error "Does not end with .css"
|
||||
```
|
||||
*)
|
||||
let custom tipe stringToSomething : Parser<_,_> =
|
||||
let inner { visited = visited; unvisited = unvisited; args = args; value = value } =
|
||||
match unvisited with
|
||||
| [] -> []
|
||||
| next :: rest ->
|
||||
match stringToSomething next with
|
||||
| Ok nextValue ->
|
||||
[ State.mkState (next :: visited) rest args (value nextValue) ]
|
||||
|
||||
| Error msg ->
|
||||
[]
|
||||
inner
|
||||
|
||||
|
||||
(** Parse a segment of the path as a `string`.
|
||||
```
|
||||
parse str location
|
||||
```
|
||||
<pre>
|
||||
/alice/ ==> Some "alice"
|
||||
/bob ==> Some "bob"
|
||||
/42/ ==> Some "42"
|
||||
</pre>
|
||||
*)
|
||||
let str state =
|
||||
custom "string" Ok state
|
||||
|
||||
|
||||
(** Parse a segment of the path as an `int`.
|
||||
```
|
||||
parse i32 location
|
||||
```
|
||||
<pre>
|
||||
/alice/ ==> None
|
||||
/bob ==> None
|
||||
/42/ ==> Some 42
|
||||
</pre>
|
||||
*)
|
||||
let i32 state =
|
||||
custom "i32" (System.Int32.TryParse >> function true, value -> Ok value | _ -> Error "Can't parse int" ) state
|
||||
|
||||
|
||||
(** Parse a segment of the path if it matches a given string.
|
||||
```
|
||||
s "blog" // can parse /blog/
|
||||
// but not /glob/ or /42/ or anything else
|
||||
```
|
||||
*)
|
||||
let s str : Parser<_,_> =
|
||||
let inner { visited = visited; unvisited = unvisited; args = args; value = value } =
|
||||
match unvisited with
|
||||
| [] -> []
|
||||
| next :: rest ->
|
||||
if next = str then
|
||||
[ State.mkState (next :: visited) rest args value ]
|
||||
else
|
||||
[]
|
||||
inner
|
||||
|
||||
|
||||
|
||||
(**
|
||||
#### Combining parsers
|
||||
Parse a path with multiple segments.
|
||||
|
||||
```
|
||||
parse (s "blog" </> i32) location
|
||||
```
|
||||
<pre>
|
||||
/blog/35/ ==> Some 35
|
||||
/blog/42 ==> Some 42
|
||||
/blog/ ==> None
|
||||
/42/ ==> None
|
||||
</pre>
|
||||
```
|
||||
parse (s "search" </> str) location
|
||||
```
|
||||
<pre>
|
||||
/search/cats/ ==> Some "cats"
|
||||
/search/frog ==> Some "frog"
|
||||
/search/ ==> None
|
||||
/cats/ ==> None
|
||||
</pre>
|
||||
*)
|
||||
let inline (</>) (parseBefore:Parser<_,_>) (parseAfter:Parser<_,_>) =
|
||||
fun state ->
|
||||
List.collect parseAfter (parseBefore state)
|
||||
|
||||
|
||||
(** Transform a path parser.
|
||||
```
|
||||
type Comment = { author : string; id : int }
|
||||
rawComment =
|
||||
s "user" </> str </> s "comments" </> i32
|
||||
comment =
|
||||
map (fun a id -> { author = a; id = id }) rawComment
|
||||
parse comment location
|
||||
```
|
||||
<pre>
|
||||
/user/bob/comments/42 ==> Some { author = "bob"; id = 42 }
|
||||
/user/tom/comments/35 ==> Some { author = "tom"; id = 35 }
|
||||
/user/sam/ ==> None
|
||||
</pre>
|
||||
*)
|
||||
let map (subValue:'a) (parse:Parser<'a,'b>) : Parser<'b->'c,'c> =
|
||||
let inner { visited = visited; unvisited = unvisited; args = args; value = value } =
|
||||
List.map (State.map value)
|
||||
<| parse { visited = visited
|
||||
unvisited = unvisited
|
||||
args = args
|
||||
value = subValue }
|
||||
inner
|
||||
|
||||
|
||||
|
||||
(** Try a bunch of different path parsers.
|
||||
```
|
||||
type Route
|
||||
= Search of string
|
||||
| Blog of int
|
||||
| User of string
|
||||
| Comment of string*int
|
||||
route =
|
||||
oneOf
|
||||
[ map Search (s "search" </> str)
|
||||
map Blog (s "blog" </> i32)
|
||||
map User (s "user" </> str)
|
||||
map Comment (s "user" </> str </> "comments" </> i32) ]
|
||||
parse route location
|
||||
```
|
||||
<pre>
|
||||
/search/cats ==> Some (Search "cats")
|
||||
/search/ ==> None
|
||||
/blog/42 ==> Some (Blog 42)
|
||||
/blog/cats ==> None
|
||||
/user/sam/ ==> Some (User "sam")
|
||||
/user/bob/comments/42 ==> Some (Comment "bob" 42)
|
||||
/user/tom/comments/35 ==> Some (Comment "tom" 35)
|
||||
/user/ ==> None
|
||||
</pre>
|
||||
*)
|
||||
let oneOf parsers state =
|
||||
List.collect (fun parser -> parser state) parsers
|
||||
|
||||
|
||||
(** A parser that does not consume any path segments.
|
||||
```
|
||||
type BlogRoute = Overview | Post of int
|
||||
blogRoute =
|
||||
oneOf
|
||||
[ map Overview top
|
||||
map Post (s "post" </> i32) ]
|
||||
parse (s "blog" </> blogRoute) location
|
||||
```
|
||||
<pre>
|
||||
/blog/ ==> Some Overview
|
||||
/blog/post/42 ==> Some (Post 42)
|
||||
</pre>
|
||||
*)
|
||||
let top state=
|
||||
[state]
|
||||
|
||||
|
||||
|
||||
(**
|
||||
#### Query parameters
|
||||
Turn query parameters like `?name=tom&age=42` into nice data.
|
||||
|
||||
*)
|
||||
|
||||
type QueryParser<'a,'b> = State<'a> -> State<'b> list
|
||||
|
||||
|
||||
(** Parse some query parameters.
|
||||
```
|
||||
type Route = BlogList (Option string) | BlogPost Int
|
||||
route =
|
||||
oneOf
|
||||
[ map BlogList (s "blog" <?> stringParam "search")
|
||||
map BlogPost (s "blog" </> i32) ]
|
||||
parse route location
|
||||
```
|
||||
<pre>
|
||||
/blog/ ==> Some (BlogList None)
|
||||
/blog/?search=cats ==> Some (BlogList (Some "cats"))
|
||||
/blog/42 ==> Some (BlogPost 42)
|
||||
</pre>
|
||||
*)
|
||||
let inline (<?>) (parser:Parser<_,_>) (queryParser:QueryParser<_,_>) : Parser<_,_> =
|
||||
fun state ->
|
||||
List.collect queryParser (parser state)
|
||||
|
||||
(** Create a custom query parser. You could create parsers like these:
|
||||
```
|
||||
val jsonParam : string -> Decoder a -> QueryParser (Option a -> b) b
|
||||
val enumParam : string -> Map<string,a> -> QueryParser (Option a -> b) b
|
||||
```
|
||||
*)
|
||||
let customParam (key: string) (func:string option -> _) : QueryParser<_,_> =
|
||||
let inner { visited = visited; unvisited = unvisited; args = args; value = value } =
|
||||
[ State.mkState visited unvisited args (value (func (Map.tryFind key args))) ]
|
||||
inner
|
||||
|
||||
|
||||
(** Parse a query parameter as a `string`.
|
||||
```
|
||||
parse (s "blog" <?> stringParam "search") location
|
||||
```
|
||||
<pre>
|
||||
/blog/ ==> Some (Overview None)
|
||||
/blog/?search=cats ==> Some (Overview (Some "cats"))
|
||||
</pre>
|
||||
*)
|
||||
let stringParam name =
|
||||
customParam name id
|
||||
|
||||
let internal intParamHelp =
|
||||
Option.bind
|
||||
(fun value ->
|
||||
match System.Int32.TryParse value with
|
||||
| (true,x) -> Some x
|
||||
| _ -> None)
|
||||
|
||||
(** Parse a query parameter as an `int`. Option you want to show paginated
|
||||
search results. You could have a `start` query parameter to say which result
|
||||
should appear first.
|
||||
```
|
||||
parse (s "results" <?> intParam "start") location
|
||||
```
|
||||
<pre>
|
||||
/results ==> Some None
|
||||
/results?start=10 ==> Some (Some 10)
|
||||
</pre>
|
||||
*)
|
||||
let intParam name =
|
||||
customParam name intParamHelp
|
||||
|
||||
|
||||
// PARSER HELPERS
|
||||
|
||||
let rec internal parseHelp states =
|
||||
match states with
|
||||
| [] ->
|
||||
None
|
||||
| state :: rest ->
|
||||
match state.unvisited with
|
||||
| [] ->
|
||||
Some state.value
|
||||
| [""] ->
|
||||
Some state.value
|
||||
| _ ->
|
||||
parseHelp rest
|
||||
|
||||
let internal splitUrl (url:string) =
|
||||
match List.ofArray <| url.Split([|'/'|]) with
|
||||
| "" :: segments ->
|
||||
segments
|
||||
| segments ->
|
||||
segments
|
||||
|
||||
/// parse a given part of the location
|
||||
let parse (parser:Parser<'a->'a,'a>) url args =
|
||||
{ visited = []
|
||||
unvisited = splitUrl url
|
||||
args = args
|
||||
value = id }
|
||||
|> parser
|
||||
|> parseHelp
|
||||
|
||||
open Fable.Import
|
||||
|
||||
let internal toKeyValuePair (segment:string) =
|
||||
match segment.Split('=') with
|
||||
| [| key; value |] ->
|
||||
Option.tuple (Option.ofFunc JS.decodeURI key) (Option.ofFunc JS.decodeURI value)
|
||||
| _ -> None
|
||||
|
||||
|
||||
let internal parseParams (querystring:string) =
|
||||
querystring.Substring(1).Split('&')
|
||||
|> Seq.map toKeyValuePair
|
||||
|> Seq.choose id
|
||||
|> Map.ofSeq
|
||||
|
||||
open Fable.Import.Browser
|
||||
|
||||
(**
|
||||
#### Parsers
|
||||
Parse based on `location.pathname` and `location.search`. This parser
|
||||
ignores the hash entirely.
|
||||
*)
|
||||
let parsePath (parser:Parser<_,_>) (location:Location) =
|
||||
parse parser location.pathname (parseParams location.search)
|
||||
|
||||
(** Parse based on `location.hash`. This parser ignores the normal
|
||||
path entirely.
|
||||
*)
|
||||
let parseHash (parser:Parser<_,_>) (location:Location) =
|
||||
let hash, search =
|
||||
let hash = location.hash.Substring 1
|
||||
if hash.Contains("?") then
|
||||
let h = hash.Substring(0, hash.IndexOf("?"))
|
||||
h, hash.Substring(h.Length)
|
||||
else
|
||||
hash, "?"
|
||||
|
||||
parse parser (hash) (parseParams search)
|
||||
@@ -1,17 +0,0 @@
|
||||
namespace Elmish.Browser
|
||||
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
|
||||
module Option =
|
||||
|
||||
let tuple a b =
|
||||
match (a,b) with
|
||||
| Some a, Some b -> Some (a,b)
|
||||
| _ -> None
|
||||
|
||||
let ofFunc f arg =
|
||||
try
|
||||
Some (f arg)
|
||||
with _ ->
|
||||
None
|
||||
BIN
Binary file not shown.
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"version": 1,
|
||||
"contentHash": "uinemTtBEefma9DXxwELgV39MqMcHkhZYGwWgxGGeB3fG1273MSQASfUHpQm+0hRjMfwraVPAr560dr8poWQzQ=="
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
-1
@@ -1 +0,0 @@
|
||||
WL53TGF880FRf3ZvoWr9hOE7tKU3ns6M1Ark332QKptJilLYId6gjGseVCcZCAd6JWuGCENdrLQQY4wjiOmq/g==
|
||||
@@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>Fable.Elmish.Debugger</id>
|
||||
<version>1.0.1</version>
|
||||
<authors>Eugene Tolmachev</authors>
|
||||
<owners>Eugene Tolmachev</owners>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<licenseUrl>https://raw.githubusercontent.com/fable-elmish/debugger/master/LICENSE.md</licenseUrl>
|
||||
<projectUrl>https://github.com/fable-elmish/debugger</projectUrl>
|
||||
<iconUrl>https://raw.githubusercontent.com/fable-elmish/debugger/master/docs/files/img/logo.png</iconUrl>
|
||||
<description>Debugger for Elmish apps</description>
|
||||
<tags>fable elmish fsharp debugger</tags>
|
||||
<dependencies>
|
||||
<group targetFramework=".NETStandard1.6">
|
||||
<dependency id="FSharp.Core" version="4.2.3" exclude="Build,Analyzers" />
|
||||
<dependency id="Fable.Core" version="1.3.1" exclude="Build,Analyzers" />
|
||||
<dependency id="Fable.Elmish" version="1.0.0" exclude="Build,Analyzers" />
|
||||
</group>
|
||||
</dependencies>
|
||||
</metadata>
|
||||
</package>
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="..\Meta.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard1.6</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Fable.Import.RemoteDev.fs" />
|
||||
<Compile Include="debugger.fs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="*.fsproj; *.fs" PackagePath="fable\" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\.paket\Paket.Restore.targets" />
|
||||
</Project>
|
||||
@@ -1,71 +0,0 @@
|
||||
namespace Fable.Import
|
||||
|
||||
open System
|
||||
open Fable.Core
|
||||
open Fable.Import.JS
|
||||
open Fable.Import.Browser
|
||||
|
||||
module RemoteDev =
|
||||
module MsgTypes =
|
||||
[<Literal>]
|
||||
let Start = "START"
|
||||
[<Literal>]
|
||||
let Action = "ACTION"
|
||||
[<Literal>]
|
||||
let Dispatch = "DISPATCH"
|
||||
|
||||
module PayloadTypes =
|
||||
[<Literal>]
|
||||
let ImportState = "IMPORT_STATE"
|
||||
[<Literal>]
|
||||
let JumpToState = "JUMP_TO_STATE"
|
||||
[<Literal>]
|
||||
let JumpToAction = "JUMP_TO_ACTION"
|
||||
|
||||
type Options =
|
||||
{ remote : bool
|
||||
port : int
|
||||
hostname : string
|
||||
secure : bool
|
||||
getActionType : (obj->obj) option
|
||||
serialize : obj }
|
||||
|
||||
type Action =
|
||||
{ ``type``: string
|
||||
fields : obj array }
|
||||
|
||||
type LiftedState =
|
||||
{ actionsById : Action array
|
||||
computedStates : obj array
|
||||
currentStateIndex : int
|
||||
nextActionId : int }
|
||||
|
||||
type Payload =
|
||||
{ nextLiftedState : LiftedState
|
||||
``type``: string }
|
||||
|
||||
type Msg =
|
||||
{ state : string
|
||||
action : obj
|
||||
``type`` : string
|
||||
payload : Payload }
|
||||
|
||||
type Listener = Msg -> unit
|
||||
|
||||
type Unsubscribe = unit -> unit
|
||||
|
||||
type Connection =
|
||||
abstract init: obj * obj Option -> unit
|
||||
abstract subscribe: Listener -> Unsubscribe
|
||||
abstract unsubscribe: Unsubscribe
|
||||
abstract send: obj * obj -> unit
|
||||
abstract error: obj -> unit
|
||||
|
||||
[<Import("connect","remotedev")>]
|
||||
let connect : Options -> Connection = jsNative
|
||||
|
||||
[<Import("connectViaExtension","remotedev")>]
|
||||
let connectViaExtension : Options -> Connection = jsNative
|
||||
|
||||
[<Import("extractState","remotedev")>]
|
||||
let extractState : obj -> obj = jsNative
|
||||
@@ -1,139 +0,0 @@
|
||||
namespace Elmish.Debug
|
||||
open Fable.Import.RemoteDev
|
||||
open Fable.Core.JsInterop
|
||||
open Fable.Core
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
module Debugger =
|
||||
open FSharp.Reflection
|
||||
|
||||
let inline private duName (x:'a) =
|
||||
match FSharpValue.GetUnionFields(x, typeof<'a>) with
|
||||
| case, _ -> case.Name
|
||||
|
||||
let inline private getCase cmd : obj =
|
||||
createObj ["type" ==> duName cmd
|
||||
"msg" ==> cmd]
|
||||
|
||||
type ConnectionOptions =
|
||||
| ViaExtension
|
||||
| Remote of address:string * port:int
|
||||
| Secure of address:string * port:int
|
||||
|
||||
let connect =
|
||||
let serialize = createObj ["replacer" ==> fun _ v -> deflate v]
|
||||
|
||||
let fallback = { Options.remote = true; hostname = "remotedev.io"; port = 443; secure = true; getActionType = Some getCase; serialize = serialize }
|
||||
|
||||
function
|
||||
| ViaExtension -> { fallback with remote = false; hostname = "localhost"; port = 8000; secure = false }
|
||||
| Remote (address,port) -> { fallback with hostname = address; port = port; secure = false; getActionType = None }
|
||||
| Secure (address,port) -> { fallback with hostname = address; port = port; getActionType = None }
|
||||
>> connectViaExtension
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
module Program =
|
||||
open Elmish
|
||||
open Fable.Import
|
||||
|
||||
let [<Global>] private setTimeout(f: unit->unit, ms: int): unit = jsNative
|
||||
|
||||
[<PassGenericsAttribute>]
|
||||
let private withDebuggerUsing' (debounce: int option) (connection:Connection) (program : Program<'a,'model,'msg,'view>) : Program<'a,'model,'msg,'view> =
|
||||
let init a =
|
||||
let (model,cmd) = program.init a
|
||||
// simple looking one liner to do a recursive deflate
|
||||
// needed otherwise extension gets F# obj
|
||||
let deflated = model |> toJson |> JS.JSON.parse
|
||||
connection.init (deflated, None)
|
||||
model,cmd
|
||||
|
||||
let mutable timeoutActive = false
|
||||
let mutable store = Unchecked.defaultof<'msg * 'model>
|
||||
|
||||
let update msg model : 'model * Cmd<'msg> =
|
||||
let (model',cmd) = program.update msg model
|
||||
match debounce with
|
||||
| Some debounce ->
|
||||
store <- msg, model'
|
||||
if not timeoutActive then
|
||||
timeoutActive <- true
|
||||
setTimeout((fun () ->
|
||||
let msg, model' = store
|
||||
connection.send (msg, model')
|
||||
timeoutActive <- false), debounce)
|
||||
| None ->
|
||||
connection.send (msg, model')
|
||||
(model',cmd)
|
||||
|
||||
let subscribe model =
|
||||
let sub dispatch =
|
||||
function
|
||||
| (msg:Msg) when msg.``type`` = MsgTypes.Dispatch ->
|
||||
try
|
||||
match msg.payload.``type`` with
|
||||
| PayloadTypes.JumpToAction
|
||||
| PayloadTypes.JumpToState ->
|
||||
let state = inflate<'model> (extractState msg)
|
||||
program.setState state dispatch
|
||||
| PayloadTypes.ImportState ->
|
||||
let state = msg.payload.nextLiftedState.computedStates |> Array.last
|
||||
program.setState (inflate<'model> state?state) dispatch
|
||||
connection.send(null, msg.payload.nextLiftedState)
|
||||
| _ -> ()
|
||||
with ex ->
|
||||
Fable.Import.Browser.console.error ("Unable to process monitor command", msg, ex)
|
||||
| _ -> ()
|
||||
|> connection.subscribe
|
||||
|> ignore
|
||||
|
||||
Cmd.batch
|
||||
[ [sub]
|
||||
program.subscribe model ]
|
||||
|
||||
let onError (text,ex: exn) =
|
||||
program.onError (text, ex)
|
||||
connection.error (text + ex.Message)
|
||||
|
||||
{ program with
|
||||
init = init
|
||||
update = update
|
||||
subscribe = subscribe
|
||||
onError = onError }
|
||||
|
||||
|
||||
[<PassGenericsAttribute>]
|
||||
let withDebuggerUsing connection program : Program<'a,'model,'msg,'view> =
|
||||
withDebuggerUsing' None connection program
|
||||
|
||||
|
||||
[<PassGenericsAttribute>]
|
||||
let withDebuggerAt options program : Program<'a,'model,'msg,'view> =
|
||||
try
|
||||
(Debugger.connect options, program)
|
||||
||> withDebuggerUsing
|
||||
with ex ->
|
||||
Fable.Import.Browser.console.error ("Unable to connect to the monitor, continuing w/o debugger", ex)
|
||||
program
|
||||
|
||||
|
||||
[<PassGenericsAttribute>]
|
||||
let withDebugger (program : Program<'a,'model,'msg,'view>) : Program<'a,'model,'msg,'view> =
|
||||
try
|
||||
((Debugger.connect Debugger.ViaExtension),program)
|
||||
||> withDebuggerUsing
|
||||
with ex ->
|
||||
Fable.Import.Browser.console.error ("Unable to connect to the monitor, continuing w/o debugger", ex)
|
||||
program
|
||||
|
||||
[<PassGenericsAttribute>]
|
||||
/// It will connect to the debugger only once
|
||||
/// within the space of a given time (in milliseconds).
|
||||
/// Intended for apps with many state updates per second, like games.
|
||||
let withDebuggerDebounce (debounce: int) (program : Program<'a,'model,'msg,'view>) : Program<'a,'model,'msg,'view> =
|
||||
try
|
||||
((Debugger.connect Debugger.ViaExtension),program)
|
||||
||> withDebuggerUsing' (Some debounce)
|
||||
with ex ->
|
||||
Fable.Import.Browser.console.error ("Unable to connect to the monitor, continuing w/o debugger", ex)
|
||||
program
|
||||
BIN
Binary file not shown.
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"version": 1,
|
||||
"contentHash": "0PonZgMlQAtiKsK8A6UGhdUFGCjBtYQJBqi8ZRCWQLNA19yA5yN9y5BxyggAiaTa49YFF7qrFO4xk1PzVqoSLw=="
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
cGh6O8L2dEujqaofv5tFgoWSu/uBlSal4QaECXKdhBbvy63VjUC2CSjhWj/Rjygs1jTWN3LAovgAYrMpovo/Gw==
|
||||
@@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>Fable.Elmish.HMR</id>
|
||||
<version>1.0.0</version>
|
||||
<authors>Maxime Mangel</authors>
|
||||
<owners>Maxime Mangel</owners>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<licenseUrl>https://raw.githubusercontent.com/fable-elmish/hmr/master/LICENSE.md</licenseUrl>
|
||||
<projectUrl>https://github.com/fable-elmish/hmr</projectUrl>
|
||||
<iconUrl>https://raw.githubusercontent.com/fable-elmish/hmr/master/docs/files/img/logo.png</iconUrl>
|
||||
<description>Hot Module Replacement for Elmish apps</description>
|
||||
<tags>fable elmish fsharp hmr</tags>
|
||||
<dependencies>
|
||||
<group targetFramework=".NETStandard1.6">
|
||||
<dependency id="FSharp.Core" version="4.2.3" exclude="Build,Analyzers" />
|
||||
<dependency id="Fable.Core" version="1.2.4" exclude="Build,Analyzers" />
|
||||
<dependency id="Fable.Elmish" version="0.9.2" exclude="Build,Analyzers" />
|
||||
</group>
|
||||
</dependencies>
|
||||
</metadata>
|
||||
</package>
|
||||
@@ -1,13 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="..\Meta.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard1.6</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="hmr.fs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="*.fsproj; *.fs" PackagePath="fable\" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\.paket\Paket.Restore.targets" />
|
||||
</Project>
|
||||
@@ -1,65 +0,0 @@
|
||||
namespace Elmish.HMR
|
||||
|
||||
open Elmish
|
||||
open Fable.Core
|
||||
open Fable.Core.JsInterop
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
module Program =
|
||||
|
||||
type IModule =
|
||||
abstract hot: obj with get, set
|
||||
|
||||
let [<Global>] [<Emit("module")>] ``module`` : IModule = jsNative
|
||||
|
||||
type HMRMsg<'msg> =
|
||||
| UserMsg of 'msg
|
||||
| Reload
|
||||
|
||||
type HMRModel<'model> =
|
||||
{ HMRCount : int
|
||||
UserModel : 'model }
|
||||
|
||||
let mutable hmrState : obj = null
|
||||
|
||||
let inline withHMR (program:Elmish.Program<'arg, 'model, 'msg, 'view>) =
|
||||
|
||||
if not (isNull ``module``.hot) then
|
||||
``module``.hot?accept() |> ignore
|
||||
|
||||
let map (model, cmd) =
|
||||
model, cmd |> Cmd.map UserMsg
|
||||
|
||||
let update msg model =
|
||||
let newModel,cmd =
|
||||
match msg with
|
||||
| UserMsg msg ->
|
||||
let newModel, cmd = program.update msg model.UserModel
|
||||
{ model with UserModel = newModel }, cmd
|
||||
| Reload ->
|
||||
{ model with HMRCount = model.HMRCount + 1 }, Cmd.none
|
||||
|> map
|
||||
|
||||
hmrState <- newModel
|
||||
// Store the state
|
||||
newModel, cmd
|
||||
|
||||
let createModel (model, cmd) =
|
||||
{ HMRCount = 0
|
||||
UserModel = model }, cmd
|
||||
|
||||
let init =
|
||||
if isNull hmrState then
|
||||
program.init >> map >> createModel
|
||||
else
|
||||
(fun _ -> unbox<HMRModel<_>> hmrState, Cmd.ofMsg Reload )
|
||||
|
||||
let subs model =
|
||||
Cmd.batch [ program.subscribe model.UserModel |> Cmd.map UserMsg ]
|
||||
|
||||
{ init = init
|
||||
update = update
|
||||
subscribe = subs
|
||||
onError = program.onError
|
||||
setState = fun model dispatch -> program.setState model.UserModel (UserMsg >> dispatch)
|
||||
view = fun model dispatch -> program.view model.UserModel (UserMsg >> dispatch) }
|
||||
BIN
Binary file not shown.
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"version": 1,
|
||||
"contentHash": "iv5hAfA4Mq4wpTQEO9NNVj6h/MeKTcRp9XARsJ7Bn/ktP1smMt4E4zOPL0hRY0WPs4XDzejfWfhtQ5uA9cztSg=="
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Loaded 100 of 836 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user