Skip to content

Instantly share code, notes, and snippets.

@vodamiro
vodamiro / FunctionsAndLambdas.kt
Created Apr 11, 2019
S_A_FunctionsAndLambdas.kt
View FunctionsAndLambdas.kt
data class User(val name)
interface UserDataSource {
fun getAllUsers(
onSuccess: (users: List<User>) -> Unit,
onError: (err: Throwable) -> Unit
)
}
// class UpdateDataSourceImpl: UserDataSource { .... }
@vodamiro
vodamiro / Constructors.kt
Created Apr 11, 2019
S_A_Constructors.kt
View Constructors.kt
class InitOrderDemo(name: String) {
val firstProperty = "First property: $name".also(::println)
init {
println("First initializer block that prints ${name}")
}
val secondProperty = "Second property: ${name.length}".also(::println)
init {
View Elvis2.kt
val sum = a ?: (0 + b)
View Elvis.kt
val a: Int? = 10
val b: Int = 10
val sum = a ?: 0 + b
@vodamiro
vodamiro / RangesInLoops3.kt
Created Apr 11, 2019
S_A_RangesInLoops3.kt
View RangesInLoops3.kt
var max = 10
val range = IntRange(1, max)
for (i in range) {
// ...
}
@vodamiro
vodamiro / RangesInLoops2.kt
Last active Apr 12, 2019
S_A_RangesInLoops2.kt
View RangesInLoops2.kt
var max = 10;
for (int i = 1 ; i <= max ; i++) {
// ...
}
@vodamiro
vodamiro / RangesAndLoops1.kt
Created Apr 11, 2019
S_A_RangesAndLoops1.kt
View RangesAndLoops1.kt
var max = 10
for (i in 1..max) {
// ...
}
@vodamiro
vodamiro / FunctionsAndLambdas.kt
Created Apr 11, 2019
S_A_FunctionsAndLambdas.kt
View FunctionsAndLambdas.kt
data class User(val name)
interface UserDataSource {
fun getAllUsers(
onSuccess: (users: List<User>) -> Unit,
onError: (err: Throwable) -> Unit
)
}
// class UpdateDataSourceImpl: UserDataSource { .... }
@vodamiro
vodamiro / PropertyDelegates.kt
Created Apr 11, 2019
S_A_PropertyDelegates.kt
View PropertyDelegates.kt
val answer: Int by lazy {
computeAnswer()
}
fun computeAnswer() = 42
@vodamiro
vodamiro / ScopeFunctions.kt
Created Apr 11, 2019
S_A_ScopeFunctions.kt
View ScopeFunctions.kt
private const val DURATION_IN_MS = 3000L
val fadeInAnimation = AlphaAnimation(0f, 1f).apply {
duration = DURATION_IN_MS
interpolator = AccelerateDecelerateInterpolator()
fillAfter = true
}