// Accept slices of T
func someSliceFunc(type T)(s []T){ ... }
// Accept a 1 member array of T
func someArrayFunc(type T)(a [1]T){ ... }
...
// For what ever number of specific length arrays you wish to support.
func someBiggerArrayFunc(type T)(a [???]T){ ... }
// Accept any length of array or slice of T
func someFunc(type T)(a [...]T){ ... }
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/f70ef878-622a-4b8e-94ca-40331df866e9o%40googlegroups.com.
Why not just accept slices only and expect the caller to add a `[:]`? It's not quite as ergonomic, but should have the same effect and we wouldn't need to add complexity to the design.
On Wed, Jul 15, 2020 at 4:58 PM <hsoo...@gmail.com> wrote:
--Right now as I understand it, I would still have to write a different generic function for different length arrays, or one that accepted slices. as per:
// Accept slices of T
func someSliceFunc(type T)(s []T){ ... }// Accept a 1 member array of T
...
func someArrayFunc(type T)(a [1]T){ ... }
// For what ever number of specific length arrays you wish to support.
func someBiggerArrayFunc(type T)(a [???]T){ ... }
It would be nice to indicate the generic function accepts any length of array as well as slices, something like:
// Accept any length of array or slice of T
func someFunc(type T)(a [...]T){ ... }
Where the [...] indicates the function works with any length array or a slice.Russell
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 golan...@googlegroups.com.