Skip to content

Instantly share code, notes, and snippets.

View sajjadyousefnia's full-sized avatar
🤒
Out sick

Sajjad Yousefnia sajjadyousefnia

🤒
Out sick
View GitHub Profile
fun getUserNameAndState(id: Int): Pair<String?, String?> {
require(id > 0, { "Error: id is less than 0" })
val userNames: Map<Int, String> = mapOf(101 to "Chike", 102 to "Segun", 104 to "Jane")
val userStates: Map<Int, String> = mapOf(101 to "Lagos", 102 to "Imo", 104 to "Enugu")
val userName = userNames[id]
val userState = userStates[id]
return Pair(userName, userState)
}
val userNameAndStatePair: Pair<String?, String?> = getUserNameAndState(101)
println(userNameAndStatePair.first) // Chike
println(userNameAndStatePair.second) // Lagos
val (name, state) = getUserNameAndState(101)
println(name) // Chike
println(state) // Lagos
fun getUserNameStateAndAge(id: Int): Triple<String?, String?, Int> {
require(id > 0, { "id is less than 0" })
val userNames: Map<Int, String> = mapOf(101 to "Chike", 102 to "Segun", 104 to "Jane")
val userStates: Map<Int, String> = mapOf(101 to "Lagos", 102 to "Imo", 104 to "Enugu")
val userName = userNames[id]
val userState = userStates[id]
val userAge = 6
return Triple(userNames[id], userStates[id], userAge)
package com.chikekotlin.projectx
fun saySomething(): String {
return "How far?"
}
package com.chikekotlin.projectx.utils
fun checkUserStatus(): String {
return "online"
}
package com.chikekotlin.projectx.utils
fun checkUserStatus(): String {
return "online"
}
package com.chikekotlin.projectx.users
import com.chikekotlin.projectx.utils.checkUserStatus
if (checkUserStatus() == "online") {
// do something
}
fun test() {
var mood = "I am sad"
run {
val mood = "I am happy"
println(mood) // I am happy
}
println(mood) // I am sad
}
run {
if (firstTimeView) introView else normalView
}.show()