Skip to content

Instantly share code, notes, and snippets.

@sitepodmatt
Created July 3, 2017 05:32
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 sitepodmatt/dab8f9d768f549f842702061d84e8f5c to your computer and use it in GitHub Desktop.
Save sitepodmatt/dab8f9d768f549f842702061d84e8f5c to your computer and use it in GitHub Desktop.
data class Informer<T : Resource>(val blah : Int = 1) {
private var started = false
fun start(): Boolean {
if (!started) {
this.started = true
return true
} else {
return false
}
}
fun start2(): Boolean {
return if (this.started) false else run {
this.started = true
true
}
}
fun start3(): Boolean = if (this.started) false else run {
this.started = true
true
}
}
@ilya-g
Copy link

ilya-g commented Jul 3, 2017

fun start4(): Boolean = (!started).also { if (!started) started = true }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment