Dzmitry Misiuk said:
List.concat_utf8—List(U8), Str -> List(U8); tack a string's UTF-8 bytes onto a byte list.
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.
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.
yeah let's leave that one out for now
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.
maybe .emptied() might be a better name (for both, including Dict)
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.
what do other languages use for this?
Opened as #10341 — get_wrap + drop_at_unordered, with concat_utf8 left out as discussed.
Almost everywhere it's clear:
Vec::clear() — "no effect on the allocated capacity"List<T>.Clear() — "Capacity remains unchanged"vector::clear()ArrayList.clear()list.clear()Map.clear() / Set.clear()clear() builtinclearRetainingCapacity() — the language we're in; ~500 uses in this codebaseSwift's the outlier: removeAll(keepingCapacity:). Couldn't find any language using emptied.
ok clear seems consistent then :+1:
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.
Dzmitry Misiuk has marked this topic as resolved.
thank you @Dzmitry Misiuk <3
Last updated: Aug 12 2026 at 12:35 UTC