argotorg / argotorg/fe

Add a way to iterate arrays with index

Open
#529 0 comments 0 reactions 0 assignees View on GitHub
prio: P3 important type: feature type: RFC / discussion / question type: syntax
Dominant language
Rust
Stars
1.7k
Forks
218
Avg merge
1d 4h
Merged PRs (30d)
8

Description

### What is wrong?

Currently, the only way to iterate arrays with a for loop goes like this:

```
for val in my_array:
pass # do something with value
```

It's common that one also needs to obtain the index of the value which currently can only be obtained manually e.g.

```
let index: u256 = 0
for val in my_array:
pass # do something with value
index += 1
```

It would be handy to have something like `enumerate()` to get both index and value at the same time e.g.

```
for (index, val) in my_array.enumerate():
pass # do something with index and value
```

### How can it be fixed

Discuss & :robot:

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the array for-loop implementation and the entry points for array methods in the compiler. Clarify the proposed enumerate() syntax and index/value semantics, then define completion around supporting the issue's example and adding coverage for indexed iteration.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.