Stream: contributing

Topic: ✔ List.get_wrap / drop_at_unordered / concat_utf8 (#9596)


view this post on Zulip Eric Rogstad (Jul 23 2026 at 15:35):

Dzmitry Misiuk said:

Shouldn't the idea that a Str is backed by a List(U8) be tied to the Str type, and not baked into List?

Sorry if this has already been discussed or if I'm missing something because I'm new to Roc, but it just seems weird to me to attach any Utf8 or Str methods to List itself.

view this post on Zulip Dzmitry Misiuk (Jul 23 2026 at 16:00):

Fair question, and no need to apologize. Worth nailing down: List.concat(bytes, Str.to_utf8(str)) already does this in pure Roc, so a dedicated concat_utf8 would only add the perf of the (currently orphaned) host listConcatUtf8 — and your point about List vs Str is fair if we keep it at all. It's on #9596, so I'll leave that call to you all: wire it onto List for the perf, move it to Str, or drop it since concat + to_utf8 already covers it. get_wrap and drop_at_unordered are plain List ops with none of this, so I'll pick those up.

view this post on Zulip Richard Feldman (Jul 23 2026 at 16:17):

yeah let's leave that one out for now

view this post on Zulip Romain Lepert (Jul 23 2026 at 16:48):

While you are on List I wonder if we could have List.clear which does the same as Dict.clear aka "Remove every entry while preserving the current capacity."
https://www.roc-lang.org/docs/main/Dict/#clear

Currently i use List.sublist() but it probably is abusing the implementation.

view this post on Zulip Richard Feldman (Jul 23 2026 at 16:49):

maybe .emptied() might be a better name (for both, including Dict)

view this post on Zulip Romain Lepert (Jul 23 2026 at 17:07):

the past principled "emptied" is not common practice in the builtin
https://www.roc-lang.org/docs/main/

If find "clear" quite straightforward with the specificity that it "preserves the current capacity" as the docstring says. So unless there will be a clear method that does NOT preserve capacity then clear can mean that.

view this post on Zulip Richard Feldman (Jul 23 2026 at 17:16):

what do other languages use for this?

view this post on Zulip Dzmitry Misiuk (Jul 23 2026 at 17:17):

Opened as #10341get_wrap + drop_at_unordered, with concat_utf8 left out as discussed.

view this post on Zulip Dzmitry Misiuk (Jul 23 2026 at 17:25):

Almost everywhere it's clear:

Swift's the outlier: removeAll(keepingCapacity:). Couldn't find any language using emptied.

view this post on Zulip Richard Feldman (Jul 23 2026 at 18:43):

ok clear seems consistent then :+1:

view this post on Zulip Dzmitry Misiuk (Jul 23 2026 at 20:09):

List.clear is up as #10342 — thanks for the nudge, @Romain Lepert. Mirrors Dict.clear (pure Roc, just List.take_first(list, 0)), so it has the same capacity-preserving behavior.

view this post on Zulip Notification Bot (Jul 24 2026 at 08:11):

Dzmitry Misiuk has marked this topic as resolved.

view this post on Zulip Romain Lepert (Jul 24 2026 at 08:29):

thank you @Dzmitry Misiuk <3


Last updated: Aug 12 2026 at 12:35 UTC