Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

orNull way #283

Open
slavonnet opened this issue Feb 18, 2024 · 1 comment
Open

orNull way #283

slavonnet opened this issue Feb 18, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@slavonnet
Copy link

slavonnet commented Feb 18, 2024

Hello. I think that trows is not kotlin way

Please add orNull version to all toDecimals parsers. Look to some examples like String.toBooleranOrNull implementation

for example i create this

fun String.toBigDecimalOrNull (exponentModifier: Long? = null, decimalMode: DecimalMode? = null) : BigDecimal? = 
    runCatching { this.toBigDecimal(exponentModifier, decimalMode) }.getOrNull()

fun Byte.toBigDecimalOrNull (exponentModifier: Long? = null, decimalMode: DecimalMode? = null) : BigDecimal? =
    runCatching { this.toBigDecimal(exponentModifier, decimalMode) }.getOrNull()

fun Float.toBigDecimalOrNull (exponentModifier: Long? = null, decimalMode: DecimalMode? = null) : BigDecimal? =
    runCatching { this.toBigDecimal(exponentModifier, decimalMode) }.getOrNull()

fun Double.toBigDecimalOrNull (exponentModifier: Long? = null, decimalMode: DecimalMode? = null) : BigDecimal? =
    runCatching { this.toBigDecimal(exponentModifier, decimalMode) }.getOrNull()

fun  Long.toBigDecimalUsingSignificandAndExponentOrNull(exponent: Long, decimalMode: DecimalMode? = null) : BigDecimal? =
    runCatching { this.toBigDecimalUsingSignificandAndExponent(exponent, decimalMode) }.getOrNull()

fun  Int.toBigDecimalUsingSignificandAndExponentOrNull(exponent: Long, decimalMode: DecimalMode? = null) : BigDecimal? =
    runCatching { this.toBigDecimalUsingSignificandAndExponent(exponent, decimalMode) }.getOrNull()

P.S. Please add @Throws to throwable funcs.
P.S.S @SharedImmutable Depricated

P.P.P.S Intrestiong info from kotlin. not for this issue. Types definitions variants:

  • T - can be nullable becouse by default <T> == <T : Any?>
  • T? - is nullanle
  • T & Any - strict non null - new
@ionspin ionspin added the enhancement New feature or request label Feb 26, 2024
@Lysander
Copy link

Lysander commented Mar 21, 2024

As I mentioned in Issue #253 then orElse and/or orDefault would also make sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants