Add new modules to standard library

This commit is contained in:
2020-03-13 17:28:02 +01:00
parent 264100eef1
commit 5680ed4e42
17 changed files with 321 additions and 4 deletions

View File

@@ -4,6 +4,6 @@ import org.pf4j.Extension
@Extension
class CollectionModule : LanguageModuleProvider("smnp.collection") {
override fun files() = listOf("list.mus")
override fun files() = listOf("list.mus", "map.mus")
override fun dependencies() = listOf("smnp.lang")
}

View File

@@ -12,4 +12,34 @@ function _flatten(list: list, output: list) {
}
return output;
}
extend list as this {
function toFlat() {
return flatten(this);
}
function contains(value) {
return (this as item ^ item % item == value).size > 0;
}
function join(separator: string = ", ") {
output = ""
this as (item, index) ^ {
output = output + item;
if (index < this.size - 1) {
output = output + separator;
}
}
return output;
}
function isEmpty() {
return this.size == 0;
}
function isNotEmpty() {
return not this.isEmpty();
}
}

View File

@@ -0,0 +1,21 @@
extend map as this {
function containsKey(key) {
return this.keys.contains(key);
}
function containsValue(value) {
return this.values.contains(value);
}
function contains(key, value) {
return (this as (v, k) ^ v % (k == key) and (v == value)).size > 0;
}
function isEmpty() {
return this.size == 0;
}
function isNotEmpty() {
return not this.isEmpty();
}
}