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

Fix truncateToSeconds extension function signature to receive non-null only #1

Closed
FrancescoJo opened this issue Feb 22, 2022 · 0 comments
Assignees
Labels
breaking Involves a breaking change enhancement New feature or request

Comments

@FrancescoJo
Copy link
Collaborator

AS-IS

fun Instant?.truncateToSeconds(): Instant? =
    this?.truncatedTo(ChronoUnit.SECONDS)

TO-BE

fun Instant.truncateToSeconds(): Instant =
    this.truncatedTo(ChronoUnit.SECONDS)

MOTIVATION

Receiving a nullable Instant instance in this case is almost useless. Since Kotlin natively supports nullsafe operator(?.), invoking truncateToSeconds via null safe call still conserve nullity of receiving object. For non-null cases, however, this call converts receiving instance as 'maybe' type and it adds a mandatory, cumbersome non-null assertion operator(!!) which degrades code readibility.

IMPACT

truncateToSeconds calls on nullable instance will not compile after this fix.

@FrancescoJo FrancescoJo self-assigned this Feb 22, 2022
@FrancescoJo FrancescoJo added breaking Involves a breaking change enhancement New feature or request labels Feb 22, 2022
@FrancescoJo FrancescoJo changed the title Fix truncateToSeconds extension signature to receive non-null only Fix truncateToSeconds extension function signature to receive non-null only Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Involves a breaking change enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant