cheptsov / AdvancedExpressionFolding

https://plugins.jetbrains.com/plugin/9320?pr=idea
140 stars 30 forks source link

map / orElse foldings #125

Open iirekm opened 5 years ago

iirekm commented 5 years ago

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 commented 5 years ago

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);
  2. 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 commented 5 months ago

@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.

https://github.com/AntoniRokitnicki/AdvancedExpressionFolding/pull/10