[PROPOSAL] Iterator Improvements (Step, Reverse, Float)

Open
#104 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
20/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
ruby
Domain
compilers

Research direction

The issue names no files, tests, or entry points. Start by reviewing existing iterator behavior and the compiler's “Cannot iterate backwards” diagnostic; the proposal still needs settled semantics for reverse, step, and float iteration before implementation can begin.

Written by the indexing model from the issue text.

Description

I'd like to see more functionality for iterators, inspired by Ruby.

// Standard IntIterator
for (i in (0...10))
  trace(i); // 1, 2, 3, 4, 5...

// PROPOSALS

// Reverse Iterator
for (i in (10...0))
  trace(i); // 10, 9, 8, 7, 6

// Step Iterator
for (i in (0...10).step(2))
  trace(i); // 0, 2, 4, 6, 8

// FloatIterator with Step
// Compiler type-checks min and max to determine if it is an Int or a Float before choosing an iterator.
for (i in (5.0...7.5).step(0.1))
  trace(i); // 5.0, 5.1, 5.2, 5.3, 5.4, ...

I was actually able to implement step(value:Int):IntIterator locally without modifying compilation, but reverse and FloatIterator would require compiler changes (I got a "Cannot iterate backwards" error)

This is pre-draft, but if nobody has any obvious problems with it I will write up a more formal proposal

Dominant language
No language data
Stars
120
Forks
56
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from HaxeFoundation/haxe-evolution

All issues in HaxeFoundation/haxe-evolution

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.