Assuming I have a list of tuples that resemble the following example:
[(5, "a"), (1, "c"), (7, "d")]
in Elm, how do I start sorting the list in ascending order by their first elements so that we get the following result?
[(1, "c"), (5, "a"), (7, "d")]
Using the Documentation Elm a List , it seems like sortByand sortWithfunctions will be helpful in this case. My implementation attempt is as follows:
maxTuples : Tuple(a, b) -> Tuple(a, b) -> Tuple(a, b)
maxTuples t1 t2 =
case compare t1 t2 of
((Tuple.first t1) >= (Tuple.first t2)) -> GT
_ -> LT
sortByFirst : List (Tuple (a, b)) -> List (Tuple (a, b))
sortByFirst lst =
List.sortWith maxTuples lst
However, I get compiler errors of the following nature:
I ran into something unexpected when parsing your code!
99| ((Tuple.first t1) >= (Tuple.first t2)) -> GT
^
I am looking for one of the following things:
an upper case name
My hunch is that the compiler is looking for GT/ LT/ EQfor the library API List, but if this is the case, I'm not sure how we can use either sortByor sortWithto sort the list of tuples into a knit by the first index of each element.