mirror of
https://github.com/apple/pkl.git
synced 2026-07-16 10:02:46 +02:00
Apply pkl formatter to codebase (#1236)
This applies the Pkl formatter to `stdlib/` and `.circleci/`
This commit is contained in:
@@ -17,8 +17,8 @@
|
||||
amends "package://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.circleci@1.2.0#/PklCI.pkl"
|
||||
|
||||
import "jobs/BuildNativeJob.pkl"
|
||||
import "jobs/GradleCheckJob.pkl"
|
||||
import "jobs/DeployJob.pkl"
|
||||
import "jobs/GradleCheckJob.pkl"
|
||||
import "jobs/SimpleGradleJob.pkl"
|
||||
|
||||
local prbJobs: Listing<String> = gradleCheckJobs.keys.toListing()
|
||||
@@ -130,15 +130,18 @@ jobs {
|
||||
[jobName] = job.job
|
||||
}
|
||||
["bench"] = new SimpleGradleJob { command = "bench:jmh" }.job
|
||||
["gradle-compatibility"] = new SimpleGradleJob {
|
||||
["gradle-compatibility"] =
|
||||
new SimpleGradleJob {
|
||||
name = "gradle compatibility"
|
||||
command = #"""
|
||||
command =
|
||||
#"""
|
||||
:pkl-gradle:build \
|
||||
:pkl-gradle:compatibilityTestReleases
|
||||
"""#
|
||||
}.job
|
||||
["deploy-snapshot"] = new DeployJob { command = "publishToSonatype" }.job
|
||||
["deploy-release"] = new DeployJob {
|
||||
["deploy-release"] =
|
||||
new DeployJob {
|
||||
isRelease = true
|
||||
command = "publishToSonatype closeAndReleaseSonatypeStagingRepository"
|
||||
}.job
|
||||
@@ -150,7 +153,8 @@ jobs {
|
||||
new AttachWorkspaceStep { at = "." }
|
||||
new RunStep {
|
||||
name = "Publish release on GitHub"
|
||||
command = #"""
|
||||
command =
|
||||
#"""
|
||||
# exclude build_artifacts.txt from publish
|
||||
rm -f */build/executable/*.build_artifacts.txt
|
||||
find */build/executable/* -type d | xargs rm -rf
|
||||
|
||||
@@ -44,7 +44,8 @@ local setupLinuxEnvironment: Config.RunStep =
|
||||
new {
|
||||
name = "Set up environment"
|
||||
shell = "#!/bin/bash -exo pipefail"
|
||||
command = new Listing {
|
||||
command =
|
||||
new Listing {
|
||||
#"""
|
||||
sed -ie '/\[ol8_codeready_builder\]/,/^$/s/enabled=0/enabled=1/g' /etc/yum.repos.d/oracle-linux-ol8.repo \
|
||||
&& microdnf -y install util-linux tree coreutils-single findutils curl tar gzip git zlib-devel gcc-c++ make openssl glibc-langpack-en libstdc++-static \
|
||||
@@ -53,7 +54,11 @@ local setupLinuxEnvironment: Config.RunStep =
|
||||
|
||||
# install jdk
|
||||
curl -Lf \
|
||||
https://github.com/adoptium/temurin\#(module.majorJdkVersion)-binaries/releases/download/\#(module.jdkGitHubReleaseName)/OpenJDK\#(module.majorJdkVersion)U-jdk_\#(if (arch == "amd64") "x64" else "aarch64")_linux_hotspot_\#(module.jdkVersionAlt).tar.gz -o /tmp/jdk.tar.gz
|
||||
https://github.com/adoptium/temurin\#(module.majorJdkVersion)-binaries/releases/download/\#(module
|
||||
.jdkGitHubReleaseName)/OpenJDK\#(module.majorJdkVersion)U-jdk_\#(if (arch == "amd64")
|
||||
"x64"
|
||||
else
|
||||
"aarch64")_linux_hotspot_\#(module.jdkVersionAlt).tar.gz -o /tmp/jdk.tar.gz
|
||||
|
||||
mkdir /jdk \
|
||||
&& cd /jdk \
|
||||
@@ -99,15 +104,18 @@ local setupLinuxEnvironment: Config.RunStep =
|
||||
}.join("\n\n")
|
||||
}
|
||||
|
||||
local setupMacEnvironment: Config.RunStep =
|
||||
new {
|
||||
local setupMacEnvironment: Config.RunStep = new {
|
||||
name = "Set up environment"
|
||||
shell = "#!/bin/bash -exo pipefail"
|
||||
command =
|
||||
#"""
|
||||
# install jdk
|
||||
curl -Lf \
|
||||
https://github.com/adoptium/temurin\#(module.majorJdkVersion)-binaries/releases/download/\#(module.jdkGitHubReleaseName)/OpenJDK\#(module.majorJdkVersion)U-jdk_\#(if (arch == "amd64") "x64" else "aarch64")_mac_hotspot_\#(module.jdkVersionAlt).tar.gz -o /tmp/jdk.tar.gz
|
||||
https://github.com/adoptium/temurin\#(module.majorJdkVersion)-binaries/releases/download/\#(module
|
||||
.jdkGitHubReleaseName)/OpenJDK\#(module.majorJdkVersion)U-jdk_\#(if (arch == "amd64")
|
||||
"x64"
|
||||
else
|
||||
"aarch64")_mac_hotspot_\#(module.jdkVersionAlt).tar.gz -o /tmp/jdk.tar.gz
|
||||
|
||||
mkdir $HOME/jdk \
|
||||
&& cd $HOME/jdk \
|
||||
@@ -134,7 +142,8 @@ steps {
|
||||
when (arch == "amd64") {
|
||||
new Config.RunStep {
|
||||
name = "Installing Rosetta 2"
|
||||
command = """
|
||||
command =
|
||||
"""
|
||||
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
|
||||
"""
|
||||
}
|
||||
@@ -146,7 +155,8 @@ steps {
|
||||
when (module.os == "windows") {
|
||||
shell = "bash.exe"
|
||||
}
|
||||
command = #"""
|
||||
command =
|
||||
#"""
|
||||
export PATH=~/staticdeps/bin:$PATH
|
||||
./gradlew \#(module.gradleArgs) \#(project):buildNative
|
||||
"""#
|
||||
|
||||
@@ -27,9 +27,7 @@ os: "macOS"|"linux"|"windows"
|
||||
/// The version of Java to use.
|
||||
javaVersion: "17.0" | "21.0"
|
||||
|
||||
fixed javaVersionFull =
|
||||
if (javaVersion == "17.0") "17.0.9+9"
|
||||
else "21.0.5+11"
|
||||
fixed javaVersionFull = if (javaVersion == "17.0") "17.0.9+9" else "21.0.5+11"
|
||||
|
||||
fixed jdkVersionAlt = javaVersionFull.replaceLast("+", "_")
|
||||
|
||||
@@ -38,12 +36,15 @@ fixed majorJdkVersion = javaVersionFull.split(".").first
|
||||
fixed jdkGitHubReleaseName =
|
||||
let (ver =
|
||||
// 17.0.9+9 is missing some binaries (see https://github.com/adoptium/adoptium-support/issues/994)
|
||||
if (javaVersionFull == "17.0.9+9" && os == "windows") "jdk-17.0.9+9.1"
|
||||
else "jdk-\(javaVersionFull)"
|
||||
if (javaVersionFull == "17.0.9+9" && os == "windows")
|
||||
"jdk-17.0.9+9.1"
|
||||
else
|
||||
"jdk-\(javaVersionFull)"
|
||||
)
|
||||
URI.encodeComponent(ver)
|
||||
|
||||
fixed gradleArgs = new Listing {
|
||||
fixed gradleArgs =
|
||||
new Listing {
|
||||
"--info"
|
||||
"--stacktrace"
|
||||
"-DtestReportsDir=${HOME}/test-results"
|
||||
@@ -84,7 +85,8 @@ job: Config.Job = new {
|
||||
new Config.RunStep {
|
||||
name = "Set up environment"
|
||||
shell = "bash.exe"
|
||||
command = #"""
|
||||
command =
|
||||
#"""
|
||||
# install jdk
|
||||
curl -Lf \
|
||||
https://github.com/adoptium/temurin\#(majorJdkVersion)-binaries/releases/download/\#(jdkGitHubReleaseName)/OpenJDK\#(majorJdkVersion)U-jdk_x64_windows_hotspot_\#(jdkVersionAlt).zip -o /tmp/jdk.zip
|
||||
|
||||
@@ -28,7 +28,8 @@ javaVersion = "21.0"
|
||||
steps {
|
||||
new Config.RunStep {
|
||||
name = module.name
|
||||
command = """
|
||||
command =
|
||||
"""
|
||||
./gradlew \(module.gradleArgs) \(module.command)
|
||||
"""
|
||||
}
|
||||
|
||||
+313
-313
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -3,7 +3,7 @@ Expected value of type `*RemoteDependency|Project(isValidLoadDependency)`, but g
|
||||
Value: new ModuleClass { package = null; tests {}; dependencies {}; evaluatorSetting...
|
||||
|
||||
xxx | dependencies: Mapping<String(!contains("/")), *RemoteDependency | Project(isValidLoadDependency)>
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
at pkl.Project#dependencies (pkl:Project)
|
||||
|
||||
* Value is not of type `Project(isValidLoadDependency)` because:
|
||||
|
||||
+11
-10
@@ -66,11 +66,11 @@
|
||||
@ModuleInfo { minPklVersion = "0.30.0" }
|
||||
module pkl.DocPackageInfo
|
||||
|
||||
// used by doc comments
|
||||
import "pkl:DocPackageInfo"
|
||||
import "pkl:Project"
|
||||
import "pkl:reflect"
|
||||
import "pkl:semver"
|
||||
// used by doc comments
|
||||
import "pkl:Project"
|
||||
import "pkl:DocPackageInfo"
|
||||
|
||||
/// The name of this package.
|
||||
name: PackageName
|
||||
@@ -173,19 +173,20 @@ class PackageDependency {
|
||||
}
|
||||
|
||||
/// A package name.
|
||||
typealias PackageName =
|
||||
String(!contains("/"))
|
||||
typealias PackageName = String(!contains("/"))
|
||||
|
||||
/// A package version.
|
||||
typealias PackageVersion =
|
||||
String(semver.isValid(this))
|
||||
typealias PackageVersion = String(semver.isValid(this))
|
||||
|
||||
@Unlisted
|
||||
fixed overview: String(!isBlank) = moduleMirror.docComment ??
|
||||
throw("""
|
||||
fixed overview: String(!isBlank) =
|
||||
moduleMirror.docComment
|
||||
?? throw(
|
||||
"""
|
||||
Missing overview documentation for package `\(name)`.
|
||||
To fix this problem, add a doc comment to `doc-package-info.pkl` (above `amends "pkl:DocPackageInfo"`).
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@Unlisted
|
||||
fixed overviewImports: Map<String, Uri> = moduleMirror.imports
|
||||
|
||||
@@ -118,19 +118,15 @@ externalResourceReaders: Mapping<String, ExternalReader>?
|
||||
@Since { version = "0.30.0" }
|
||||
traceMode: ("compact" | "pretty")?
|
||||
|
||||
const local hostnameRegex = Regex(#"https?://([^/?#]*)"#)
|
||||
local const hostnameRegex = Regex(#"https?://([^/?#]*)"#)
|
||||
|
||||
const local hasNonEmptyHostname = (it: String) ->
|
||||
local const hasNonEmptyHostname = (it: String) ->
|
||||
let (hostname = hostnameRegex.findMatchesIn(it).getOrNull(0)?.groups?.getOrNull(1)?.value)
|
||||
hostname != null && hostname.length > 0
|
||||
|
||||
/// A key or value in [Http.rewrites].
|
||||
@Since { version = "0.29.0" }
|
||||
typealias HttpRewrite = String(
|
||||
startsWith(Regex("https?://")),
|
||||
endsWith("/"),
|
||||
hasNonEmptyHostname
|
||||
)
|
||||
typealias HttpRewrite = String(startsWith(Regex("https?://")), endsWith("/"), hasNonEmptyHostname)
|
||||
|
||||
/// Settings that control how Pkl talks to HTTP(S) servers.
|
||||
class Http {
|
||||
|
||||
+7
-6
@@ -99,7 +99,7 @@ local isValidLoadDependency = (it: Project) ->
|
||||
&& it != module
|
||||
&& it.package != null
|
||||
|
||||
const local function isUriLocal(uri1: Uri, uri2: Uri): Boolean =
|
||||
local const function isUriLocal(uri1: Uri, uri2: Uri): Boolean =
|
||||
// This is an imperfect check; should also check that the URIs have the same authority.
|
||||
// We should improve this if/when there is a URI library in the stdlib.
|
||||
uri1.substring(0, uri1.indexOf(":")) == uri2.substring(0, uri2.indexOf(":"))
|
||||
@@ -201,7 +201,7 @@ local isFileBasedProject = projectFileUri.startsWith("file:")
|
||||
evaluatorSettings: EvaluatorSettingsModule(
|
||||
(modulePath != null).implies(isFileBasedProject),
|
||||
(rootDir != null).implies(isFileBasedProject),
|
||||
(moduleCacheDir != null).implies(isFileBasedProject)
|
||||
(moduleCacheDir != null).implies(isFileBasedProject),
|
||||
)
|
||||
|
||||
/// The URI of the PklProject file.
|
||||
@@ -224,11 +224,12 @@ function newInstance(enclosingModule: Module): Project = new {
|
||||
projectFileUri = reflect.Module(enclosingModule).uri
|
||||
}
|
||||
|
||||
const local hasVersion = (it: Uri) ->
|
||||
local const hasVersion = (it: Uri) ->
|
||||
let (versionSep = it.lastIndexOf("@"))
|
||||
if (versionSep == -1) false
|
||||
else let (version = it.drop(versionSep + 1))
|
||||
semver.parseOrNull(version) != null
|
||||
if (versionSep == -1)
|
||||
false
|
||||
else
|
||||
let (version = it.drop(versionSep + 1)) semver.parseOrNull(version) != null
|
||||
|
||||
typealias PackageUri = Uri(startsWith("package:"), hasVersion)
|
||||
|
||||
|
||||
+138
-42
@@ -21,8 +21,8 @@
|
||||
module pkl.base
|
||||
|
||||
import "pkl:jsonnet"
|
||||
import "pkl:xml"
|
||||
import "pkl:protobuf"
|
||||
import "pkl:xml"
|
||||
|
||||
/// The top type of the type hierarchy.
|
||||
///
|
||||
@@ -96,15 +96,26 @@ abstract external class Module {
|
||||
value = outer
|
||||
renderer =
|
||||
let (format = read?("prop:pkl.outputFormat") ?? "pcf")
|
||||
if (format == "json") new JsonRenderer {}
|
||||
else if (format == "jsonnet") new jsonnet.Renderer {}
|
||||
else if (format == "pcf") new PcfRenderer {}
|
||||
else if (format == "plist") new PListRenderer {}
|
||||
else if (format == "properties") new PropertiesRenderer {}
|
||||
else if (format == "textproto") new protobuf.Renderer {}
|
||||
else if (format == "xml") new xml.Renderer {}
|
||||
else if (format == "yaml") new YamlRenderer {}
|
||||
else throw("Unknown output format: `\(format)`. Supported formats are `json`, `jsonnet`, `pcf`, `plist`, `properties`, `textproto`, `xml`, `yaml`.")
|
||||
if (format == "json")
|
||||
new JsonRenderer {}
|
||||
else if (format == "jsonnet")
|
||||
new jsonnet.Renderer {}
|
||||
else if (format == "pcf")
|
||||
new PcfRenderer {}
|
||||
else if (format == "plist")
|
||||
new PListRenderer {}
|
||||
else if (format == "properties")
|
||||
new PropertiesRenderer {}
|
||||
else if (format == "textproto")
|
||||
new protobuf.Renderer {}
|
||||
else if (format == "xml")
|
||||
new xml.Renderer {}
|
||||
else if (format == "yaml")
|
||||
new YamlRenderer {}
|
||||
else
|
||||
throw(
|
||||
"Unknown output format: `\(format)`. Supported formats are `json`, `jsonnet`, `pcf`, `plist`, `properties`, `textproto`, `xml`, `yaml`."
|
||||
)
|
||||
text = renderer.renderDocument(value)
|
||||
bytes = text.encodeToBytes("UTF-8")
|
||||
}
|
||||
@@ -179,7 +190,18 @@ class SourceCode extends Annotation {
|
||||
/// - `"x = 42"` is valid source code for language `"Pkl"`.
|
||||
/// - `"42"` is valid source code for language `"PklExpr"`.
|
||||
/// - `"42"` is valid source code for language `"Pkl"` with [prefix] `"x = "`.
|
||||
language: "Go"|"HTML"|"Java"|"JavaScript"|"Markdown"|"Pkl"|"PklExpr"|"Python"|"Ruby"|"SQL"|"Swift"|String
|
||||
language: "Go"
|
||||
| "HTML"
|
||||
| "Java"
|
||||
| "JavaScript"
|
||||
| "Markdown"
|
||||
| "Pkl"
|
||||
| "PklExpr"
|
||||
| "Python"
|
||||
| "Ruby"
|
||||
| "SQL"
|
||||
| "Swift"
|
||||
| String
|
||||
|
||||
/// A source code prefix to help tools understand the source code.
|
||||
///
|
||||
@@ -1353,17 +1375,26 @@ external class String extends Any {
|
||||
/// Replaces the first occurrence of [pattern] in this string with the return value of [mapper].
|
||||
///
|
||||
/// Returns this string unchanged if [pattern] does not occur in this string.
|
||||
external function replaceFirstMapped(pattern: String|Regex, mapper: (RegexMatch) -> String): String
|
||||
external function replaceFirstMapped(
|
||||
pattern: String | Regex,
|
||||
mapper: (RegexMatch) -> String,
|
||||
): String
|
||||
|
||||
/// Replaces the last occurrence of [pattern] in this string with the return value of [mapper].
|
||||
///
|
||||
/// Returns this string unchanged if [pattern] does not occur in this string.
|
||||
external function replaceLastMapped(pattern: String|Regex, mapper: (RegexMatch) -> String): String
|
||||
external function replaceLastMapped(
|
||||
pattern: String | Regex,
|
||||
mapper: (RegexMatch) -> String,
|
||||
): String
|
||||
|
||||
/// Replaces all occurrences of [pattern] in this string with the return value of [mapper].
|
||||
///
|
||||
/// Returns this string unchanged if [pattern] does not occur in this string.
|
||||
external function replaceAllMapped(pattern: String|Regex, mapper: (RegexMatch) -> String): String
|
||||
external function replaceAllMapped(
|
||||
pattern: String | Regex,
|
||||
mapper: (RegexMatch) -> String,
|
||||
): String
|
||||
|
||||
/// Replaces the characters between [start] and [exclusiveEnd] with [replacement].
|
||||
///
|
||||
@@ -1630,7 +1661,8 @@ external class Duration extends Any {
|
||||
}
|
||||
|
||||
/// The unit of a [DataSize].
|
||||
typealias DataSizeUnit = "b"|"kb"|"kib"|"mb"|"mib"|"gb"|"gib"|"tb"|"tib"|"pb"|"pib"
|
||||
typealias DataSizeUnit =
|
||||
"b" | "kb" | "kib" | "mb" | "mib" | "gb" | "gib" | "tb" | "tib" | "pb" | "pib"
|
||||
|
||||
/// A quantity of binary data, represented as a [value] (e.g. `30.5`) and [unit] (e.g. `mb`).
|
||||
external class DataSize extends Any {
|
||||
@@ -2018,7 +2050,10 @@ class Listing<out Element> extends Object {
|
||||
/// Folds this listing in iteration order using [operator], starting with [initial].
|
||||
///
|
||||
/// The first parameter of [operator] is the zero-based index of the current element.
|
||||
external function foldIndexed<Result>(initial: Result, operator: (Int, Result, Element) -> Result): Result
|
||||
external function foldIndexed<Result>(
|
||||
initial: Result,
|
||||
operator: (Int, Result, Element) -> Result,
|
||||
): Result
|
||||
|
||||
/// Converts the elements of this listing to strings and concatenates them inserting [separator] between elements.
|
||||
external function join(separator: String): String
|
||||
@@ -2119,13 +2154,15 @@ external class Function3<in Param1, in Param2, in Param3, out Result> extends Fu
|
||||
}
|
||||
|
||||
/// A function literal with four parameters.
|
||||
external class Function4<in Param1, in Param2, in Param3, in Param4, out Result> extends Function<Result> {
|
||||
external class Function4<in Param1, in Param2, in Param3, in Param4, out Result>
|
||||
extends Function<Result> {
|
||||
@AlsoKnownAs { names { "call"; "invoke" } }
|
||||
external function apply(p1: Param1, p2: Param2, p3: Param3, p4: Param4): Result
|
||||
}
|
||||
|
||||
/// A function literal with five parameters.
|
||||
external class Function5<in Param1, in Param2, in Param3, in Param4, in Param5, out Result> extends Function<Result> {
|
||||
external class Function5<in Param1, in Param2, in Param3, in Param4, in Param5, out Result>
|
||||
extends Function<Result> {
|
||||
@AlsoKnownAs { names { "call"; "invoke" } }
|
||||
external function apply(p1: Param1, p2: Param2, p3: Param3, p4: Param4, p5: Param5): Result
|
||||
}
|
||||
@@ -2312,7 +2349,9 @@ abstract external class Collection<out Element> extends Any {
|
||||
/// Same as [split()] but returns [null] if [index] is outside range `0`..[length].
|
||||
abstract function splitOrNull(index: Int): Pair<Collection<Element>, Collection<Element>>?
|
||||
|
||||
abstract function partition(predicate: (Element) -> Boolean): Pair<Collection<Element>, Collection<Element>>
|
||||
abstract function partition(
|
||||
predicate: (Element) -> Boolean,
|
||||
): Pair<Collection<Element>, Collection<Element>>
|
||||
|
||||
/// The zero-based index of the first occurrence of [element] in this collection.
|
||||
///
|
||||
@@ -2510,7 +2549,9 @@ abstract external class Collection<out Element> extends Any {
|
||||
/// List(1, 2, 3).mapNonNull((n) -> if (n.isOdd) null else n + 2) == List(4)
|
||||
/// ```
|
||||
@AlsoKnownAs { names { "filterMap" } }
|
||||
abstract function mapNonNull<Result>(transform: (Element) -> Result): Collection<Result(this != null)>
|
||||
abstract function mapNonNull<Result>(
|
||||
transform: (Element) -> Result,
|
||||
): Collection<Result(this != null)>
|
||||
|
||||
/// Transforms this collection by applying [transform] to each element and removing resulting [null] elements.
|
||||
///
|
||||
@@ -2522,7 +2563,9 @@ abstract external class Collection<out Element> extends Any {
|
||||
/// List(1, 2, 3, 4, null).mapNonNullIndexed((i, n) -> if (n?.isOdd ?? true) null else n * i) == List(2, 12)
|
||||
/// ```
|
||||
@Since { version = "0.29.0" }
|
||||
abstract function mapNonNullIndexed<Result>(transform: (Int, Element) -> Result): Collection<Result(this != null)>
|
||||
abstract function mapNonNullIndexed<Result>(
|
||||
transform: (Int, Element) -> Result,
|
||||
): Collection<Result(this != null)>
|
||||
|
||||
/// Applies a collection-generating [transform] to each element in this collection
|
||||
/// and concatenates the resulting collections.
|
||||
@@ -2536,7 +2579,9 @@ abstract external class Collection<out Element> extends Any {
|
||||
/// [transform] takes two arguments: the index of the element, and the element itself.
|
||||
///
|
||||
/// Throws if [transform] produces a non-collection value.
|
||||
abstract function flatMapIndexed<Result>(transform: (Int, Element) -> Collection<Result>): Collection<Result>
|
||||
abstract function flatMapIndexed<Result>(
|
||||
transform: (Int, Element) -> Collection<Result>,
|
||||
): Collection<Result>
|
||||
|
||||
/// Concatenates the elements in this collection, each of which must itself be a collection.
|
||||
///
|
||||
@@ -2588,7 +2633,10 @@ abstract external class Collection<out Element> extends Any {
|
||||
/// Folds this collection in iteration order using [operator], starting with [initial].
|
||||
///
|
||||
/// The first parameter of [operator] is the zero-based index of the current element.
|
||||
abstract function foldIndexed<Result>(initial: Result, operator: (Int, Result, Element) -> Result): Result
|
||||
abstract function foldIndexed<Result>(
|
||||
initial: Result,
|
||||
operator: (Int, Result, Element) -> Result,
|
||||
): Result
|
||||
|
||||
/// Folds this collection in iteration order using [operator], starting with the first element.
|
||||
///
|
||||
@@ -2662,7 +2710,9 @@ abstract external class Collection<out Element> extends Any {
|
||||
abstract function maxWith(comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int): Element
|
||||
|
||||
/// Same as [maxWith()] but returns [null] if this collection is empty.
|
||||
abstract function maxWithOrNull(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): Element?
|
||||
abstract function maxWithOrNull(
|
||||
comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int,
|
||||
): Element?
|
||||
|
||||
/// Sorts this collection of [Comparable] elements in ascending order.
|
||||
///
|
||||
@@ -2687,7 +2737,9 @@ abstract external class Collection<out Element> extends Any {
|
||||
/// ```
|
||||
/// List(1, 2, 3).sortWith((a, b) -> a > b)) == List(3, 2, 1)
|
||||
/// ```
|
||||
abstract function sortWith(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): Collection<Element>
|
||||
abstract function sortWith(
|
||||
comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int,
|
||||
): Collection<Element>
|
||||
|
||||
/// Reverses the order of elements in this collection.
|
||||
abstract function reverse(): Collection<Element>
|
||||
@@ -2725,7 +2777,10 @@ abstract external class Collection<out Element> extends Any {
|
||||
abstract function toSet(): Set<Element>
|
||||
|
||||
/// Converts this collection to a map by extracting a key and value from each element using the given functions.
|
||||
abstract function toMap<Key, Value>(keyExtractor: (Element) -> Key, valueExtractor: (Element) -> Value): Map<Key, Value>
|
||||
abstract function toMap<Key, Value>(
|
||||
keyExtractor: (Element) -> Key,
|
||||
valueExtractor: (Element) -> Value,
|
||||
): Map<Key, Value>
|
||||
|
||||
/// Converts this collection to a [Listing].
|
||||
abstract function toListing(): Listing<Element>
|
||||
@@ -2959,8 +3014,12 @@ external class List<out Element> extends Collection<Element> {
|
||||
external function mapIndexed<Result>(transform: (Int, Element) -> Result): List<Result>
|
||||
|
||||
@Since { version = "0.29.0" }
|
||||
external function mapNonNullIndexed<Result>(transform: (Int, Element) -> Result): List<Result(this != null)>
|
||||
external function flatMapIndexed<Result>(transform: (Int, Element) -> Collection<Result>): List<Result>
|
||||
external function mapNonNullIndexed<Result>(
|
||||
transform: (Int, Element) -> Result,
|
||||
): List<Result(this != null)>
|
||||
external function flatMapIndexed<Result>(
|
||||
transform: (Int, Element) -> Collection<Result>,
|
||||
): List<Result>
|
||||
|
||||
external function filterIsInstance<Type>(clazz: Class<Type>): List<Type>
|
||||
|
||||
@@ -3028,12 +3087,20 @@ external class List<out Element> extends Collection<Element> {
|
||||
/// Replaces the elements between indices [range] and [exclusiveEnd] with [replacement].
|
||||
///
|
||||
/// Throws if [range] or [exclusiveEnd] is outside the bounds of this list.
|
||||
external function replaceRange<Other>(start: Int, exclusiveEnd: Int, replacement: Collection<Other>): List<Element|Other>
|
||||
external function replaceRange<Other>(
|
||||
start: Int,
|
||||
exclusiveEnd: Int,
|
||||
replacement: Collection<Other>,
|
||||
): List<Element | Other>
|
||||
|
||||
/// Replaces the elements between indices [range] and [exclusiveEnd] with [replacement].
|
||||
///
|
||||
/// Returns [null] if [range] or [exclusiveEnd] is outside the bounds of this list.
|
||||
external function replaceRangeOrNull<Other>(start: Int, exclusiveEnd: Int, replacement: Collection<Other>): List<Element|Other>?
|
||||
external function replaceRangeOrNull<Other>(
|
||||
start: Int,
|
||||
exclusiveEnd: Int,
|
||||
replacement: Collection<Other>,
|
||||
): List<Element | Other>?
|
||||
|
||||
external function find(predicate: (Element) -> Boolean): Element
|
||||
external function findOrNull(predicate: (Element) -> Boolean): Element?
|
||||
@@ -3067,7 +3134,10 @@ external class List<out Element> extends Collection<Element> {
|
||||
|
||||
external function fold<Result>(initial: Result, operator: (Result, Element) -> Result): Result
|
||||
external function foldBack<Result>(initial: Result, operator: (Element, Result) -> Result): Result
|
||||
external function foldIndexed<Result>(initial: Result, operator: (Int, Result, Element) -> Result): Result
|
||||
external function foldIndexed<Result>(
|
||||
initial: Result,
|
||||
operator: (Int, Result, Element) -> Result,
|
||||
): Result
|
||||
|
||||
external function reduce<Result>(operator: (Element | Result, Element) -> Result): Result
|
||||
external function reduceOrNull<Result>(operator: (Element | Result, Element) -> Result): Result?
|
||||
@@ -3108,7 +3178,10 @@ external class List<out Element> extends Collection<Element> {
|
||||
|
||||
external function toSet(): Set<Element>
|
||||
|
||||
external function toMap<Key, Value>(keyExtractor: (Element) -> Key, valueExtractor: (Element) -> Value): Map<Key, Value>
|
||||
external function toMap<Key, Value>(
|
||||
keyExtractor: (Element) -> Key,
|
||||
valueExtractor: (Element) -> Value,
|
||||
): Map<Key, Value>
|
||||
|
||||
external function toListing(): Listing<Element>
|
||||
|
||||
@@ -3176,8 +3249,12 @@ external class Set<out Element> extends Collection<Element> {
|
||||
external function mapIndexed<Result>(transform: (Int, Element) -> Result): Set<Result>
|
||||
|
||||
@Since { version = "0.29.0" }
|
||||
external function mapNonNullIndexed<Result>(transform: (Int, Element) -> Result): Set<Result(this != null)>
|
||||
external function flatMapIndexed<Result>(transform: (Int, Element) -> Collection<Result>): Set<Result>
|
||||
external function mapNonNullIndexed<Result>(
|
||||
transform: (Int, Element) -> Result,
|
||||
): Set<Result(this != null)>
|
||||
external function flatMapIndexed<Result>(
|
||||
transform: (Int, Element) -> Collection<Result>,
|
||||
): Set<Result>
|
||||
|
||||
external function filterIsInstance<Type>(clazz: Class<Type>): Set<Type>
|
||||
|
||||
@@ -3208,7 +3285,10 @@ external class Set<out Element> extends Collection<Element> {
|
||||
|
||||
external function fold<Result>(initial: Result, operator: (Result, Element) -> Result): Result
|
||||
external function foldBack<Result>(initial: Result, operator: (Element, Result) -> Result): Result
|
||||
external function foldIndexed<Result>(initial: Result, operator: (Int, Result, Element) -> Result): Result
|
||||
external function foldIndexed<Result>(
|
||||
initial: Result,
|
||||
operator: (Int, Result, Element) -> Result,
|
||||
): Result
|
||||
|
||||
external function reduce<Result>(operator: (Element | Result, Element) -> Result): Result
|
||||
external function reduceOrNull<Result>(operator: (Element | Result, Element) -> Result): Result?
|
||||
@@ -3224,7 +3304,9 @@ external class Set<out Element> extends Collection<Element> {
|
||||
external function minByOrNull(selector: (Element) -> Int): Element?
|
||||
|
||||
external function minWith(comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int): Element
|
||||
external function minWithOrNull(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): Element?
|
||||
external function minWithOrNull(
|
||||
comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int,
|
||||
): Element?
|
||||
|
||||
external max: Element
|
||||
external maxOrNull: Element?
|
||||
@@ -3233,11 +3315,15 @@ external class Set<out Element> extends Collection<Element> {
|
||||
external function maxByOrNull(selector: (Element) -> Int): Element?
|
||||
|
||||
external function maxWith(comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int): Element
|
||||
external function maxWithOrNull(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): Element?
|
||||
external function maxWithOrNull(
|
||||
comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int,
|
||||
): Element?
|
||||
|
||||
external function sort(): List<Element>
|
||||
external function sortBy(selector: (Element) -> Comparable): List<Element>
|
||||
external function sortWith(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): List<Element>
|
||||
external function sortWith(
|
||||
comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int,
|
||||
): List<Element>
|
||||
|
||||
external function reverse(): List<Element>
|
||||
|
||||
@@ -3249,7 +3335,10 @@ external class Set<out Element> extends Collection<Element> {
|
||||
|
||||
external function toSet(): Set<Element>
|
||||
|
||||
external function toMap<Key, Value>(keyExtractor: (Element) -> Key, valueExtractor: (Element) -> Value): Map<Key, Value>
|
||||
external function toMap<Key, Value>(
|
||||
keyExtractor: (Element) -> Key,
|
||||
valueExtractor: (Element) -> Value,
|
||||
): Map<Key, Value>
|
||||
|
||||
external function toListing(): Listing<Element>
|
||||
|
||||
@@ -3313,7 +3402,10 @@ external class Map<out Key, out Value> extends Any {
|
||||
external function containsValue(value: Any): Boolean
|
||||
|
||||
/// Adds or updates [key] to [value].
|
||||
external function put<NewKey, NewValue>(key: NewKey, value: NewValue): Map<NewKey|Key, NewValue|Value>
|
||||
external function put<NewKey, NewValue>(
|
||||
key: NewKey,
|
||||
value: NewValue,
|
||||
): Map<NewKey | Key, NewValue | Value>
|
||||
|
||||
/// Removes the map entry with the given key.
|
||||
///
|
||||
@@ -3327,7 +3419,9 @@ external class Map<out Key, out Value> extends Any {
|
||||
external function fold<Result>(initial: Result, operator: (Result, Key, Value) -> Result): Result
|
||||
|
||||
/// Transforms the entries of this map using [transform].
|
||||
external function map<NewKey, NewValue>(transform: (Key, Value) -> Pair<NewKey, NewValue>): Map<NewKey, NewValue>
|
||||
external function map<NewKey, NewValue>(
|
||||
transform: (Key, Value) -> Pair<NewKey, NewValue>,
|
||||
): Map<NewKey, NewValue>
|
||||
|
||||
/// Transforms the keys of this map using [transform].
|
||||
external function mapKeys<NewKey>(transform: (Key, Value) -> NewKey): Map<NewKey, Value>
|
||||
@@ -3336,7 +3430,9 @@ external class Map<out Key, out Value> extends Any {
|
||||
external function mapValues<NewValue>(transform: (Key, Value) -> NewValue): Map<Key, NewValue>
|
||||
|
||||
/// Applies a map-generating [transform] to each map entry and concatenates the resulting maps.
|
||||
external function flatMap<NewKey, NewValue>(transform: (Key, Value) -> Map<NewKey, NewValue>): Map<NewKey, NewValue>
|
||||
external function flatMap<NewKey, NewValue>(
|
||||
transform: (Key, Value) -> Map<NewKey, NewValue>,
|
||||
): Map<NewKey, NewValue>
|
||||
|
||||
/// Tells if [predicate] holds for every entry of this map.
|
||||
///
|
||||
|
||||
@@ -79,7 +79,6 @@ external minPositiveFloat: Float
|
||||
/// [1]: https://en.wikipedia.org/wiki/E_(mathematical_constant)
|
||||
external e: Float
|
||||
|
||||
|
||||
/// The number [π][1].
|
||||
///
|
||||
/// [1]: https://en.wikipedia.org/wiki/Pi
|
||||
|
||||
+40
-23
@@ -47,7 +47,8 @@ function Version(version: String): Version =
|
||||
/// ```
|
||||
function parseOrNull(version: String): Version? =
|
||||
let (groups = versionRegex.matchEntire(version)?.groups)
|
||||
if (groups == null) null
|
||||
if (groups == null)
|
||||
null
|
||||
else
|
||||
new Version {
|
||||
major = groups[1].value.toInt()
|
||||
@@ -99,7 +100,13 @@ class Version {
|
||||
/// - `"1.0.0-0.3.7"`
|
||||
/// - `"1.0.0-x.7.z.92"`
|
||||
/// - `"1.0.0-x-y-z.–"`
|
||||
preRelease: String(matches(Regex(#"(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*"#)))?
|
||||
preRelease: String(
|
||||
matches(
|
||||
Regex(
|
||||
#"(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*"#,
|
||||
),
|
||||
),
|
||||
)?
|
||||
|
||||
hidden fixed preReleaseIdentifiers: List<Int | String> =
|
||||
if (preRelease == null) List() else preRelease.split(".").map((it) -> it.toIntOrNull() ?? it)
|
||||
@@ -119,8 +126,7 @@ class Version {
|
||||
/// Note: Unlike `==`, [equals()] and comparison methods such as [isLessThan()] ignore [build].
|
||||
build: String(matches(Regex(#"[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*"#)))?
|
||||
|
||||
hidden fixed buildIdentifiers: List<String> =
|
||||
if (build == null) List() else build.split(".")
|
||||
hidden fixed buildIdentifiers: List<String> = if (build == null) List() else build.split(".")
|
||||
|
||||
/// Tells whether this version is equal to [other] according to semantic versioning rules.
|
||||
///
|
||||
@@ -160,23 +166,19 @@ class Version {
|
||||
major < other.major
|
||||
|| major == other.major && minor < other.minor
|
||||
|| major == other.major && minor == other.minor && patch < other.patch
|
||||
||
|
||||
major == other.major
|
||||
|| major == other.major
|
||||
&& minor == other.minor
|
||||
&& patch == other.patch
|
||||
&& isPreReleaseLessThan(other)
|
||||
|
||||
/// Tells whether this version is less than or equal to [other] according to semantic versioning rules.
|
||||
function isLessThanOrEquals(other: Version): Boolean =
|
||||
isLessThan(other) || equals(other)
|
||||
function isLessThanOrEquals(other: Version): Boolean = isLessThan(other) || equals(other)
|
||||
|
||||
/// Tells whether this version is greater than [other] according to semantic versioning rules.
|
||||
function isGreaterThan(other: Version): Boolean =
|
||||
other.isLessThan(this)
|
||||
function isGreaterThan(other: Version): Boolean = other.isLessThan(this)
|
||||
|
||||
/// Tells whether this version is greater than or equal to [other] according to semantic versioning rules.
|
||||
function isGreaterThanOrEquals(other: Version): Boolean =
|
||||
other.isLessThanOrEquals(this)
|
||||
function isGreaterThanOrEquals(other: Version): Boolean = other.isLessThanOrEquals(this)
|
||||
|
||||
/// A normal version number MUST take the form X.Y.Z where X, Y, and Z are non-negative integers, and MUST NOT contain leading zeroes.
|
||||
function isNormal(): Boolean = preRelease == null && build == null
|
||||
@@ -187,24 +189,39 @@ class Version {
|
||||
/// Strips [preRelease] and [build] from this version.
|
||||
function toNormal(): Version = (this) { preRelease = null; build = null }
|
||||
|
||||
function toString() = "\(major).\(minor).\(patch)\(if (preRelease != null) "-\(preRelease)" else "")\(if (build != null) "+\(build)" else "")"
|
||||
function toString() =
|
||||
"\(major).\(minor).\(patch)\(if (preRelease != null) "-\(preRelease)" else "")\(if (build != null) "+\(build)" else "")"
|
||||
|
||||
local function isPreReleaseLessThan(other: Version): Boolean =
|
||||
if (preRelease == null) false
|
||||
else if (other.preRelease == null) true
|
||||
else if (preRelease == other.preRelease) false
|
||||
if (preRelease == null)
|
||||
false
|
||||
else if (other.preRelease == null)
|
||||
true
|
||||
else if (preRelease == other.preRelease)
|
||||
false
|
||||
else
|
||||
let (result = preReleaseIdentifiers
|
||||
let (result =
|
||||
preReleaseIdentifiers
|
||||
.zip(other.preReleaseIdentifiers)
|
||||
.fold(null, (result, next) ->
|
||||
if (result != null) result
|
||||
if (result != null)
|
||||
result
|
||||
else if (next.first == next.second)
|
||||
null
|
||||
else if (next.first.getClass() == next.second.getClass())
|
||||
next.first < next.second
|
||||
else
|
||||
if (next.first == next.second) null
|
||||
else if (next.first.getClass() == next.second.getClass()) next.first < next.second
|
||||
else next.first is Int
|
||||
next.first is Int
|
||||
)
|
||||
) if (result != null) result else preReleaseIdentifiers.length < other.preReleaseIdentifiers.length
|
||||
)
|
||||
if (result != null)
|
||||
result
|
||||
else
|
||||
preReleaseIdentifiers.length < other.preReleaseIdentifiers.length
|
||||
}
|
||||
|
||||
// https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
|
||||
local versionRegex = Regex(#"(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?"#)
|
||||
local versionRegex =
|
||||
Regex(
|
||||
#"(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?"#,
|
||||
)
|
||||
|
||||
+3
-6
@@ -28,10 +28,7 @@ function escapeWithSingleQuotes(str: String): String =
|
||||
else if (acc.last.last != "'" && ch != "'")
|
||||
acc.replace(acc.lastIndex, acc.last.add(ch))
|
||||
else
|
||||
acc.add(List(ch)))
|
||||
acc.add(List(ch))
|
||||
)
|
||||
let (grouped = str.chars.fold(List(), processChar))
|
||||
grouped
|
||||
.map((chSeq) ->
|
||||
if (chSeq == List("'")) #"\'"#
|
||||
else "'\(chSeq.join(""))'")
|
||||
.join("")
|
||||
grouped.map((chSeq) -> if (chSeq == List("'")) #"\'"# else "'\(chSeq.join(""))'").join("")
|
||||
|
||||
Reference in New Issue
Block a user