Fork me on GitHub
#beginners
<
2018-01-02
>
magra16:01:38

Hi, and happy new year! I have a very unfunctional problem: How do I destroy a var from the namespace? Instead of (doc butlast) my fingers typed (def butlast) at the repl. So user/butlast now shadows clojure.core/butlast. How do I destroy user/butlast?

Prakash16:01:16

there is ns-unmap

pablore18:01:34

What is a efficient insertion into a sorted collection? ie:

(insert-sort 5 [1 2 3 6 7 8]) => [1 2 3 4 5 6 7 8]
My naive approach is to insert at the end (with conj) and sort again but this isnt very efficient at all in a best-case-scenario

donaldball18:01:03

The idiomatic clojure type for a sorted collection is probably a sorted-set.

tbaldridge18:01:18

assuming he wants a set

tbaldridge18:01:27

(no duplicate items)

pablore18:01:16

yes! that works for me

pablore19:01:51

now, midje doesnt seem to be able to compare sets

pablore19:01:14

Expected:
#{{:simulator2.core.entity.event/created-at 1}
  {:simulator2.core.entity.event/created-at 4}}
Actual:
#{{:simulator2.core.entity.event/created-at 1}
  {:simulator2.core.entity.event/created-at 4}}

noisesmith19:01:53

that’s super weird

noisesmith19:01:16

is it because one of those is a set, and one a sorted-set?

noisesmith19:01:58

no that wouldn’t be it

=> (= (hash-set 1 2 3) (sorted-set 1 2 3))
true

pablore19:01:41

but comparing with set of maps raises an exception

pablore19:01:11

(= (hash-set {:id 1} {:id 2} {:id 3})
   (sorted-set {:id 1} {:id 2} {:id 3}))
=> clojure.lang.PersistentArrayMap cannot be cast to java.lang.Comparable

Prakash19:01:38

I think its because u cant sort maps

pablore19:01:58

can you put them in a priority queue?

pablore19:01:09

with a comparing fn?

Prakash19:01:33

there is a sorted-set-by

pablore19:01:48

yes, but it doesnt let me compare

pablore19:01:05

I need it to be easy to test

Prakash19:01:57

I am not sure what u mean by does not let me compare

Prakash19:01:25

very badly written example for map - (sorted-set-by (fn [m1 m2] (> (val (first m1)) (val (first m2)))) {:id 1} {:id 2} {:id 3})

Prakash19:01:18

if u can create a function that returns a boolean based on your logic of comparing 2 maps, it should work

pablore19:01:46

okay, was able to compare by transforming the set into a vector with (into [])

pablore19:01:03

therefore a sorted-set is good and enough