elect
10/03/2021, 7:40 AMvar configure: Input.() -> Unit as a property on Input itself in order to execute it later on.
However, to execute it externally, I have to call input.configure(input)... does this sound right?
I'm inclined to think so, because if I scope input, then I can simply call configure as input.apply { configure() } , but I'd like to have some feedbacks on thisCLOVIS
10/03/2021, 8:03 AMInput.() -> Unit
Matching call: input.configure()
Signature: (Input) -> Unit
Matching call: configure(input)
Signature: Input.(Input) -> Unit
Matching call: input.configure(input)
What is your case exactly? It seems like you are confusing some of these togetherephemient
10/03/2021, 8:39 AMconfigure isn't in scope then it's understandable,
val fn = input.configure
fn(input)
==
input.configure(input)
but it seems that you can avoid that just by bringing it into scopeCLOVIS
10/03/2021, 11:31 AMinput.configure() and configure(input) are allowed, not input.configure(input) (you can't specify the same parameter twice)elect
10/03/2021, 11:40 AMconfigure is an Input propertyelect
10/03/2021, 11:40 AMclass Input {
var configure: Input.() -> Unit = {}elect
10/03/2021, 11:43 AMconfigure as () -> Unit, but then I cant assign block to it
// this is a companion object fun
fun Input(block: Input.() -> Unit) {
val input = Input()
input.configure = block
}
which sounds weird, because configure does have Input as receiver/hostelect
10/03/2021, 11:50 AMval fn = input.configure
fn(input)or
val fn = input.configure
input.fn()Joffrey
10/03/2021, 12:30 PMconfigure public here? It seems it's not supposed to be called from outside of the Input class, otherwise you could pass other instances of Input to it, and that would be quite a mess. I would suggest to create a public method inside Input that would simply call configure on this :
class Input(
private val configure: Input.() -> Unit
) {
fun initialize() {
this.configure()
}
}
But this looks like an XY problem, I wonder what invariants you have for the input class. Is configure supposed to be called exactly once? When? It seems it should be used when creating the Input instance itselfelect
10/04/2021, 9:22 AM