-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction.go
35 lines (27 loc) · 863 Bytes
/
transaction.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package devto
type Transaction struct {
CheckNumber int `json:"check_number"`
Category string `json:"category"`
Amount float64 `json:"amount"`
RemainingBalance float64 `json:"remaining_balance"`
}
type TransactionCollection []Transaction
type TransactionCollectionMap map[string]TransactionCollection
type TransactionFilterFunc func(transaction Transaction) bool
type TransactionMapFunc func(transaction Transaction) Transaction
func (tc TransactionCollection) Filter(filterFunc TransactionFilterFunc) TransactionCollection {
var c TransactionCollection
for _, t := range tc {
if filterFunc(t) {
c = append(c, t)
}
}
return c
}
func (tc TransactionCollection) Map(mapFunc TransactionMapFunc) TransactionCollection {
var c TransactionCollection
for _, t := range tc {
c = append(c, mapFunc(t))
}
return c
}