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
Enable builder inference for optics copy
#2792
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
package arrow.optics | ||
|
||
import kotlin.experimental.ExperimentalTypeInference | ||
|
||
@DslMarker | ||
public annotation class OpticsCopyMarker | ||
|
||
@OpticsCopyMarker | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this do on the interface? I thought it was supposed to go on the functions, the documentation didn’t clarify it for me 😅 Is it applied to all DSL functions that have this as a lambda receiver? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I understand from https://kotlinlang.org/docs/type-safe-builders.html#scope-control-dslmarker, you put the annotation in the interface which will be in scope in the builder, which in this case is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I understand the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I asked because I used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the docs (emphasis mine):
|
||
public interface Copy<A> { | ||
/** | ||
* Changes the value of the element(s) pointed by the [Setter]. | ||
|
@@ -33,7 +39,8 @@ public interface Copy<A> { | |
* } | ||
* ``` | ||
*/ | ||
public fun <B> inside(field: Traversal<A, B>, f: Copy<B>.() -> Unit): Unit = | ||
@OptIn(ExperimentalTypeInference::class) | ||
public fun <B> inside(field: Traversal<A, B>, @BuilderInference f: Copy<B>.() -> Unit): Unit = | ||
field.transform { it.copy(f) } | ||
} | ||
|
||
|
@@ -67,5 +74,6 @@ private class CopyImpl<A>(var current: A): Copy<A> { | |
* } | ||
* ``` | ||
*/ | ||
public fun <A> A.copy(f: Copy<A>.() -> Unit): A = | ||
@OptIn(ExperimentalTypeInference::class) | ||
public fun <A> A.copy(@BuilderInference f: Copy<A>.() -> Unit): A = | ||
CopyImpl(this).also(f).current |
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.
Are both these flags needed?
First one is to allow builder inference inside Arrow, or to be able to expose annotation?
Second one is to allow OptIn without a compiler warning?
I’m always confused about the OptIn, because it works fine without this flag.
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.
I am not sure, the docs at https://kotlinlang.org/docs/using-builders-with-builder-inference.html#writing-your-own-builders are by no means clear. But I'll delete the opt-in one.
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.
I'm not sure if we need it yes, or no 😅 Just wanted to clarify, it can be that we're currently missing it.
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.
As you said "are by no means clear" :/ I feel the same for the
opt-in
one.