Indeed. In hindsight, I should've predicted that.
I think you are SOOL then, in general. I'd suggest using ~[]E directly and
do the "scalar" case as a 1-element slice then.
For a function, you can write `func F[E any](e ...E)`, which makes it
callable with any number of arguments. Or `func F[E any
Gave it a try on playground, but this unfortunately raises the error "term
cannot be a type parameter" for the E | ~[]E.
On Friday, August 12, 2022 at 3:18:05 PM UTC+2 axel.wa...@googlemail.com
wrote:
> type ScalarOrSlice[E any] interface {
> E | ~[]E
> }
>
> func New[E any, T ScalarOrSlice
type ScalarOrSlice[E any] interface {
E | ~[]E
}
func New[E any, T ScalarOrSlice[E]](v T) { … }
Though I haven't tested this.
On Fri, Aug 12, 2022 at 3:07 PM TheDiveO wrote:
> I would like to provide a generics-based type-safe API that accepts either
> a scalar or slice of some type T (not
I would like to provide a generics-based type-safe API that accepts either
a scalar or slice of some type T (not a type parameter), that is, the type
constraint is (if I'm not mistaken) "T | []T".
While I understand that this constraint would be declared as an interface
(simplified example)...
Maybe there is a language barrier. My statement implied Go was a modern
language yet it did not have a streams package - not that it was not a modern
language.
You seem to be looking for a fight and I’m not sure why. Why don’t you focus on
solutions - it’s better for everyone.
> On Aug 12, 2
On Thu, Aug 11, 2022 at 11:18 PM Robert Engels wrote:
> Every modern language with generics or similar has a streams package so
> there’s no need to call out Java.
For some reason unknown to me you seem to consider Go not being a
modern language as it does not have a "streams" package. I don't
See https://github.com/golang/go/issues/45380 for a proposal for a language
feature that would allow this. In the meantime, you can convert to any, and
type switch on that:
func Foo[T allowedTypes](arg T) {
switch t := any(arg).(type) {
case int64:
...
On Fri, 12 Aug 2022, 00:40 'Matt Ro