Randgalt / record-builder

Record builder generator for Java records
Apache License 2.0
758 stars 55 forks source link

[proposal] generate increment methods for numeric fields #171

Open eshepelyuk opened 8 months ago

eshepelyuk commented 8 months ago

Hello

it could be useful to have methods that return a copy of record with particular numeric field (including BigDecimal) increased by a value.

I.e. instead of this

import io.soabase.recordbuilder.core.RecordBuilder;

@RecordBuilder
public record MyRec(Long cnt) implements MyRecBuilder.With {}

var r1 = new MyRec(10L);
var r2 = r1.withCnt(r1.cnt() + 5);

One could write smth like this

var r2 = r1.incrCnt(5);

Basically all java operaators like += , -= etc could be generated, so one could write

r1.plusCnt(5); // += 5
r1.divCnt(5); // %= 5

etc