Fork me on GitHub
#beginners
<
2017-01-19
>
fabrao03:01:43

hello all, is there any way to keep teh original data type ?

(sort-by first {:a "1" :z "2" :g "3"}) =>   ([:a "1"] [:g "3"] [:z "2"])

fabrao03:01:32

I want the result would be

{:a "1" :g "3" :z "2"}
?

seancorfield03:01:28

A hash map is inherently unsorted.

seancorfield03:01:34

A sequence has an ordering.

brthrjon03:01:20

(into {} '([:a "1"] [:g "3"] [:z "2"]))

seancorfield03:01:42

No, that won't work.

seancorfield03:01:49

A hash map is not ordered.

brthrjon03:01:24

i didn't read the sort part.

brthrjon03:01:02

maybe sorted-map?

seancorfield03:01:29

Yeah, if you want a hash map ordered by its keys, just use sorted-map @fabrao

seancorfield03:01:15

(sorted-map :a "1" :z "2" :g "3")

seancorfield04:01:26

You can convert an unordered map to a sorted map: (into (sorted-map) {:a "1" :z "2" :g "3"})

fabrao04:01:21

@seancorfield It worked, thanks a lot

Jon09:01:10

boot-cljs compiled my code of el.setAttribute into a.b thing and it threw errors. How to use extern files to fix it please?

rauh09:01:27

@jiyinyiyong Shouldn't happen. Can you add @param {Element} element to the fn parameter and see if that fixes it?

Jon09:01:08

I should be more specific, it was el.setAttr, non standard.

Jon09:01:38

Is there any working example I can refer to? Not managed to define an extern file before..

Jon09:01:00

(.call (aget el "setAttr") el p1 p2), working now in ugly syntax

abhir00p21:01:58

is there any way to provide default case for cond->

abhir00p21:01:04

in case none of the expressions match

dpsutton21:01:40

it looks like no, but because of the semantics of cond->

dpsutton21:01:00

from the docstring, it doesn't "short-circuit", so it does this for all matching branches, not just the first

dpsutton21:01:32

so if you added a default clause, it would match every time

dpsutton21:01:37

according to the way it currently works

abhir00p21:01:11

yeah maybe cond-> is a bad choice

dpsutton21:01:18

and easily extend it to do what you want

abhir00p21:01:35

basically i am trying to build an sql query in honeysql

abhir00p21:01:50

and adding clauses to and

abhir00p21:01:57

using cond->

dpsutton21:01:03

(let [g (gensym)
        steps (map (fn [[test step]] `(if ~test (-> ~g ~step) ~g))
                   (partition 2 clauses))]
if you changed to
(let [g (gensym)
          executed# (atom false)
          steps (map (fn [[test step]] `(if ~test (do (reset! executed true) (-> ~g ...))))

abhir00p21:01:05

oh jut found out cond-> returns the original argument if no clauses match

abhir00p21:01:11

thats what I wanted

abhir00p21:01:29

basically to return the original query if none of the clauses match