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
// UserRepository interface | |
interface UserRepository { | |
suspend fun isBiometricsOptedIn(): Boolean | |
} | |
// SessionController interface | |
interface SessionController { | |
suspend fun biometricOptIn(): BiometricResult | |
suspend fun biometricOptOut(): BiometricResult | |
} |
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.example.codesnippetsforinterviews | |
class User( | |
val name: String, val age: String, val address: Address, medicalRecordNumber: String, | |
primaryDiagnosis: List<String> | |
) | |
class Address( | |
var s1: String, var s2: String, | |
var c: String, var zc: String, | |
medicalRecordNumber: String, serviceArea: String |
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
private fun processSuccess(response: RefreshResponse) { | |
// before 1.5 | |
run msgLoop@{ | |
response.messages.forEach { message -> | |
val user = extractUserData(message) | |
if (user != null) { | |
logLastMessage(message.userData) | |
return@msgLoop | |
} | |
} |
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
@JvmInline | |
value class PreferredFirstNameInline(private val name: String) // No overhead for PreferredFirstNameInline class unless needed for boxing | |
// as compared to | |
data class PreferredFirstName(private val name: String) | |
fun main() { | |
// The Java code decompiled from the bytecode shows the underlying implementation. | |
val inlineFirstName = PreferredFirstNameInline("fred") // Implemented by static method | |
/** |
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
sealed interface NewSession { | |
fun showMessage() | |
} | |
sealed interface ExistingSession | |
sealed class Navigation | |
class PreviousPage : Navigation(), ExistingSession | |
class NextPage : Navigation(), ExistingSession | |
class Home : Navigation(), NewSession { | |
override fun showMessage() {} |
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 interface DataChangeNotifier { | |
fun publishDataChange() | |
} |
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 notifyAppointmentDataChanges() { | |
val notifier = DataChangeNotifier { apptDataPubSub.onNext() } | |
notifier.publishDataChange() | |
} |
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 notifyAppointmentDataChangesNonFunctional() { | |
val notifier = object : DataChangeNotifier { | |
override fun publishDataChange() { | |
apptDataPubSub.onNext() | |
} | |
} | |
notifier.publishDataChange() | |
} |
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
for (proxy in proxyList) { | |
when (proxy.relation) { | |
(Proxy.RELATION_SELF) -> break | |
(Proxy.RELATION_CHILD) -> continue | |
(Proxy.RELATION_TEEN) -> { | |
// Logic for teen relation | |
} | |
} | |
// Additional processing | |
} |
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
PROXYLOOP@for (proxy in proxyList) { | |
when (proxy.relation) { | |
(Proxy.RELATION_SELF) -> break@PROXYLOOP | |
(Proxy.RELATION_CHILD) -> continue@PROXYLOOP | |
(Proxy.RELATION_TEEN) -> { | |
// Logic for teen relation | |
} | |
} | |
// Additional processing | |
} |
NewerOlder