Skip to content

Commit

Permalink
Math functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mnbjhu committed May 22, 2023
1 parent 32e0892 commit 8eed798
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

# This workflow should start docker and run gradle build

name: Java CI with Gradle

on:
Expand Down
47 changes: 46 additions & 1 deletion core/src/main/kotlin/uk.gibby.dsl/functions/Math.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package uk.gibby.dsl.functions


import kotlinx.serialization.encodeToString
import uk.gibby.dsl.driver.surrealJson
import uk.gibby.dsl.types.*

object Math {
Expand Down Expand Up @@ -33,4 +35,47 @@ object Math {
fun sqrt(number: LongType) = doubleType.createReference("math::sqrt(${number.getReference()})")
fun sum(array: ListType<Double, DoubleType>) = doubleType.createReference("array::sum(${array.getReference()})")
fun sum(array: ListType<Long, LongType>) = longType.createReference("array::sum(${array.getReference()})")
}
}

// Math operators

operator fun DoubleType.plus(other: DoubleType) = doubleType.createReference("(${this.getReference()} + ${other.getReference()})")
operator fun DoubleType.plus(other: LongType) = doubleType.createReference("(${this.getReference()} + ${other.getReference()})")
operator fun DoubleType.plus(other: Double) = doubleType.createReference("(${this.getReference()} + ${surrealJson.encodeToString(other)})")
operator fun DoubleType.plus(other: Long) = doubleType.createReference("(${this.getReference()} + ${surrealJson.encodeToString(other)})")
operator fun LongType.plus(other: DoubleType) = doubleType.createReference("(${this.getReference()} + ${other.getReference()})")
operator fun LongType.plus(other: LongType) = longType.createReference("(${this.getReference()} + ${other.getReference()})")
operator fun LongType.plus(other: Double) = doubleType.createReference("(${this.getReference()} + ${surrealJson.encodeToString(other)})")
operator fun LongType.plus(other: Long) = longType.createReference("(${this.getReference()} + ${surrealJson.encodeToString(other)})")
operator fun DoubleType.minus(other: DoubleType) = doubleType.createReference("(${this.getReference()} - ${other.getReference()})")
operator fun DoubleType.minus(other: LongType) = doubleType.createReference("(${this.getReference()} - ${other.getReference()})")
operator fun DoubleType.minus(other: Double) = doubleType.createReference("(${this.getReference()} - ${surrealJson.encodeToString(other)})")
operator fun DoubleType.minus(other: Long) = doubleType.createReference("(${this.getReference()} - ${surrealJson.encodeToString(other)})")
operator fun LongType.minus(other: DoubleType) = doubleType.createReference("(${this.getReference()} - ${other.getReference()})")
operator fun LongType.minus(other: LongType) = longType.createReference("(${this.getReference()} - ${other.getReference()})")
operator fun LongType.minus(other: Double) = doubleType.createReference("(${this.getReference()} - ${surrealJson.encodeToString(other)})")
operator fun LongType.minus(other: Long) = longType.createReference("(${this.getReference()} - ${surrealJson.encodeToString(other)})")
operator fun DoubleType.times(other: DoubleType) = doubleType.createReference("(${this.getReference()} * ${other.getReference()})")
operator fun DoubleType.times(other: LongType) = doubleType.createReference("(${this.getReference()} * ${other.getReference()})")
operator fun DoubleType.times(other: Double) = doubleType.createReference("(${this.getReference()} * ${surrealJson.encodeToString(other)})")
operator fun DoubleType.times(other: Long) = doubleType.createReference("(${this.getReference()} * ${surrealJson.encodeToString(other)})")
operator fun LongType.times(other: DoubleType) = doubleType.createReference("(${this.getReference()} * ${other.getReference()})")
operator fun LongType.times(other: LongType) = longType.createReference("(${this.getReference()} * ${other.getReference()})")
operator fun LongType.times(other: Double) = doubleType.createReference("(${this.getReference()} * ${surrealJson.encodeToString(other)})")
operator fun LongType.times(other: Long) = longType.createReference("(${this.getReference()} * ${surrealJson.encodeToString(other)})")
operator fun DoubleType.div(other: DoubleType) = doubleType.createReference("(${this.getReference()} / ${other.getReference()})")
operator fun DoubleType.div(other: LongType) = doubleType.createReference("(${this.getReference()} / ${other.getReference()})")
operator fun DoubleType.div(other: Double) = doubleType.createReference("(${this.getReference()} / ${surrealJson.encodeToString(other)})")
operator fun DoubleType.div(other: Long) = doubleType.createReference("(${this.getReference()} / ${surrealJson.encodeToString(other)})")
operator fun LongType.div(other: DoubleType) = doubleType.createReference("(${this.getReference()} / ${other.getReference()})")
operator fun LongType.div(other: LongType) = longType.createReference("(${this.getReference()} / ${other.getReference()})")
operator fun LongType.div(other: Double) = doubleType.createReference("(${this.getReference()} / ${surrealJson.encodeToString(other)})")
operator fun LongType.div(other: Long) = longType.createReference("(${this.getReference()} / ${surrealJson.encodeToString(other)})")
operator fun DoubleType.rem(other: DoubleType) = doubleType.createReference("(${this.getReference()} % ${other.getReference()})")
operator fun DoubleType.rem(other: LongType) = doubleType.createReference("(${this.getReference()} % ${other.getReference()})")
operator fun DoubleType.rem(other: Double) = doubleType.createReference("(${this.getReference()} % ${surrealJson.encodeToString(other)})")
operator fun DoubleType.rem(other: Long) = doubleType.createReference("(${this.getReference()} % ${surrealJson.encodeToString(other)})")
operator fun LongType.rem(other: DoubleType) = doubleType.createReference("(${this.getReference()} % ${other.getReference()})")
operator fun LongType.rem(other: LongType) = longType.createReference("(${this.getReference()} % ${other.getReference()})")
operator fun LongType.rem(other: Double) = doubleType.createReference("(${this.getReference()} % ${surrealJson.encodeToString(other)})")
operator fun LongType.rem(other: Long) = longType.createReference("(${this.getReference()} % ${surrealJson.encodeToString(other)})")

0 comments on commit 8eed798

Please sign in to comment.