You can easily get it to work, but not in a useful way I guess.

https://go.dev/play/p/mq0O8OhJ1-a

You could have a different template for each type you use I guess.

-Bruno


On Mon, Mar 6, 2023 at 4:43 PM Rory Campbell-Lange <r...@campbell-lange.net>
wrote:

> Hi. I have a generic function
>
> func slicerG[A any](s []A, i int) []A {
>         fmt.Println(len(s), i)
>         if i > len(s) {
>                 return s
>         }
>         return s[0:i]
> }
>
> When I try to register this in a template's FuncMap, it fails with
>
>     "cannot use generic function slicerG without instantiation"
>
> https://go.dev/play/p/KpvrbbcTaM2
>
> I guess this makes sense if the compiler is converting the function to
> function variants of particular types based on instantiation, but is there
> any way around this?
>
> Thanks,
> Rory
>
> --
> 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/ZAZelXNTAEaXy0cs%40campbell-lange.net
> .
>

-- 
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/CAEd86Tzd7YUeNfiJapN7bqWfq%2Bb4xff8oWbcxGK6RnbscVNMAQ%40mail.gmail.com.

Reply via email to