Skip to content

Instantly share code, notes, and snippets.

@yongjhih
Created November 22, 2023 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yongjhih/3bc8feefcda9cc265f22efeece11b318 to your computer and use it in GitHub Desktop.
Save yongjhih/3bc8feefcda9cc265f22efeece11b318 to your computer and use it in GitHub Desktop.
fun <T> byWeakReference(initialValue: T? = null): MutableProperty<T?> = mutablePropertyOf(WeakReference(initialValue)).map(
set = { if (this.field.get() == it) this.field else WeakReference(it) },
get = { it.get() },
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment