ValV
09/13/2018, 2:13 AMaddListener { ... }
?
Java's example shows something like addListener((obs, oldVal, newVal) -> { ... })
Shawn
09/13/2018, 2:15 AMaddListener { obs, oldVal, newVal ->
...
}
ValV
09/13/2018, 2:17 AMobservable ->
, but later I can't call it
inside the lambdaShawn
09/13/2018, 2:18 AMit
is only implicitly provided when you don’t declare a named parameter for the lambdaShawn
09/13/2018, 2:18 AM{ foo -> ... }
it
will not be present, the parameter will instead be named foo
ValV
09/13/2018, 2:23 AMShawn
09/13/2018, 2:24 AMValV
09/13/2018, 2:26 AMfirst
, second
, third
?Shawn
09/13/2018, 2:27 AM{ first, second, third -> ... }
but Kotlin will not do it for youShawn
09/13/2018, 2:27 AMShawn
09/13/2018, 2:28 AMoldVal
and newVal
, though admittedly not much less soValV
09/13/2018, 2:30 AMfirst
, second
references are not the same as it
?ValV
09/13/2018, 2:30 AMShawn
09/13/2018, 2:34 AMit
is implicitly provided - as in, you don’t need to explicitly label it as a parameter to use it in a single-argument lambdaShawn
09/13/2018, 2:34 AMfirst
, `second`… are manually labeledShawn
09/13/2018, 2:35 AMfun foo(block: (Int, Int, Int) -> Any) { }
fun bar() {
foo {
println(first)
}
}
this won’t compileShawn
09/13/2018, 2:35 AMfun foo(block: (Int, Int, Int) -> Any) { }
fun bar() {
foo { first, second, third ->
println(first)
}
}
ValV
09/13/2018, 2:38 AMValV
09/13/2018, 2:41 AMaddListener { observer -> ... }
is still legal, as well as addListener { obs, old, new -> ... }
ValV
09/13/2018, 2:50 AMShawn
09/13/2018, 2:53 AMaddListener
is overloadedShawn
09/13/2018, 2:53 AMctrl/cmd+b
into the definition to see if there are multiple definitionsShawn
09/13/2018, 2:53 AMShawn
09/13/2018, 2:55 AMfun <T, R> addListener(block: (Observer, T, T) -> R) { ... }
fun <R> addListener(block: (Observer) -> R) { ... }
maybe something like that?ValV
09/13/2018, 2:57 AMValV
09/13/2018, 2:59 AMit
inside lambda, there should be something like () -> Unit
in addListener
signature, right?ValV
09/13/2018, 2:59 AMObservable! -> Unit
?Shawn
09/13/2018, 3:00 AM() -> Unit
is a lambda that takes no arguments whatsoever and returns Unit
Shawn
09/13/2018, 3:00 AMit
for a lambda that doesn’t take argumentsShawn
09/13/2018, 3:01 AMit
you need a lambda that takes exactly one argument (of any sort)Shawn
09/13/2018, 3:01 AMValV
09/13/2018, 3:01 AMShawn
09/13/2018, 3:01 AM(Observable!) -> Unit
would work just fine 👌ValV
09/13/2018, 3:04 AMaddListener { println("$it") }
for signature addListener(Observable! -> Unit)
?Shawn
09/13/2018, 3:04 AMValV
09/13/2018, 3:06 AMOverload resolution ambiguity. All these functions match
- those with 1 and 3 argumentsShawn
09/13/2018, 3:07 AMShawn
09/13/2018, 3:07 AMValV
09/13/2018, 3:11 AMValV
09/13/2018, 3:11 AMShawn
09/13/2018, 3:17 AMShawn
09/13/2018, 3:17 AMValV
09/13/2018, 3:22 AMRuckus
09/13/2018, 3:25 AMValV
09/13/2018, 3:38 AMRuckus
09/13/2018, 3:36 PMAndreas Sinz
09/14/2018, 4:06 PMaddListener
to call without looking at the body of the lambdaAndreas Sinz
09/14/2018, 4:13 PMInvalidationListener
with ...addListener(InvalidationListener { println("$it") }
, maybe that worksValV
09/15/2018, 7:45 AMInvalidationListener { ... }
does really work, but it's dark magic is beyond my imagination. I.e. the magic which is involved in choosing lambdas by the compilerValV
09/15/2018, 7:50 AMInvalidationListener
? AFAIK, it's an interface with the only one method invalidated
. I did not find where it accepts lambdasAndreas Sinz
09/15/2018, 8:26 AM