28 lines
456 B
Go
28 lines
456 B
Go
package utils
|
|
|
|
func WaitFor(fn func()) <-chan struct{} {
|
|
ch := make(chan struct{})
|
|
go func() {
|
|
defer close(ch)
|
|
fn()
|
|
}()
|
|
return ch
|
|
}
|
|
|
|
func ToLookupMap[T comparable](s []T) map[T]struct{} {
|
|
m := make(map[T]struct{}, len(s))
|
|
for _, item := range s {
|
|
m[item] = struct{}{}
|
|
}
|
|
return m
|
|
}
|
|
|
|
func Reverse[T any](s []T) []T {
|
|
length := len(s)
|
|
reversed := make([]T, length)
|
|
for i, item := range s {
|
|
reversed[length-i-1] = item
|
|
}
|
|
return reversed
|
|
}
|