2022-11-23 05:05:39 +09:00
|
|
|
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
|
|
|
|
}
|
2023-03-20 19:12:41 +09:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|