When I have a function that expects a value of typ...
# compiler
s
When I have a function that expects a value of type
(A) -> B
, it’d be cool to be able to just pass
::foo
instead of
A::foo
. Is there a name for what I want? Even better, is there an existing ticket/proposal for it? Example:
Copy code
data class A(val name: String)
fun <B> A.getProp(prop: (A) -> B) = prop(this)
fun A.getName() = getProp(::name) // I want this
fun A.getName2() = getProp(A::name) // But I have to do this instead
2
The context where this bugs me is in tests using
assertk
, where I end up with things like:
Copy code
assertThat(actual)
    .isInstanceOf(ExpectedClass::class).all {
        prop(ExpectedClass::a).isEqualTo(expectedA)
        prop(ExpectedClass::b).isEqualTo(expectedB)
    }
I end up repeating the
ExpectedClass
over and over again
But I keep doing it because it is useful to use the property reference rather than a lambda (like
prop { it. a }
), so that when the assertion fails it will include the name of the property
c
Better post in #language-proposals
s
👍 thanks for the suggestion, will do!