frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Pure vs. Impure Iterators in Go

https://jub0bs.com/posts/2025-05-29-pure-vs-impure-iterators-in-go/
44•ingve•3d ago

Comments

tapirl•3d ago
Be careful there are bugs and design flaws in Go iterators: https://go101.org/blog/2025-03-15-some-facts-about-iterators...
jub0bs•3d ago
Your post does show that iterators are somewhat of a leaky abstraction, but I'm not sure I would go as far as calling some of their infelicities "bugs". Whether those infelicities matter in practice is a moot point.
tapirl•3d ago
The bug is confirmed: https://github.com/golang/go/issues/71685
jub0bs•2d ago
Ok, that is annoying. I hope it gets fixed soon.
euroderf•2d ago
Great! How about iterators on trees ? Multiple options to provide.
pansa2•1d ago
> Most iterators provide the ability to walk an entire sequence [...] Calling the iterator again walks the sequence again.

> "Single-use iterators" break that convention, providing the ability to walk a sequence only once.

This seems similar to the difference between an "iterable" and an "iterator" in Python (and between `IEnumerable` and `IEnumerator` in C#).

A Python list `l = [1, 2, 3]` is an iterable, and you can do `for v in l: print(v)` multiple times. But `iter(l)` is an iterator and `for v in i: print(v)` will only work once.

catlifeonmars•1d ago
This is the same in JavaScript. There is “pure” Iterable protocol which produces an “impure” Iterator. Interestingly , for loops in JavaScript do not work directly with Iterators; to use in a for loop you must wrap an Iterator in an Iterable
codr7•1d ago
Java is the same if I remember correctly, always felt like a design failure to me.
masklinn•1d ago
It's especially dumb for Java, because Iterator could just have been a subtype of Iterable. That's basically what Python does, the iterator protocol requires also being an iterable[0]. And Rust just blanket implements IntoIterator for every Iterator without asking.

At least it's pretty easy to wrap an iterator in JS:

  {[Symbol.iterator]: () => it}
[0] which in the rare case you implement an iterator entirely by hand will be a trivial `return self`, so much so that `collection.abc.Iterator` just provides that)
masklinn•1d ago
It's more between repeatable iterables and one-shot iterables (of which iterators are a subset, as iterators are iterable). For instance a file is an iterable, but (unless it's seekable and you rewind it) it'll only let you iterate once.

Basically what Go calls an iterator most other language call an iterable. Because it uses internal iteration, Go doesn't hand out iterators (save through iter.Pull).

catlifeonmars•1d ago
- My initial thought is that the performance implication (e.g. escaping to the heap) of impure iterators is an implementation detail and seems like a good candidate for a future compiler optimization.

- impure iterators are strictly more powerful than pure iterators in that they can be resumed but do not have to be. If I wanted to pick one pattern for consistent behavior across all iterators it would be this one.

gregwebs•1d ago
Not all impure iterators can be resumed. But any pure iterator can be converted to a resumable iterator with a generic conversion function.
catlifeonmars•1d ago
> any pure iterator can be converted to a resumable iterator with a generic conversion function.

Makes sense

> Not all impure iterators can be resumed

How do you mean? In my head resuming an iterator is just partially unrolling a loop.

nine_k•1d ago
An impure iterator can panic, so you can't resume?
shubhjain•1d ago
Are the wordings "pure" vs "impure" suitable here, or should it have been "stateless" vs "stateful"?

Show HN: MBCompass – Android Compass App

https://github.com/MubarakNative/MBCompass
19•nativeforks•1h ago•2 comments

The Princeton INTERCAL Compiler's source code

https://esoteric.codes/blog/published-for-the-first-time-the-original-intercal72-compiler-code
41•surprisetalk•3h ago•6 comments

The Visual World of 'Samurai Jack'

https://animationobsessive.substack.com/p/the-visual-world-of-samurai-jack
228•ani_obsessive•7h ago•41 comments

Root shell on a credit card terminal

https://stefan-gloor.ch/yomani-hack
610•stgl•15h ago•177 comments

I made a chair

https://milofultz.com/2025-05-27-i-made-a-chair.html
71•surprisetalk•1d ago•24 comments

LibriVox

https://librivox.org/
119•bookofjoe•8h ago•32 comments

TPDE: A Fast Adaptable Compiler Back-End Framework

https://arxiv.org/abs/2505.22610
14•npalli•3h ago•3 comments

How Can AI Researchers Save Energy? By Going Backward

https://www.quantamagazine.org/how-can-ai-researchers-save-energy-by-going-backward-20250530/
17•pseudolus•2h ago•9 comments

LFSR CPU Running Forth

https://github.com/howerj/lfsr-vhdl
7•izabera•1h ago•0 comments

HeidiSQL Available Also for Linux

https://www.heidisql.com/forum.php?t=44068
54•Daril•3d ago•11 comments

Cinematography of “Andor”

https://www.pushing-pixels.org/2025/05/20/cinematography-of-andor-interview-with-christophe-nuyens.html
347•rcarmo•19h ago•331 comments

The Zach Attack Scratch 'N Solve Puzzle Pack

https://coincidence.games/zach-attack/
9•GauntletWizard•3d ago•0 comments

What works (and doesn't) selling formal methods

https://www.galois.com/articles/what-works-and-doesnt-selling-formal-methods
49•azhenley•3d ago•7 comments

Writing your own C++ standard library part 2

https://nibblestew.blogspot.com/2025/05/writing-your-own-c-standard-library.html
16•signa11•1d ago•6 comments

Nitrogen Triiodide (2016)

https://www.fourmilab.ch/documents/chemistry/NI3/
71•keepamovin•3d ago•38 comments

A new generation of Tailscale access controls

https://tailscale.com/blog/grants-ga
178•ingve•3d ago•48 comments

Estimating Logarithms

https://obrhubr.org/logarithm-estimation
74•surprisetalk•1d ago•18 comments

How Generative Engine Optimization (GEO) rewrites the rules of search

https://a16z.com/geo-over-seo/
44•eutropheon•2d ago•33 comments

Show HN: Moon Phase Algorithms for C, Lua, Awk, JavaScript, etc.

https://github.com/oliverkwebb/moonphase
14•oliverkwebb•5h ago•5 comments

Progressive JSON

https://overreacted.io/progressive-json/
478•kacesensitive•1d ago•198 comments

When Fine-Tuning Makes Sense: A Developer's Guide

https://getkiln.ai/blog/why_fine_tune_LLM_models_and_how_to_get_started
124•scosman•3d ago•48 comments

Atari Means Business with the Mega ST

https://www.goto10retro.com/p/atari-means-business-with-the-mega
141•rbanffy•18h ago•103 comments

How I like to install NixOS (declaratively)

https://michael.stapelberg.ch/posts/2025-06-01-nixos-installation-declarative/
125•secure•22h ago•119 comments

Google AI Edge – On-device cross-platform AI deployment

https://ai.google.dev/edge
189•nreece•22h ago•36 comments

RenderFormer: Neural rendering of triangle meshes with global illumination

https://microsoft.github.io/renderformer/
251•klavinski•1d ago•50 comments

Making maps with noise functions (2022)

https://www.redblobgames.com/maps/terrain-from-noise/
26•benbreen•4d ago•2 comments

The Rise of Judgement over Technical Skill

https://notsocommonthoughts.com/blog/ai-and-judgement/
14•kohlhofer•8h ago•0 comments

Show HN: Agno – A full-stack framework for building Multi-Agent Systems

https://github.com/agno-agi/agno
6•bediashpreet•3h ago•0 comments

M8.2 solar flare, Strong G4 geomagnetic storm watch

https://www.spaceweatherlive.com/en/news/view/581/20250531-m8-2-solar-flare-strong-g4-geomagnetic-storm-watch.html
176•sva_•12h ago•44 comments

Codex CLI is going native

https://github.com/openai/codex/discussions/1174
107•bundie•17h ago•96 comments