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
import io.konad.Result | |
inline class NotEmptyString | |
@Deprecated(level = DeprecationLevel.ERROR, message = "use companion method 'of'") | |
constructor(val value: String){ | |
companion object{ | |
@Suppress("DEPRECATION_ERROR") | |
fun of(value: String): Result<NotEmptyString> = valikate { | |
validate(NotEmptyString(value)){ | |
validate(NotEmptyString::value).isNotBlank() |
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
inline class NotEmptyString | |
@Deprecated(level = DeprecationLevel.ERROR, message = "use companion method 'of'") | |
constructor(val value: String){ | |
@Suppress("DEPRECATION_ERROR") | |
companion object{ | |
fun of(value: String): NotEmptyString = validate(NotEmptyString(value)){ | |
validate(NotEmptyString::value).isNotBlank() | |
} | |
} | |
} |
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
data class PersonalName( | |
val firstname: NotEmptyString, | |
val middleInitial: NotEmptyString?, // Here it clearly states that could be missing | |
val lastname: NotEmptyString) |
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
data class PersonalName( | |
val firstname: String, | |
val middleInitial: String, | |
val lastname: String) | |
data class Email( | |
val value: String, | |
val isVerified: Boolean) | |
data class ContactInfo( |
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
data class ContactInfo( | |
val firstname: String, | |
val middleInitial: String, | |
val lastname: String, | |
val email: String, | |
val emailIsVerified: Boolean) |
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 becomeRich(crypto: CryptoInfo, buyInfo: BuyCryptoInfo): Boolean = false | |
val user = CryptoUser(username = "foo.bar", ..., ...) | |
val crypto = CryptoInfo("Bitcoin") | |
val youGotRich1: Result<Boolean> = ::becomeRich + crypto + BuyCryptoInfo.from1(user) | |
// or | |
val youGotRich2: Result<Boolean> = BuyCryptoInfo.from1(user) |
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
import io.konad.* | |
data class BuyCryptoInfo( | |
val username: String, | |
val phoneNumber: PhoneNumber, | |
val creditCard: CreditCard, | |
val kycVerification: KycVerificationData){ | |
companion object{ | |
// If you want to go for errors |
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
data class BuyCryptoInfo( | |
val username: String, | |
val phoneNumber: PhoneNumber, | |
val creditCard: CreditCard, | |
val kycVerification: KycVerificationData){ | |
companion object{ | |
fun from1(user: CryptoUser): Result<BuyCryptoInfo> = with(user){ | |
val listOfErrors = mutableListOf<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
sealed class Result<out T>{ | |
data class Ok<out T>(val value: T): Result<T>() | |
data class Error(val description: String): Result<Nothing>() | |
} | |
data class BuyCryptoInfo( | |
val username: String, | |
val phoneNumber: PhoneNumber, | |
val creditCard: CreditCard, | |
val kycVerification: KycVerificationData){ |
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
data class BuyCryptoInfo( | |
val username: String, | |
val phoneNumber: PhoneNumber, | |
val creditCard: CreditCard, | |
val kycVerification: KycVerificationData){ | |
companion object{ | |
fun from1(user: CryptoUser): BuyCryptoInfo? = with(user){ | |
if(phoneNumber != null && creditCard != null && kycVerification != null) | |
BuyCryptoInfo(username, phoneNumber, creditCard, kycVerification) |