-
Notifications
You must be signed in to change notification settings - Fork 642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/arrowcontracts #834
Conversation
@@ -23,4 +23,11 @@ dependencies { | |||
testCompile project(":kotlintest-runner:kotlintest-runner-junit5") | |||
} | |||
|
|||
compileKotlin { | |||
kotlinOptions { | |||
freeCompilerArgs += '-Xuse-experimental=kotlin.Experimental' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually necessary?
I remember adding a experimental contract somewhere else in our code, and I don't think I needed to add this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you need it where the contract is defined, but not where it is used.
@UseExperimental(ExperimentalContracts::class) | ||
fun <T> Either<*, T>.shouldBeRight() { | ||
contract { | ||
returns() implies (this@shouldBeRight is Either.Right<*>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We wanted this to be the generic type, but it's not possible due to contracts not supporting it yet, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, so once contracts support generics we can just change Either.Right<*>
to Either.Right<T>
and it will be generic.
Great.
Let's merge this!
…On Mon., Jun. 17, 2019, 12:16 Stephen Samuel, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In
kotlintest-assertions/kotlintest-assertions-arrow/src/main/kotlin/io/kotlintest/assertions/arrow/either/matchers.kt
<#834 (comment)>:
> @@ -6,14 +6,20 @@ import io.kotlintest.Result
import io.kotlintest.matchers.beInstanceOf2
import io.kotlintest.should
import io.kotlintest.shouldNot
+import kotlin.contracts.ExperimentalContracts
+import kotlin.contracts.contract
+
***@***.***(ExperimentalContracts::class)
+fun <T> Either<*, T>.shouldBeRight() {
+ contract {
+ returns() implies ***@***.*** is Either.Right<*>)
Yes, so once contracts support generics we can just change Either.Right<*>
to Either.Right<T> and it will be generic.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#834>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAMBCI4HDMG7P4DQMNTN3PLP26TDPANCNFSM4HYOI2NA>
.
|
Please do if you're happy. We can apply this strategy to other parts too.
On Mon, 17 Jun 2019, 10:18 Leonardo Colman Lopes, <notifications@github.com>
wrote:
… Great.
Let's merge this!
On Mon., Jun. 17, 2019, 12:16 Stephen Samuel, ***@***.***>
wrote:
> ***@***.**** commented on this pull request.
> ------------------------------
>
> In
>
kotlintest-assertions/kotlintest-assertions-arrow/src/main/kotlin/io/kotlintest/assertions/arrow/either/matchers.kt
> <#834 (comment)
>:
>
> > @@ -6,14 +6,20 @@ import io.kotlintest.Result
> import io.kotlintest.matchers.beInstanceOf2
> import io.kotlintest.should
> import io.kotlintest.shouldNot
> +import kotlin.contracts.ExperimentalContracts
> +import kotlin.contracts.contract
> +
> ***@***.***(ExperimentalContracts::class)
> +fun <T> Either<*, T>.shouldBeRight() {
> + contract {
> + returns() implies ***@***.*** is Either.Right<*>)
>
> Yes, so once contracts support generics we can just change
Either.Right<*>
> to Either.Right<T> and it will be generic.
>
> —
> You are receiving this because your review was requested.
> Reply to this email directly, view it on GitHub
> <
#834
>,
> or mute the thread
> <
https://github.com/notifications/unsubscribe-auth/AAMBCI4HDMG7P4DQMNTN3PLP26TDPANCNFSM4HYOI2NA
>
> .
>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#834>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAFVSGQDIECOHK6Z6NSKKVDP26TMVANCNFSM4HYOI2NA>
.
|
I've added contracts for Validated, Either and Option.
These contracts allow us to extract the field from these datatypes, but because of the issue with contracts not supporting generics yet, the extracted field will be
Any?
.This is still a big improvement I think, and also means when contracts support generics (1.4?) we can easily update these matchers.
Current example:
Example with this PR:
Example in the future:
This partially addresses the feature request of #612