tgbot_misaka_5882f7/utils/utils.go

28 lines
456 B
Go
Raw Permalink Normal View History

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
}