All great answers and thank you for the spec link!

On Thursday, February 20, 2025 at 8:07:42 PM UTC+1 Diogo Lisboa wrote:

> You have to remember that methods are just regular functions with the 
> receiver as the first parameter. From the spec (
> https://go.dev/ref/spec#Method_declarations):
>
> > A method is a function <https://go.dev/ref/spec#Function_declarations> with 
> a receiver.
>
> This mean that if you detach the method from the receiver, which 
> time.Time.Compare does, then it requires two arguments instead of one.
>
> a := time.Now()
> b := a.Add(1 * time.Hour)
> cmp := time.Time.Compare
> cmp(a) // error: not enough arguments in call to cmp
> cmp(a, b) // ok
>
> https://go.dev/play/p/x3ZGIhQ2TNE
>
>
> Diogo Lisboa
>
> On Thursday, February 20, 2025 at 2:57:35 PM UTC-3 cpu...@gmail.com wrote:
>
>> Sorry for not finding a better than this click bait subject. 
>>
>> In https://github.com/golang/go/issues/62642 this suggestion was made:
>>
>> slices.SortFunc(times, time.Time.Compare)
>>
>> It's totally unclear to me how Time.Compare matches the compare func(a,b 
>> T) int signature? I assume it's something from the golang spec, but which 
>> part?
>>
>> Are there other typical uses of this capability that are common?
>>
>> Cheers,
>> Andi
>>
>

-- 
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 visit 
https://groups.google.com/d/msgid/golang-nuts/b8199569-d85d-4138-9465-3d32d2dbca3en%40googlegroups.com.

Reply via email to