If I remember well, max(slice...) existed but not anymore: it disappeared
with Go 1.21 I think. The idea was to force one element at least -> why
not, that's the "min/max business" I may say.
But the "unpacking" operator is a builtin and should be allowed for all
func with a variadic input param. For min/max, it's not the case.... And as
you said "there is deep reason" which I don't really understand (not really
technically but much more as global understood of the ... operator mecanism
-> why unpacking couldn't be used with generic ?!)
Le lundi 20 janvier 2025 à 16:33:16 UTC+1, Stephen Illingworth a écrit :
> Oh I see what you mean now.
>
> Should max(slice...) be allowed (ie. just the slice and no unary value) ?
> It would behave like slices.Max() I think. Maybe there is deep reason for
> not allowing but it would be nice to have for sure.
>
> On Monday, 20 January 2025 at 15:21:10 UTC Benoît Marguerie wrote:
>
>> Hi Stephen,
>> max(5,slice) has no sense by itself, I'm agree with you.
>>
>> But the issue is about max(5,*slice...*) which should accept the
>> "unpacking" operation like the append function. I know there's a buildin
>> type "Type" for append while the min/max functions use the Generic with the
>> interface cmp.Ordered but from an "usage point of view", it doesn't seem
>> "understandable".
>>
>> Le lundi 20 janvier 2025 à 16:14:54 UTC+1, Stephen Illingworth a écrit :
>>
>>> What value do you think should be returned for "max(5, slice)" ?
>>>
>>> On Monday, 20 January 2025 at 15:00:04 UTC Benoît Marguerie wrote:
>>>
>>>> Hi,
>>>>
>>>> Even if the spec precises :
>>>> > slice arguments are not permitted
>>>>
>>>> I wonder if there's any real technical reason to prohibit the use of
>>>> the slice variadics during *min/max* buildin functions, when it's
>>>> allowed with *append* (which creates inconsistent behavior between
>>>> buildin functions)?
>>>>
>>>> Example:
>>>> ```
>>>> func main() {
>>>> slice := []int{0, 1, 2, 3, 4, 5, 6, 7}
>>>> padding := []int{8, 9}
>>>>
>>>> slice = append(slice, padding...)
>>>> forbidden := max(5, slice...) //Doesn't build due to this line....
>>>>
>>>> fmt.Println(forbidden)
>>>> }
>>>> ```
>>>> -> https://go.dev/play/p/pWzf9WKgW3q
>>>>
>>>>
--
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 [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/golang-nuts/438b052f-005f-47e3-bac0-17e92767927cn%40googlegroups.com.