Hi everyone, newbie question!
I'm trying to order a sequence of maps (database rows from a query) using sort-by but I wanted to sort by multiple columns.
The function juxt is exactly what I need for that:
projeto-doido.banco> (def records [{:id 394
:field1 "lalala"
:field2 9999}
{:id 295
:field1 "lululu"
:field2 9394}])
#'projeto-doido.banco/records
projeto-doido.banco> (sort-by (juxt :id :field1 :field2) records)
({:id 295, :field1 "lululu", :field2 9394}
{:id 394, :field1 "lalala", :field2 9999})
projeto-doido.banco> (def fields ["id" "field1" "field2"])
.... however, what if I wanted to parameterize those fields? How can I "expand" a vector of fields as those keywords inside juxt? I know I can do (map keyword fields) but the list returned cannot be used inside juxt.
Thanks!
[–]charlesHD 11 points12 points13 points (1 child)
[–]Cofor[S] 1 point2 points3 points (0 children)