Add curring and update kotlin

This commit is contained in:
Alexander Nozik 2020-12-20 14:18:12 +03:00
parent f1435c2c05
commit de3c2a1b5a
2 changed files with 30 additions and 2 deletions

View File

@ -22,10 +22,22 @@ public interface Algebra<T> {
*/
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<T> : Algebra<T> {
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)
}
}
/**

View File

@ -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"