News for hackers. Stuff that matters.
Re:Good-bye core types; Hello Go as we know and love it by wwarner on Wednesday March 26, 2025 @05:23PM (#43487470)
anything you can ‘range’ over :)
Re:Good-bye core types; Hello Go as we know and love it by hnlmorg on Wednesday March 26, 2025 @05:53PM (#43487827)
That’s been possible for a couple of releases now

In fact I created a struct that you can range over just a couple of days ago.

I can’t say I love the way Go implemented it though. But it does work.

Re:Good-bye core types; Hello Go as we know and love it by wwarner on Wednesday March 26, 2025 @07:35PM (#43488764)
did not know this thank you!
Re:Good-bye core types; Hello Go as we know and love it by fuzztester on Wednesday March 26, 2025 @09:17PM (#43489449)
You can range over the fields of a struct?
Re:Good-bye core types; Hello Go as we know and love it by dharmab on Thursday March 27, 2025 @01:14AM (#43490569)
https://go.dev/play/p/Is1uwjRGASI

But I suspect they meant a struct which contains/encapsulates data which can be ranged over.

Re:Good-bye core types; Hello Go as we know and love it by fuzztester on Monday March 31, 2025 @03:56PM (#43539151)
thanks
Re:Good-bye core types; Hello Go as we know and love it by fuzztester on Wednesday March 26, 2025 @09:20PM (#43489469)
>I can’t say I love the way Go implemented it though.

Why not?

Re:Good-bye core types; Hello Go as we know and love it by hnlmorg on Thursday March 27, 2025 @03:43AM (#43491247)
It might just be user error on my part but it wasn’t entirely clear to me:

1. How it should be implemented “correctly”

2. The resulting code isn’t clear how it works at first glance (particularly with the yield command, it has “magical” properties that take a little effort to grok)

3. Requires calling a method

Example code: https://github.com/lmorg/Ttyphoon/blob/321738f289e4791e9674d...

I did write this at something like 11pm so it’s entirely possible I’ve done this completely wrong though.

Also please ignore the weird use of mutexes here too.

I’m also aware that sync.Map could/should have been used here. This struct was more of an experiment than anything that will ultimately find its way into production code.

Re:Good-bye core types; Hello Go as we know and love it by dharmab on Thursday March 27, 2025 @04:00AM (#43491320)
In this specific case, one could do something like https://github.com/dharmab/skyeye/blob/main/pkg/radar/contac.... But your critique is still relevant for cases where you are generating/querying items on demand.
Re:Good-bye core types; Hello Go as we know and love it by hnlmorg on Thursday March 27, 2025 @11:21AM (#43494584)
Thanks for sharing that. I’ll give that a play tonight.
Re:Good-bye core types; Hello Go as we know and love it by umanwizard on Wednesday March 26, 2025 @05:45PM (#43487739)
Go added support for custom iterators a few versions ago.
Re:Good-bye core types; Hello Go as we know and love it by dharmab on Wednesday March 26, 2025 @05:30PM (#43487562)
I have written my own types that can do this?

EDIT: Had to check, yeah I had to implement the iter.Seq type to do it