I have come across code in my companies project, which goes like this
void pAccount(List<Account> accounts) {
accounts.stream()
.filter(o->getKey(o) != null)
.collect(Collectors.groupingBy(this::getKey))
.forEach(this::pAccounts);
}
private Key getKey(Account account) {
return keyRepository.getKeyById(account.getId());
}
private void pAccounts(Key key , List<Account> accounts) {
//Some Code
}
While debugging we came to the conclusion that pAccount(List<Account> accounts) calls pAccounts(Key key , List<Account> accounts.
I have tried to find similar examples online but found nothing that matches this behavior.
I want to know if this is some kind of functionality in streams that allows us to do that or it's something else.