Features: - CLI structure with verbs and resources - Application config and parameters - Output formatters - Initial resource: dishes Reviewed-on: #1 Co-authored-by: bdoerfchen <git@bissendorf.co> Co-committed-by: bdoerfchen <git@bissendorf.co>
34 lines
608 B
Go
34 lines
608 B
Go
package util
|
|
|
|
func Transform[Tin any, Tout any](s []Tin, transformFn func(i *Tin) Tout) (out []Tout) {
|
|
out = make([]Tout, 0)
|
|
|
|
for _, item := range s {
|
|
out = append(out, transformFn(&item))
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func Select[T any](s []T, selectFn func(i *T) bool) (out []T) {
|
|
out = make([]T, 0)
|
|
|
|
for _, item := range s {
|
|
if selectFn(&item) {
|
|
out = append(out, item)
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func Map[T any, Tkey comparable, Tval any](s []T, transformFn func(i *T) (Tkey, Tval)) (out map[Tkey]Tval) {
|
|
out = make(map[Tkey]Tval)
|
|
for _, i := range s {
|
|
key, val := transformFn(&i)
|
|
out[key] = val
|
|
}
|
|
|
|
return
|
|
}
|