HaxeFoundation / HaxeFoundation/haxe-evolution

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

Open
#104 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
119
Forks
56
PR merge metrics
No merged PRs in 30d

Description

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

```haxe
// 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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.