I'm trying to sort a list of something that boils down to strings, and running into some issues. First, I see that there's nothing like List.sortByKey .name
(to access the name field and sort by that as a key) - and nor do things like List seem to be comparable. When I try to encode everything in strings and write my own comparison function to use with List.sortWith
, like so:
set
|> Set.toList
|> List.sortWith \{modu: ma, name: na}, {modu: mb, name: nb} ->
a = Str.concat (Str.joinWith (List.map ma \m -> Str.concat m "::") "") na
b = Str.concat (Str.joinWith (List.map mb \m -> Str.concat m "::") "") nb
if a == b then
EQ
else
if a < b then
LT
else
GT
I just get:
── TYPE MISMATCH ───────────────────────── crates/compiler/parse/generator.roc ─
This 1st argument to isLt has an unexpected type:
48│ else if a < b then
^
This a value is a:
Str
But isLt needs its 1st argument to be:
Num a
... which is very surprising. Is string comparison not implemented in Roc yet?
yeah we have Hash
and beEq
but not Ord
yet
implementing it should be very similar to Hash
I think!
Last updated: Jul 05 2025 at 12:14 UTC