Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit 5839704

Browse files
committed
re-adding composeModify laws
1 parent 3226a91 commit 5839704

File tree

7 files changed

+59
-55
lines changed

7 files changed

+59
-55
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-c
1818
arrow-fx-coroutines = { module = "io.arrow-kt:arrow-fx-coroutines", version.ref = "arrow" }
1919
arrow-core = { module = "io.arrow-kt:arrow-core", version.ref = "arrow" }
2020
arrow-optics = { module = "io.arrow-kt:arrow-optics", version.ref = "arrow" }
21+
arrow-functions = { module = "io.arrow-kt:arrow-functions", version.ref = "arrow" }
2122

2223
# Gradle plugins used in buildSrc
2324
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }

kotest-property-arrow-optics/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ kotlin {
77
commonMain {
88
dependencies {
99
compileOnly(libs.arrow.optics)
10+
implementation(libs.arrow.functions)
1011
implementation(libs.kotest.assertions.core)
1112
implementation(libs.kotest.framework.api)
1213
implementation(libs.kotest.property)

kotest-property-arrow-optics/src/commonMain/kotlin/io/kotest/property/arrow/optics/IsoLaws.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
package io.kotest.property.arrow.optics
44

5-
//import arrow.core.compose
5+
import arrow.core.compose
66
import arrow.core.identity
77
import arrow.optics.Iso
88
import io.kotest.property.Arb
@@ -25,7 +25,7 @@ public object IsoLaws {
2525
Law("Iso Law: round trip one way") { iso.roundTripOneWay(aGen, eqa) },
2626
Law("Iso Law: round trip other way") { iso.roundTripOtherWay(bGen, eqb) },
2727
Law("Iso Law: modify identity is identity") { iso.modifyIdentity(aGen, eqa) },
28-
// Law("Iso Law: compose modify") { iso.composeModify(aGen, funcGen, eqa) },
28+
Law("Iso Law: compose modify") { iso.composeModify(aGen, funcGen, eqa) },
2929
Law("Iso Law: consitent set with modify") { iso.consistentSetModify(aGen, bGen, eqa) }
3030
)
3131

@@ -44,11 +44,11 @@ public object IsoLaws {
4444
modify(a, ::identity).equalUnderTheLaw(a, eq)
4545
}
4646

47-
// public suspend fun <A, B> Iso<A, B>.composeModify(aGen: Arb<A>, funcGen: Arb<(B) -> B>, eq: (A, A) -> Boolean): PropertyContext =
48-
// checkAll(aGen, funcGen, funcGen) { a, f, g ->
49-
// modify(modify(a, f), g).equalUnderTheLaw(modify(a, g compose f), eq)
50-
// }
51-
//
47+
public suspend fun <A, B> Iso<A, B>.composeModify(aGen: Arb<A>, funcGen: Arb<(B) -> B>, eq: (A, A) -> Boolean): PropertyContext =
48+
checkAll(aGen, funcGen, funcGen) { a, f, g ->
49+
modify(modify(a, f), g).equalUnderTheLaw(modify(a, g compose f), eq)
50+
}
51+
5252
public suspend fun <A, B> Iso<A, B>.consistentSetModify(aGen: Arb<A>, bGen: Arb<B>, eq: (A, A) -> Boolean): PropertyContext =
5353
checkAll(aGen, bGen) { a, b ->
5454
set(b).equalUnderTheLaw(modify(a) { b }, eq)

kotest-property-arrow-optics/src/commonMain/kotlin/io/kotest/property/arrow/optics/LensLaws.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
package io.kotest.property.arrow.optics
44

5+
import arrow.core.compose
56
import arrow.core.identity
67
import arrow.optics.Lens
78
import io.kotest.property.Arb
@@ -26,7 +27,7 @@ public object LensLaws {
2627
Law("Lens law: set get") { lensSetGet(lensGen, aGen, bGen, eqb) },
2728
Law("Lens law: is set idempotent") { lensSetIdempotent(lensGen, aGen, bGen, eqa) },
2829
Law("Lens law: modify identity") { lensModifyIdentity(lensGen, aGen, eqa) },
29-
// Law("Lens law: compose modify") { lensComposeModify(lensGen, aGen, funcGen, eqa) },
30+
Law("Lens law: compose modify") { lensComposeModify(lensGen, aGen, funcGen, eqa) },
3031
Law("Lens law: consistent set modify") { lensConsistentSetModify(lensGen, aGen, bGen, eqa) }
3132
)
3233

@@ -84,18 +85,18 @@ public object LensLaws {
8485
}
8586
}
8687

87-
// public suspend fun <A, B> lensComposeModify(
88-
// lensGen: Arb<Lens<A, B>>,
89-
// aGen: Arb<A>,
90-
// funcGen: Arb<(B) -> B>,
91-
// eq: (A, A) -> Boolean
92-
// ): PropertyContext =
93-
// checkAll(lensGen, aGen, funcGen, funcGen) { lens, a, f, g ->
94-
// lens.run {
95-
// modify(modify(a, f), g).equalUnderTheLaw(modify(a, g compose f), eq)
96-
// }
97-
// }
98-
//
88+
public suspend fun <A, B> lensComposeModify(
89+
lensGen: Arb<Lens<A, B>>,
90+
aGen: Arb<A>,
91+
funcGen: Arb<(B) -> B>,
92+
eq: (A, A) -> Boolean
93+
): PropertyContext =
94+
checkAll(lensGen, aGen, funcGen, funcGen) { lens, a, f, g ->
95+
lens.run {
96+
modify(modify(a, f), g).equalUnderTheLaw(modify(a, g compose f), eq)
97+
}
98+
}
99+
99100
public suspend fun <A, B> lensConsistentSetModify(
100101
lensGen: Arb<Lens<A, B>>,
101102
aGen: Arb<A>,

kotest-property-arrow-optics/src/commonMain/kotlin/io/kotest/property/arrow/optics/OptionalLaws.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
package io.kotest.property.arrow.optics
44

5+
import arrow.core.compose
56
import arrow.core.identity
67
import arrow.optics.Optional
78
import io.kotest.property.Arb
@@ -25,7 +26,7 @@ public object OptionalLaws {
2526
Law("Optional Law: set what you get") { setGetOption(optionalGen, aGen, bGen, eqb) },
2627
Law("Optional Law: set is idempotent") { setIdempotent(optionalGen, aGen, bGen, eqa) },
2728
Law("Optional Law: modify identity = identity") { modifyIdentity(optionalGen, aGen, eqa) },
28-
// Law("Optional Law: compose modify") { composeModify(optionalGen, aGen, funcGen, eqa) },
29+
Law("Optional Law: compose modify") { composeModify(optionalGen, aGen, funcGen, eqa) },
2930
Law("Optional Law: consistent set with modify") { consistentSetModify(optionalGen, aGen, bGen, eqa) }
3031
)
3132

@@ -88,18 +89,18 @@ public object OptionalLaws {
8889
}
8990
}
9091

91-
// public suspend fun <A, B> composeModify(
92-
// optionalGen: Arb<Optional<A, B>>,
93-
// aGen: Arb<A>,
94-
// funcGen: Arb<(B) -> B>,
95-
// eq: (A, A) -> Boolean
96-
// ): PropertyContext =
97-
// checkAll(optionalGen, aGen, funcGen, funcGen) { optional, a, f, g ->
98-
// optional.run {
99-
// modify(modify(a, f), g).equalUnderTheLaw(modify(a, g compose f), eq)
100-
// }
101-
// }
102-
//
92+
public suspend fun <A, B> composeModify(
93+
optionalGen: Arb<Optional<A, B>>,
94+
aGen: Arb<A>,
95+
funcGen: Arb<(B) -> B>,
96+
eq: (A, A) -> Boolean
97+
): PropertyContext =
98+
checkAll(optionalGen, aGen, funcGen, funcGen) { optional, a, f, g ->
99+
optional.run {
100+
modify(modify(a, f), g).equalUnderTheLaw(modify(a, g compose f), eq)
101+
}
102+
}
103+
103104
public suspend fun <A, B> consistentSetModify(
104105
optionalGen: Arb<Optional<A, B>>,
105106
aGen: Arb<A>,

kotest-property-arrow-optics/src/commonMain/kotlin/io/kotest/property/arrow/optics/PrismLaws.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
package io.kotest.property.arrow.optics
44

5+
import arrow.core.compose
56
import arrow.core.identity
67
import arrow.optics.Prism
78
import io.kotest.property.Arb
@@ -23,7 +24,7 @@ public object PrismLaws {
2324
Law("Prism law: partial round trip one way") { prism.partialRoundTripOneWay(aGen, eqa) },
2425
Law("Prism law: round trip other way") { prism.roundTripOtherWay(bGen, eqb) },
2526
Law("Prism law: modify identity") { prism.modifyIdentity(aGen, eqa) },
26-
// Law("Prism law: compose modify") { prism.composeModify(aGen, funcGen, eqa) },
27+
Law("Prism law: compose modify") { prism.composeModify(aGen, funcGen, eqa) },
2728
Law("Prism law: consistent set modify") { prism.consistentSetModify(aGen, bGen, eqa) }
2829
)
2930

@@ -44,10 +45,10 @@ public object PrismLaws {
4445
modify(a, ::identity).equalUnderTheLaw(a, eq)
4546
}
4647

47-
// public suspend fun <A, B> Prism<A, B>.composeModify(aGen: Arb<A>, funcGen: Arb<(B) -> B>, eq: (A, A) -> Boolean): PropertyContext =
48-
// checkAll(aGen, funcGen, funcGen) { a, f, g ->
49-
// modify(modify(a, f), g).equalUnderTheLaw(modify(a, g compose f), eq)
50-
// }
48+
public suspend fun <A, B> Prism<A, B>.composeModify(aGen: Arb<A>, funcGen: Arb<(B) -> B>, eq: (A, A) -> Boolean): PropertyContext =
49+
checkAll(aGen, funcGen, funcGen) { a, f, g ->
50+
modify(modify(a, f), g).equalUnderTheLaw(modify(a, g compose f), eq)
51+
}
5152

5253
public suspend fun <A, B> Prism<A, B>.consistentSetModify(aGen: Arb<A>, bGen: Arb<B>, eq: (A, A) -> Boolean): PropertyContext =
5354
checkAll(aGen, bGen) { a, b ->

kotest-property-arrow-optics/src/commonMain/kotlin/io/kotest/property/arrow/optics/TraversalLaws.kt

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
package io.kotest.property.arrow.optics
44

5-
//import arrow.core.compose
5+
import arrow.core.compose
66
import arrow.core.identity
77
import arrow.optics.Traversal
88
import io.kotest.property.Arb
@@ -24,7 +24,7 @@ public object TraversalLaws {
2424
Law("Traversal law: set is idempotent") { traversal.setIdempotent(aGen, bGen, eq) },
2525
Law("Traversal law: modify identity") { traversal.modifyIdentity(aGen, eq) },
2626
// TODO: Was there any replacement for `compose` in Arrow 2?
27-
// Law("Traversal law: compose modify") { traversal.composeModify(aGen, funcGen, eq) }
27+
Law("Traversal law: compose modify") { traversal.composeModify(aGen, funcGen, eq) }
2828
)
2929

3030
public suspend fun <A, B> Traversal<A, B>.setIdempotent(aGen: Arb<A>, bGen: Arb<B>, eq: (A, A) -> Boolean): PropertyContext =
@@ -38,19 +38,18 @@ public object TraversalLaws {
3838
modify(a, ::identity).equalUnderTheLaw(a, eq)
3939
}
4040

41-
// TODO: Was there any replacement for `compose` in Arrow 2?
42-
// public suspend fun <A, B> Traversal<A, B>.composeModify(
43-
// aGen: Arb<A>,
44-
// funcGen: Arb<(B) -> B>,
45-
// eq: (A, A) -> Boolean
46-
// ): PropertyContext =
47-
// checkAll(
48-
// max(max(aGen.minIterations(), funcGen.minIterations()), funcGen.minIterations()),
49-
// aGen,
50-
// funcGen,
51-
// funcGen
52-
// ) { a, f, g ->
53-
// modify(modify(a, f), g)
54-
// .equalUnderTheLaw(modify(a, g compose f), eq)
55-
// }
41+
public suspend fun <A, B> Traversal<A, B>.composeModify(
42+
aGen: Arb<A>,
43+
funcGen: Arb<(B) -> B>,
44+
eq: (A, A) -> Boolean
45+
): PropertyContext =
46+
checkAll(
47+
max(max(aGen.minIterations(), funcGen.minIterations()), funcGen.minIterations()),
48+
aGen,
49+
funcGen,
50+
funcGen
51+
) { a, f, g ->
52+
modify(modify(a, f), g)
53+
.equalUnderTheLaw(modify(a, g compose f), eq)
54+
}
5655
}

0 commit comments

Comments
 (0)