Skip to content

Instantly share code, notes, and snippets.

@lucapiccinelli
Last active April 19, 2021 05:27
Show Gist options
  • Save lucapiccinelli/b69bd97101916d561cc9efff9a88b513 to your computer and use it in GitHub Desktop.
Save lucapiccinelli/b69bd97101916d561cc9efff9a88b513 to your computer and use it in GitHub Desktop.
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
fun from1(user: CryptoUser): Result<BuyCryptoInfo> = with(user){
::BuyCryptoInfo +
username +
phoneNumber.ifNull("missing phone number") +
creditCard.ifNull("missing credit card") +
kycVerification.ifNull("missing kyc verification")
}
// If you want to go just for a null
fun from2(user: CryptoUser): BuyCryptoInfo? = with(user){
::BuyCryptoInfo +
username +
phoneNumber +
creditCard +
kycVerification
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment