This file contains 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
plugins { | |
id("com.android.application") version "8.1.0" apply false | |
id("org.jetbrains.kotlin.android") version "1.8.0" apply false | |
id("com.google.dagger.hilt.android") version "2.47" apply false | |
} |
This file contains 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
plugins { | |
... | |
kotlin("kapt") | |
id("com.google.dagger.hilt.android") | |
id ("kotlin-parcelize") | |
} | |
android { |
This file contains 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
sealed class ApiResponse<out R> { | |
data class Success<out T>(val data: T) : ApiResponse<T>() | |
data class Error(val errorMessage: String) : ApiResponse<Nothing>() | |
object Empty : ApiResponse<Nothing>() | |
} |
This file contains 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
sealed class Resource<T>(val data: T? = null, val message: String? = null) { | |
class Success<T>(data: T) : Resource<T>(data) | |
class Loading<T>(data: T? = null) : Resource<T>(data) | |
class Error<T>(message: String, data: T? = null) : Resource<T>(data, message) | |
} |
This file contains 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
// 3. Inisialisasi variabel jumlah = 0 | |
// Untuk setiap nilai i dari 8 sampai 1 dengan langkah -1 | |
// Tambahkan nilai i ke dalam jumlah | |
// Tampilkan jumlah | |
// CODE: | |
#include <iostream> | |
using namespace std; |
This file contains 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
val numbers = mutableListOf(1, 2, 3) | |
val doubled = numbers.also { | |
it.add(4) | |
it.mapInPlace { num -> num * 2 } | |
} | |
println("Original List: $numbers") | |
println("Doubled List: $doubled") | |
// Output: | |
// Original List: [1, 2, 3, 4] |
This file contains 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
val result = run { | |
val a = 10 | |
val b = 20 | |
a + b | |
} | |
println("Result: $result") | |
// Output: Result: 30 |
This file contains 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 Person { | |
var name: String = "" | |
var age: Int = 0 | |
} | |
val person = Person().apply { | |
name = "R AL" | |
age = 22 | |
} |
This file contains 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
data class Person(val name: String, var age: Int) | |
val person = Person("Renren", 22) | |
with(person) { | |
println("Name: $name") | |
println("Age: $age") | |
age += 1 | |
} | |
// Output: | |
// Name: Renren |
This file contains 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
val name: String? = "Renren" | |
val length = name?.let { | |
println("Name is not null: $it") | |
it.length | |
} ?: 0 | |
// Output: Name is not null: Renren | |
// length = 4 |
NewerOlder