Stream: announcements

Topic: Breaking change: removing Iter.rev and Iter.take_last


view this post on Zulip Richard Feldman (Aug 08 2026 at 01:45):

we currently have an assumption that iterators are reversible, but I think that was a mistake in hindsight. Some custom iterators simply aren't (e.g. an infinite range), or have terrible performance if you reverse them (e.g. a linked list), and I think it's better to just expose things like List.iter_rev from only the data structures that can reasonably offer reversed iterators, instead of having the reversal operation in Iter itself.

view this post on Zulip Richard Feldman (Aug 08 2026 at 01:46):

(I haven't landed his change yet, but I'll be opening a PR for it soon.)

view this post on Zulip Aurélien Geron (Aug 13 2026 at 02:15):

This did indeed break a few exercises, I'm fixing them now.

One use-case was: (1..=10).rev() which no longer works.
It would be nice to have a simple way to express this. For now, I've replaced this with List.from_iter(1..=10).iter_rev(). It works, but it materializes a List when we don't really need one.

view this post on Zulip Aurélien Geron (Aug 13 2026 at 02:31):

A few random ideas:

However, none of these fix the fact that these ranges should be reversible.

Also, (1..=10).size_hint() could return Known(10) (currently it returns Unknown).

view this post on Zulip Richard Feldman (Aug 13 2026 at 02:40):

Aurélien Geron said:

perhaps 1..=10 could produce a Range type. You would have to add iter() or rev_iter() to actually get an Iter, example: (1..=10).iter() to get 1 to 10. Might be a good compromise actually. It would also allow things like (1..=10).step(2).iter_rev() to get 10, 8, 6, 4, 2.

Also, (1..=10).size_hint() could return Known(10) (currently it returns Unknown).

yeah, that all seems reasonable! We could put it under Num.Range so it doesn't need a separate top-level thing

view this post on Zulip Richard Feldman (Aug 13 2026 at 02:40):

and since for works on anything that has an iter method, Range would continue to Just Work inside for loops

view this post on Zulip Aurélien Geron (Aug 13 2026 at 02:47):

Oh right, I had forgotten about that last point, cool. :+1:

view this post on Zulip Luke Boswell (Aug 13 2026 at 02:56):

@Aurélien Geron want to make a GH Issue for this?

view this post on Zulip Aurélien Geron (Aug 13 2026 at 03:09):

Sure, I'm on it

view this post on Zulip Aurélien Geron (Aug 13 2026 at 03:32):

https://github.com/roc-lang/roc/issues/10753

view this post on Zulip Aurélien Geron (Aug 13 2026 at 04:42):

Note: this change broke roc-random, so this PR fixes it.

view this post on Zulip Luke Boswell (Aug 13 2026 at 05:07):

I'll wait for tomorrow's nightly and then bump that and kickoff CI and a release

view this post on Zulip Aurélien Geron (Aug 13 2026 at 05:08):

This roc-random? https://github.com/kili-ilo/roc-random

view this post on Zulip Luke Boswell (Aug 13 2026 at 05:09):

yes, the latest nightly doesn't have the Iter thing does it?

view this post on Zulip Aurélien Geron (Aug 13 2026 at 05:09):

Ah yes, indeed

view this post on Zulip Luke Boswell (Aug 13 2026 at 05:09):

I had another PR staged to update the nightly, but then I realised it didn't have the fix in it

view this post on Zulip Aurélien Geron (Aug 13 2026 at 05:10):

Btw, something seems to be broken with types, see this new issue.

view this post on Zulip Aurélien Geron (Aug 13 2026 at 05:12):

I also ran into a type issue while fixing roc-random: I had to add a type spec for component_generator on line 278 in package/Random.roc`, or else it ran into a type issue.

view this post on Zulip Luke Boswell (Aug 13 2026 at 05:12):

this will be a good regression test to add when we fix that

view this post on Zulip Luke Boswell (Aug 13 2026 at 05:13):

Aurélien Geron said:

I also ran into a type issue while fixing roc-random: I had to add a type spec for component_generator on line 278 in package/Random.roc`, or else it ran into a type issue.

Do you think you could make a minimal repro? I guess it's probably ok to make an issue with the git commits from roc-random, but would be nice if we had something small we could convert into a regression test

view this post on Zulip Aurélien Geron (Aug 13 2026 at 05:14):

I'll give it a shot.


Last updated: Sep 03 2026 at 15:16 UTC