Hi Kovas,

When I run your code in a Clojure repl (as opposed to CLJS), I get an
exception:

clojure.lang.ArityException: Wrong number of args (2) passed to:
app.core-test/sort-map/fn--24334

And this is because you're the comparator that you pass to sorted-map-by is
a 1-arity function: #(if (= % :input) "aaaaa" (name %)))

The comparator will be called with two map entries as arguments so that the
comparator can decide which one of them should be first, so your comparator
function should do something with %1 and %2. But I can't really tell from
the code what you're trying to do, so I'm not sure what the comparator
should look like.

Cheers,
Lauri

On Tue, 18 Jan 2022 at 14:15, Kovas Palunas <[email protected]> wrote:

> Hey all,
>
> I think I've found a bug in `sorted-map-by`, as shown by the below code:
>
> ```
> (ns app.core-test
>   (:require
>    [cljs.test :refer (deftest is)]
>    [clojure.string :as st]))
>
> (prn *clojurescript-version*)  ;; "1.10.914"
>
> (defn single-row [result-row]
>   {:input (:input result-row)
>    (keyword (st/join [(name (:biomarker result-row)) "-datapoints"]))
> (:datapoints result-row)})
>
> (defn sort-map [m]
>   ; Sort row so that :input is first, then put this rest in alphabetical
> order
>   (into (sorted-map-by #(if (= % :input) "aaaaa" (name %))) m))
>
> (defn get-per-input-row [same-input-results]
>   ; Calling sort-map twice here resolves the problem.
>   (sort-map (reduce merge (map single-row same-input-results))))
>
> (defn make-per-input-results
>   [results]
>   (let [rows-by-input (group-by :input results)]
>     (map get-per-input-row (vals rows-by-input))))
>
> (deftest test-bad-map-sorting
>   (is (= '({:input 1 :a-datapoints 5}
>            {:input 2 :a-datapoints 5}
>            {:input 3 :b-datapoints 5}
>            {:input 4 :b-datapoints 5})
>          (make-per-input-results
>           [{:input 1 :biomarker :a :datapoints 5}
>            {:input 2 :biomarker :a :datapoints 5}
>            {:input 3 :biomarker :b :datapoints 5}
>            {:input 4 :biomarker :b :datapoints 5}]))))
> ```
>
> The testcase fails, when I would expect it to succeed.  I tried posting
> this on the cljs JIRA as a bug, but I don't have permission, so I thought
> I'd post it here instead.  Anyone want to try reproducing this and posting
> on the JIRA if you can reproduce it?
>
>  - Kovas
>
> --
> Note that posts from new members are moderated - please be patient with
> your first post.
> ---
> You received this message because you are subscribed to the Google Groups
> "ClojureScript" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/clojurescript/7eedfcb0-acff-496c-b332-11589f7e9582n%40googlegroups.com
> <https://groups.google.com/d/msgid/clojurescript/7eedfcb0-acff-496c-b332-11589f7e9582n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojurescript/CABgZr0s7iwQe8r%3DWXSDpx42bh7B_T8CURo61U7gonokrw9OJQw%40mail.gmail.com.

Reply via email to