Preferences

anything you can ‘range’ over :)

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.

>I can’t say I love the way Go implemented it though.

Why not?

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.

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.
Thanks for sharing that. I’ll give that a play tonight.
You can range over the fields of a struct?
https://go.dev/play/p/Is1uwjRGASI

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

did not know this thank you!
Go added support for custom iterators a few versions ago.
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

This item has no comments currently.

Keyboard Shortcuts

Story Lists

j
Next story
k
Previous story
Shift+j
Last story
Shift+k
First story
o Enter
Go to story URL
c
Go to comments
u
Go to author

Navigation

Shift+t
Go to top stories
Shift+n
Go to new stories
Shift+b
Go to best stories
Shift+a
Go to Ask HN
Shift+s
Go to Show HN

Miscellaneous

?
Show this modal