Last active
April 19, 2021 05:27
-
-
Save lucapiccinelli/b69bd97101916d561cc9efff9a88b513 to your computer and use it in GitHub Desktop.
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 | |
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