Improve smnp.math and smnp.collection modules
This commit is contained in:
@@ -99,4 +99,8 @@ extend list {
|
||||
function shuffle() {
|
||||
return shuffle(this);
|
||||
}
|
||||
|
||||
function countBy(value) {
|
||||
return (this as item ^ item % item == value).size;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,12 @@
|
||||
package io.smnp.ext.math
|
||||
|
||||
import io.smnp.ext.provider.HybridModuleProvider
|
||||
import io.smnp.ext.math.function.ModuloFunction
|
||||
import io.smnp.ext.math.function.RandomFunction
|
||||
import io.smnp.ext.math.function.RangeFunction
|
||||
import io.smnp.ext.provider.HybridModuleProvider
|
||||
import org.pf4j.Extension
|
||||
|
||||
@Extension
|
||||
class MathModule : HybridModuleProvider("smnp.math") {
|
||||
override fun functions() = listOf(
|
||||
ModuloFunction(), RangeFunction(),
|
||||
RandomFunction()
|
||||
)
|
||||
override fun functions() = listOf(ModuloFunction(), RandomFunction())
|
||||
override fun dependencies() = listOf("smnp.lang", "smnp.collection")
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package io.smnp.ext.math.function
|
||||
|
||||
import io.smnp.callable.function.Function
|
||||
import io.smnp.callable.function.FunctionDefinitionTool
|
||||
import io.smnp.callable.signature.Signature.Companion.simple
|
||||
import io.smnp.type.enumeration.DataType.INT
|
||||
import io.smnp.type.matcher.Matcher.Companion.ofType
|
||||
import io.smnp.type.model.Value
|
||||
|
||||
class RangeFunction : Function("range") {
|
||||
override fun define(new: FunctionDefinitionTool) {
|
||||
new function simple(ofType(INT), ofType(INT)) body { _, (begin, end) ->
|
||||
Value.list(IntRange(begin.value as Int, end.value as Int).map { Value.int(it) })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,4 +79,8 @@ function pick(items: list<map<string><>>) {
|
||||
return item.get("value");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function range(begin: int, end: int, step: int = 1) {
|
||||
return ((end-begin) as i ^ begin + i * step) as i ^ i % i < end;
|
||||
}
|
||||
Reference in New Issue
Block a user