42 lines
594 B
Go
42 lines
594 B
Go
package do
|
|
|
|
func empty[T any]() (t T) {
|
|
return
|
|
}
|
|
|
|
func must(err error) {
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func keys[K comparable, V any](in map[K]V) []K {
|
|
result := make([]K, 0, len(in))
|
|
|
|
for k := range in {
|
|
result = append(result, k)
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
func mAp[T any, R any](collection []T, iteratee func(T) R) []R {
|
|
result := make([]R, len(collection))
|
|
|
|
for i, item := range collection {
|
|
result[i] = iteratee(item)
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
func invertMap[K comparable, V comparable](in map[K]V) map[V]K {
|
|
out := map[V]K{}
|
|
|
|
for k, v := range in {
|
|
out[v] = k
|
|
}
|
|
|
|
return out
|
|
}
|