Let's suppose that i have an Array of objects (Payment) :

```
listPayments=[Payment(type='check', amount=25),Payment(type='cash', amount=20),Payment(type='check', amount=25),Payment(type='cash', amount=20)]

```

i want to get an array that contains objects with amount sum based on payment type like so :

```
filtredList = [Payment(type='check', amount=50),Payment(type='cash', amount=40)]

```

But ***i don't want to hard code the type*** because i can have multiple payment types, can you help me to find a generic way to do this, thanks in advance.