On Fri, May 7, 2021 at 11:08 AM Viet Nguyen <afel...@gmail.com> wrote:
>
> I'm trying to convert this code to use generics:
>
> type Cache interface {
> GetIfPresent(interface{}) (interface{}, bool)
> }
>
> type LoadingCache interface {
> Cache
> Get(interface{}) (interface{}, error)
> }
>
> However, I couldn't find any way to include Cache[K, V] in LoadingCache[K, 
> V]. (No similar use cases in the proposal? I must miss something here). The 
> workaround is copying all methods over, like:
>
> type Cache[K comparable, V any] interface {
> GetIfPresent(K) (V, bool)
> }
>
> type LoadingCache[K comparable, V any] interface {
> GetIfPresent(K) (V, bool) // FIXME: Embedding the Cache interface
> Get(K) (V, error)
> }
>
> // See: https://go2goplay.golang.org/p/T7h15CdUEa3
> // WIP: https://github.com/goburrow/cache/tree/go2

The go2go tool is an experiment and it does not support all valid
code.  It's particularly bad at embedding.  In the real release it
should work to write

type LoadingCache[K comparable, V any] interface {
    Cache[K, V]
    Get(K) (V, error)
}

Ian

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVU%3DgrZYLpHcDZD-G0v4UPodpLB27DXGo2%3DmUVc%3D%2Bws8w%40mail.gmail.com.

Reply via email to