Last active
May 26, 2018 23:41
-
-
Save sliskiCode/805a243ff75f47d07f9c62900da7279b to your computer and use it in GitHub Desktop.
6 magic sugars that can make your Kotlin codebase happier #23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReferencedProperty<T>(private val get: () -> T, | |
private val set: (T) -> Unit = {}) { | |
operator fun getValue(thisRef: Any?, | |
property: KProperty<*>): T = get() | |
operator fun setValue(thisRef: Any?, | |
property: KProperty<*>, | |
value: T) = set(value) | |
} | |
fun <T> ref(property: KMutableProperty0<T>) = ReferencedProperty(property::get, | |
property::set) | |
fun <T> ref(property: KProperty0<T>) = ReferencedProperty(property::get) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment