Skip to content

Commit

Permalink
Fix Then0 cases
Browse files Browse the repository at this point in the history
  • Loading branch information
deusaquilus committed Dec 26, 2023
1 parent e87cd3d commit f1c2d61
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ apply(plugin = "io.github.gradle-nexus.publish-plugin")
allprojects {

group = "io.exoquery"
version = "0.0.2"
version = "0.0.3"

apply(plugin = "kotlin")
apply(plugin = "maven-publish")
Expand Down
6 changes: 6 additions & 0 deletions decomat-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ tasks.register<TemplateTask>("template_base", TemplateTask::class) {
into("build/templates/io/decomat")
}

//tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
// kotlinOptions{
// freeCompilerArgs = listOf("-Xno-optimize")
// }
//}

//tasks.register("template", Sync::class) {
// dependsOn("template_base")
// from("build/templates/io/decomat")
Expand Down
18 changes: 18 additions & 0 deletions decomat-core/src/main/kotlin/io/decomat/ThenPattern1.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
package io.decomat

fun <R> case(pat: Pattern0<R>) = ThenIs(pat, {true})

class ThenIs<R>(
override val pat: Pattern0<R>,
override val check: (R) -> Boolean
): Stage<Pattern0<R>, R> {
inline fun <O> useComponents(r: R, f: (R) -> O): O {
return f(r)
}

inline fun thenIf(crossinline f: (R) -> Boolean) = ThenIs(pat) { r: R -> useComponents(r, f) }
inline fun thenIfThis(crossinline f: R.() -> (R) -> Boolean) = ThenIs(pat) { r: R -> useComponents(r, f(r)) }
inline fun <O> then(crossinline f: (R) -> O): Case<O, R> = StageCase(pat, check) { r: R -> useComponents(r, f) }
inline fun <O> thenThis(crossinline f: R.() -> (R) -> O): Case<O, R> = StageCase(pat, check) { r: R -> useComponents(r, f(r)) }
}



fun <P1: Pattern0<R1>, R1, R> case(pat: Pattern1<P1, R1, R>) = Then0(pat, {true})

class Then0<P1: Pattern0<R1>, R1, R>(
Expand Down
4 changes: 2 additions & 2 deletions decomat-core/src/templates/Pattern3.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
[@output file="decomat-core/build/templates/io/decomat/Then2.kt"]
package io.decomat

[#list 0..3 as i1]
[#list 0..3 as i2]
[#list 0..2 as i1]
[#list 0..2 as i2]
[#-- fun <P1: Pattern1<P11, R11, R1>, P2: Pattern0<R2>, P11: Pattern<R11>, R11, R1, R2, R> case(pat: Pattern2<P1, P2, R1, R2, R>) = Then10(pat, {true}) --]

fun <P1: [@PatternVars 1 i1 /], P2: [@PatternVars 2 i2 /], R> case(pat: [@Pattern 2 /]) = Then${i1}${i2}(pat, {true})
Expand Down
30 changes: 30 additions & 0 deletions decomat-core/src/test/kotlin/io/decomat/ThenTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,41 @@ import kotlin.test.Test

public class ThenTest: DecomatTest {
// Just check that the types don't fail
@Test
fun `ThenIs - Is`() =
assert(
case(Is<Entity>()).then { a -> Res1(a) }.eval(foo) == Res1(foo)
)

@Test
fun typesTest() {
case(FlatMap_M(Is(), Is())).then { a: Query, b: Query -> Res2(a, b) }
}

@Test
fun `Then0 - distinct(Is) - Filter`() =
assert(
case(Distinct_M(Is<Entity>())).then { (a) -> Res1(a) }.eval(Distinct(foo)) == Res1(foo)
)

@Test
fun `Then0 - distinct(Is)`() =
assert(
case(Distinct_M(Is<Entity>())).then { (a) -> Res1(a) }.eval(Distinct(foo)) == Res1(foo)
)

@Test
fun `Then1 - distinct(distinct(Is))`() =
assert(
case(Distinct_M(Distinct_M(Is<Entity>()))).then { (a) -> Res1(a) }.eval(Distinct(Distinct(foo))) == Res1(foo)
)

@Test
fun `Then2 - distinct(flatMap(Is, Is))`() =
assert(
case(Distinct_M(FlatMap_M(Is(), Is()))).then { (a, b) -> Res2(a, b) }.eval(Distinct(FlatMap(foo, bar))) == Res2(foo, bar)
)

@Test
fun `Then00 - flatMap(Is, Is) - Filter`() =
assert(
Expand Down

0 comments on commit f1c2d61

Please sign in to comment.