This file contains hidden or 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
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) | |
} |
This file contains hidden or 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 userNameAndStatePair: Pair<String?, String?> = getUserNameAndState(101) | |
println(userNameAndStatePair.first) // Chike | |
println(userNameAndStatePair.second) // Lagos |
This file contains hidden or 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, state) = getUserNameAndState(101) | |
println(name) // Chike | |
println(state) // Lagos |
This file contains hidden or 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
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) |
This file contains hidden or 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
package com.chikekotlin.projectx | |
fun saySomething(): String { | |
return "How far?" | |
} |
This file contains hidden or 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
package com.chikekotlin.projectx.utils | |
fun checkUserStatus(): String { | |
return "online" | |
} |
This file contains hidden or 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
package com.chikekotlin.projectx.utils | |
fun checkUserStatus(): String { | |
return "online" | |
} |
This file contains hidden or 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
package com.chikekotlin.projectx.users | |
import com.chikekotlin.projectx.utils.checkUserStatus | |
if (checkUserStatus() == "online") { | |
// do something | |
} |
This file contains hidden or 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
fun test() { | |
var mood = "I am sad" | |
run { | |
val mood = "I am happy" | |
println(mood) // I am happy | |
} | |
println(mood) // I am sad | |
} |
This file contains hidden or 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
run { | |
if (firstTimeView) introView else normalView | |
}.show() |