icerockdev / moko-network

Network components with codegeneration of rest api for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev
Apache License 2.0
151 stars 29 forks source link

Add method to Safeable to map null to a particular value #202

Open dalewking opened 1 year ago

dalewking commented 1 year ago

When encountering a null value for Safeable often you just want to map that to one of the existing enum values and one can do that in the accessing code with Elvis operator and perhaps some added parentheses, but it would seem to me that it would improve readability if Safeable had a method like:

   fun valueOrElse(defaultValue: T) = value ?: defaultValue