From de3c2a1b5ad902c1b6bba70a4983b033ae822924 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 20 Dec 2020 14:18:12 +0300 Subject: [PATCH] Add curring and update kotlin --- .../kscience/kmath/operations/Algebra.kt | 28 +++++++++++++++++++ settings.gradle.kts | 4 +-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt index 12a45615a..ed10901df 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt +++ b/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt @@ -22,10 +22,22 @@ public interface Algebra { */ public fun unaryOperation(operation: String, arg: T): T + /** + * Currying version of [unaryOperation] + */ + public fun unaryOperationFunction(operation: String): (T) -> T = { unaryOperation(operation, it) } + /** * Dynamic call of binary operation [operation] on [left] and [right] */ public fun binaryOperation(operation: String, left: T, right: T): T + + /** + * Curring version of [binaryOperation] + */ + public fun binaryOperationFunction(operation: String): (left: T, right: T) -> T = { left, right -> + binaryOperation(operation, left, right) + } } /** @@ -45,11 +57,27 @@ public interface NumericAlgebra : Algebra { public fun leftSideNumberOperation(operation: String, left: Number, right: T): T = binaryOperation(operation, number(left), right) + /** + * Curring version of [leftSideNumberOperation] + */ + public fun leftSideNumberOperationFunction(operation: String): (left: Number, right: T) -> T = + { left: Number, right: T -> + leftSideNumberOperation(operation, left, right) + } + /** * Dynamic call of binary operation [operation] on [left] and [right] where right element is [Number]. */ public fun rightSideNumberOperation(operation: String, left: T, right: Number): T = leftSideNumberOperation(operation, right, left) + + /** + * Curring version of [rightSideNumberOperation] + */ + public fun rightSideNumberOperationFunction(operation: String): (left: T, right: Number) -> T = + { left: T, right: Number -> + rightSideNumberOperation(operation, left, right) + } } /** diff --git a/settings.gradle.kts b/settings.gradle.kts index 10e4d9577..da33fea59 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,8 +8,8 @@ pluginManagement { maven("https://dl.bintray.com/kotlin/kotlinx") } - val toolsVersion = "0.7.0" - val kotlinVersion = "1.4.20" + val toolsVersion = "0.7.1" + val kotlinVersion = "1.4.21" plugins { id("kotlinx.benchmark") version "0.2.0-dev-20"