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

map / orElse foldings #125

Open
iirekm opened this issue Aug 27, 2018 · 2 comments
Open

map / orElse foldings #125

iirekm opened this issue Aug 27, 2018 · 2 comments

Comments

@iirekm
Copy link

iirekm commented Aug 27, 2018

Java 8 code contains a lot of stuff like

optional.map(Obj::x).map(it -> it.y()).orElse(z())

it would be nice to have on the screen just:

optional?.x()?.y() ?: z()

Similarly for streams:

stream.map(Obj::x).map(it -> it.y())

can be:

stream*.x()*.y()
@stokito
Copy link

stokito commented Sep 25, 2018

Here we can split into two things:

  1. Fold Optional to null safe operators. For example on my working project it's very popular to use Optional as Elvis operator:
BigDecimal totalAmount = Optional .ofNullable(amount).orElse(BigDecimal.ZERO);
  1. Replace Stream.map() with spread operator.
    But here is not so straightforward: there is other map* functions, it will look not consistent to others.

@AntoniRokitnicki
Copy link

AntoniRokitnicki commented Jan 21, 2024

@iirekm @stokito I have incorporated the Optional feature, and I plan to implement the spread operator in upcoming implementations. For further details, please refer to my branch.

AntoniRokitnicki#10

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

No branches or pull requests

3 participants