Beyond Enumerable: Heaps and Priority Queues | baweaver
12-Jun-2026 9
Our last post named windows: moving through a collection while maintaining running state. This one goes after a different shape, one that shows up the moment a collection won’t sit still long enough for sort_by to help.
Enumerable gives you min_by, max_by, sort_by, and they’re enough when the collection is static. You ask once, they walk everything, and you get your answer, but they keep nothing between calls. Ask again after an insert or a delete and they redo all that work from scratch. On a collection that changes on every read, you’re re-scanning every time, and if you never had an algorithms class that told you there’s a name for the structure that fixes this, you end up rebuilding it by hand without knowing what you’re building. I did that for years. These articles exist so the path is shorter for other people.
Beyond Enumerable: Heaps and Priority Queues | baweaver #ruby #rubydeveloper #rubyonrails #Beyond #Enumerable: #Heaps #Priority #Queues #baweaver https://www.rubyonrails.ba/link/beyond-enumerable-heaps-and-priority-queues-baweaver