I am wondering if there's a better way to rewrite the groupA method with lambda as part of the chaining operations ?
public class Id {
private final int value;
public Id(int value) {
this.value = value;
}
public int value() {
return value;
}
}
public class Ids implements Iterable<Id> {
private final List<Id> ids;
private Ids(List<Id> ids) {
this.ids = ids;
}
public static Ids of(List<Id> ids) {
return new Ids(ids);
}
public Ids groupA() {
return Ids.of(ids.stream()
.filter(id -> id.value() > 5)
.collect(Collectors.toList()));
}
@Override
public Iterator<Id> iterator() {
return ids.iterator();
}
}
Basically I want to do something like
ids.stream()
.filter(id -> id % 10 > 5)
.collect(Collectiors.toList())
.andThen(Ids::of);
And wonder if that's possible