balances.NotLike
parent
f41386b3b4
commit
fe8d80ffc8
|
|
@ -11,6 +11,17 @@ type Balances map[string]Balance
|
|||
|
||||
type Balance map[Currency]float64
|
||||
|
||||
func (balances Balances) NotLike(pattern string) Balances {
|
||||
result := make(Balances)
|
||||
p := regexp.MustCompile(pattern)
|
||||
for k, v := range balances {
|
||||
if !p.MatchString(k) {
|
||||
result[k] = maps.Clone(v)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (balances Balances) Like(pattern string) Balances {
|
||||
result := make(Balances)
|
||||
p := regexp.MustCompile(pattern)
|
||||
|
|
|
|||
|
|
@ -61,6 +61,11 @@ func TestBalances(t *testing.T) {
|
|||
if len(got) != 1 || got["ab"][USD] != 1.2 {
|
||||
t.Error(got)
|
||||
}
|
||||
|
||||
got = was.NotLike(`^ab$`)
|
||||
if len(got) != 1 || got["a"][USD] != 0.1 {
|
||||
t.Error(got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("group", func(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -8,11 +8,20 @@ type Like func(Delta) bool
|
|||
|
||||
type Likes []Like
|
||||
|
||||
func LikeTransaction(delta Delta) Like {
|
||||
func LikeTransactions(deltas ...Delta) Like {
|
||||
return func(d Delta) bool {
|
||||
return d.Transaction == delta.Transaction
|
||||
for i := range deltas {
|
||||
if deltas[i].Transaction == d.Transaction {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func LikeTransaction(delta Delta) Like {
|
||||
return LikeTransactions(delta)
|
||||
}
|
||||
|
||||
func LikeBefore(date string) Like {
|
||||
return func(d Delta) bool {
|
||||
|
|
|
|||
Loading…
Reference in New Issue