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

[result4k] Introduce a way to early return on successful result with a null value #67

Merged
merged 1 commit into from
Aug 20, 2024

Conversation

th3n3rd
Copy link
Contributor

@th3n3rd th3n3rd commented Aug 20, 2024

In cases were is preferred to return a nullable type over using a failure to model the absence of a value, would be useful to have a more cohesive way to have an early return that abort the current function.

e.g.

val productDetails = productCatalogue.findById(123)
    .onFailure { return it }

if (productDetails == null) {
    return Success(Unit) // i.e. no-op
}

// ...

can now be written as

val productDetails = productCatalogue.findById(123)
    .onNull { return Success(Unit) } // i.e. no-op
    .onFailure { return it }

// ...

@th3n3rd th3n3rd changed the title Introduce a way to early return on successful result with a null value [result4k] Introduce a way to early return on successful result with a null value Aug 20, 2024
@daviddenton daviddenton merged commit d080e40 into fork-handles:trunk Aug 20, 2024
1 check passed
@daviddenton
Copy link
Member

It's a good change. Thanks @th3n3rd 🙃

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

Successfully merging this pull request may close these issues.

2 participants