So, for instance, this appears to compile, but I haven't run it yet: func getFromCommitsCache[T any](project string, repo string, branch string) ([]T, bool) { commitsCacheMutex.RLock() defer commitsCacheMutex.RUnlock() var result []T if commits, found := commitsCache[project+"/"+repo+"/"+branch]; found { for _, commit := range commits { result = append(result, commit.(T)) } return result, true } return nil, false }
func storeToCommitsCache[T any](project string, repo string, branch string, commits []T) { commitsCacheMutex.Lock() defer commitsCacheMutex.Unlock() var anyResult []any for _, commit := range commits { anyResult = append(anyResult, commit) } commitsCache[project+"/"+repo+"/"+branch] = anyResult } On Wednesday, February 12, 2025 at 2:33:51 PM UTC-8 David Karr wrote: > Ok, good to know. How do I solve this problem? It almost looks like I have > to create a slice of the generic type and iterate through the entries in > the commitsCache result, doing a type conversion of every entry. > > On Wednesday, February 12, 2025 at 2:15:03 PM UTC-8 Jan Mercl wrote: > >> On Wed, Feb 12, 2025 at 10:54 PM David Karr <davidmic...@gmail.com> >> wrote: >> >> `[]any` is a slice type (https://go.dev/ref/spec#Slice_types), not an >> interface type (https://go.dev/ref/spec#Interface_types). >> >> But type assertions, as in `expr.(someType)`, are valid only for >> interface types: https://go.dev/ref/spec#Type_assertions >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/b493ab36-1785-4d12-b39d-1162678f66dfn%40googlegroups.com.