enlightware / enlightware/ferlium

Iteration by projection

Open
#177 0 comments 0 reactions 1 assignee Claimed by @stephanemagnenat View on GitHub
hir mir optimisation type
Dominant language
Rust
Stars
14
Forks
2
PR merge metrics
No merged PRs in 30d

Description

Currently due to MVS iterators copy with `next`. This is clearly suboptimal.

An improvement could be to add a multiple yield iterator to `Seq`:

```
pub trait Seq Item, Iter ! IterEffect> where Iter: Iterator<...> {
fn iter(seq: Self) -> Iter;
subscript many elements(seq: Self) -> Item ! IterEffect { ref }; // new
}
```

This requires a `YieldMultiple` return convention.

This allows nice iteration by reference for arrays:
```
impl Seq for Item = A, Iter = ArrayIterator> where A: Value {
fn iter(a: [A]) -> ArrayIterator
{ ArrayIterator { array: a, index: 0 } }

subscript many elements(c: [A]) -> A {
ref {
let mut i = 0;
let n = array_len(c);
loop { if i >= n { break }; yield c[i]; i += 1 }
}
}
}
```

I am working on a detailed design document.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.