Add new modules to standard library
This commit is contained in:
@@ -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")
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
21
modules/collection/src/main/resources/map.mus
Normal file
21
modules/collection/src/main/resources/map.mus
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user