I'm trying to do what it says on the tin. Str
don't seem to implement the Eq
ability, so its not that simple. I've gotten this so far:
compareStr : Str, Str -> [LT, EQ, GT]
compareStr = \a, b ->
compareLetters (Str.toUtf8 a) (Str.toUtf8 b)
compareLetters : List u8, List u8 -> [LT, EQ, GT]
compareLetters = \x, y ->
when (x, y) is
([], []) -> EQ
([], [_]) -> LT
([_], []) -> GT
(a, b) ->
if (List.first a) == List.frist b then
...
else
...
My plan is to pass this into the List.sortWith
function, but I'm finding it cumbersome to implement. My first thought was to write a recursive function that compares one letter at a time, but that doesn't seems easily possible.
Is there a pattern match that is something along the lines of [head, ..rest] -> ...
Otherwise, the List.first
function, but this (understandably) returns Result a [ListWasEmpty]
. Is there a way, similar to .unwrap()
in Rust, that I can easily throw away the error, since I know what branch of the pattern match I'm on?
For pattern match the syntax is [head, .. as rest] -> ...
Richard added a detailed guide recently to https://www.roc-lang.org/builtins/Str which explains the logic behind not having Eq
ability for Str
Refer to the section String equality and normalization
Is this something the eventual unicode package plans to support?
I would guess so, but we need to implement the Unicode Normalization Algorithm I think
Luke Boswell said:
Refer to the section
String equality and normalization
we should totally make these headers automatically self-linkifying like in the tutorial! :smiley:
I was thinking the same thing... should be another good first issue for Doc gen
Or maybe it can already be done
It's not implemented like the static-site-gen platform.
So we need to update docs gen crate to support e.g.
## ## [Syntax](#syntax) {#syntax}
should generate
<h2 id="syntax"><a href="#syntax">Syntax</a></h2>
Sound ok?
I created an issue for this https://github.com/roc-lang/roc/issues/6420
Last updated: Jul 06 2025 at 12:14 UTC