Skip to content

Instantly share code, notes, and snippets.

View AndroidPoet's full-sized avatar
God Mode

Ranbir Singh AndroidPoet

God Mode
View GitHub Profile
@Composable
fun SecondRootComposable() {
Box(Modifier.fillMaxSize()) { // Recomposition Scope Start
val scroll = rememberScrollState(0)
Title(snack = snack,scroll=scroll.value)
}
}
var name by remember { mutableStateOf("") }
@Composable
fun TextFieldDemo() {
Column(Modifier.padding(16.dp)) {
val textState = remember {mutableStateOf(mutableStateOf(""))}
TextField(
value = textState.value,
onValueChange = { textState.value = it }
)
Text("The textfield has this text:textState.value.text)
}
@Composable
fun RootComposable() {
var name by rememberSaveable { mutableStateOf("") }
HelloContent(name = name, onNameChange = { name = it })
}
@Composable
fun HelloContent(name: String, onNameChange: (String) -> Unit) {
Column(modifier = Modifier.padding(16.dp)) {
Text(
import android.util.Log
import com.currency.domain.CurrencyConverter
import io.ktor.client.*
import io.ktor.client.engine.android.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.plugins.logging.*
import io.ktor.client.plugins.observer.*
import io.ktor.serialization.kotlinx.json.*
import kotlinx.serialization.json.Json
//interface
interface CoroutineDispatcherProvider {
val main: CoroutineDispatcher
val io: CoroutineDispatcher
val default: CoroutineDispatcher
val unconfirmed: CoroutineDispatcher
}
//initialization using "by lazy"
open class RealCoroutineDispatcherProvider : CoroutineDispatcherProvider {
fun main() {
//var can be reassigned
var varInt: Int = 1
var varString: String = "Hello"
var varDouble: Double = 24.0
var varLong: Long = 30L
//val can't be reassigned
val valInt: Int = 1
fun main() {
printMessage("Hello")
printMessageWithPrefix("Hello", "World")
sum(4, 5)
multiply(4, 5)
}
fun printMessage(message: String) {
println(message)
@AndroidPoet
AndroidPoet / HigherOrderFunctions.kt
Created May 6, 2022 05:18
Higher-Order Functions
fun main() {
val sumResult = calculate(4, 5, ::sum) //sumResult 9,
val mulResult = calculate(4, 5) { a, b -> a * b } // mulResult 20
println("sumResult $sumResult, mulResult $mulResult")
}
fun calculate(x: Int, y: Int, operation: (Int, Int) -> Int): Int {
return operation(x, y)
val intList = mutableListOf(1, 2, 3, 4, 5, 6, 7)
val filtered = intList.filter {
it % 2 == 0
}
println(filtered)///[2, 4, 6]
val mapped = intList.map {
it * it
}