- Added the between operator to query expressions. - Added the using query expression suffix to specify which index to query (or force a scan). This is required if query planning has found multiple indices that can potentially be used. - Rewrote the types of the query expressions to allow for functions to be defined once, and be useful in queries that result in DynamoDB queries, and evaluation. - Added some test functions around time and summing numbers. - Fixed a bug in the del-attr which was not honouring marked rows in a similar way to set-attr: it was only deleting attributes from the first row. - Added the -to type flag to set-attr which will set the attribute to the value of a query expression.
34 lines
583 B
Go
34 lines
583 B
Go
package maputils
|
|
|
|
func Values[K comparable, T any](ts map[K]T) []T {
|
|
values := make([]T, 0, len(ts))
|
|
for _, v := range ts {
|
|
values = append(values, v)
|
|
}
|
|
return values
|
|
}
|
|
|
|
func MapValues[K comparable, T, U any](ts map[K]T, fn func(t T) U) map[K]U {
|
|
us := make(map[K]U)
|
|
|
|
for k, t := range ts {
|
|
us[k] = fn(t)
|
|
}
|
|
|
|
return us
|
|
}
|
|
|
|
func MapValuesWithError[K comparable, T, U any](ts map[K]T, fn func(t T) (U, error)) (map[K]U, error) {
|
|
us := make(map[K]U)
|
|
|
|
for k, t := range ts {
|
|
var err error
|
|
us[k], err = fn(t)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return us, nil
|
|
}
|