jeremy
02/15/2019, 2:57 AMfun <T: Somethingable> String.buildSomething(): T {
return T.buildSomethingFromString(this)
}
The only way to get buildSomethingFromString is to have a interface Somethingable have a default implementation in a companion object. But then I lose compile time checking for overriding implementation on T. I thought I could be specific on the extension for each concrete impl, but I can’t redefine String.buildSomething(): Impl1 and String.buildSomething(): Impl2 without changing the name.jeremy
02/15/2019, 3:00 AMval something1: Something1 = "...".buildSomething()
val something2: Something2 = "...".buildSomething()
sitepodmatt
02/15/2019, 3:46 AMjeremy
02/15/2019, 3:50 AMsitepodmatt
02/15/2019, 3:52 AMsitepodmatt
02/15/2019, 3:54 AMjeremy
02/15/2019, 3:56 AMsitepodmatt
02/15/2019, 4:00 AMsitepodmatt
02/15/2019, 4:01 AMsitepodmatt
02/15/2019, 4:01 AMjeremy
02/15/2019, 4:08 AMjeremy
02/15/2019, 4:09 AMsitepodmatt
02/15/2019, 4:09 AMdumptruckman
02/25/2019, 9:17 PMdumptruckman
02/25/2019, 9:18 PMMarc Knaup
02/25/2019, 9:18 PMapply
and run
use this
instead of passing a parameter.Marc Knaup
02/25/2019, 9:18 PMlet
and run
return the lambda's return value.Marc Knaup
02/25/2019, 9:18 PMapply
and also
always return this
Marc Knaup
02/25/2019, 9:21 PMstreetsofboston
02/25/2019, 9:22 PMapply
you should use for configuring the receiver-object (eg. a builder like pattern)
also
is for ’side-effects`.
Both apply
and also
return the receiver on which they were called.streetsofboston
02/25/2019, 9:23 PMlet
is often used for handling nullable properties to do stuff when it’s not null: myProperty?.let { .... code... }
.
with
and run
are often used to avoid writing/coding the same receiver over and over again (you can often refactor them into proper private extension functions) or for calling an instance method with a receiver from outside the class of that instance (calling an instance method given a certain context).Marc Knaup
02/25/2019, 9:33 PMrun
is better for method chains. The name is quite misleading in some scenarios though.bjonnh
02/25/2019, 10:52 PMbjonnh
02/25/2019, 10:52 PMbjonnh
02/25/2019, 10:53 PMbjonnh
02/25/2019, 10:58 PMJordan Stewart
02/25/2019, 11:13 PMJordan Stewart
02/25/2019, 11:16 PMJordan Stewart
02/25/2019, 11:19 PMbjonnh
02/25/2019, 11:20 PM