This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-11-06
Channels
- # admin-announcements (59)
- # announcements (1)
- # beginners (67)
- # boot (140)
- # cljsrn (8)
- # clojure (70)
- # clojure-berlin (18)
- # clojure-dev (7)
- # clojure-russia (53)
- # clojurescript (124)
- # clojurescript-ios (3)
- # clojurewerkz (2)
- # clojurex (10)
- # code-reviews (42)
- # cursive (9)
- # datomic (2)
- # editors-rus (2)
- # emacs (5)
- # events (1)
- # hoplon (35)
- # jobs (8)
- # ldnclj (7)
- # lein-figwheel (34)
- # luminus (1)
- # om (410)
- # onyx (22)
- # overtone (19)
- # portland-or (6)
- # re-frame (1)
- # yada (4)
I made a custom Clojure type! https://github.com/martinklepsch/custom-comparator-set
First time I’ve done this. It’s pretty little code easy to review I guess. Comments on style/indentation/thinking/everything most welcome
@martinklepsch: do you need to define .equals and .hashcode?
@xeqi: it probably would make sense
I’m just doing that for the cljs side of things
also, tried to build locally to test and got "Could not find artifact adzerk:boot-test:jar:1.0.5-SNAPSHOT"
Yeah, that’s a local mod for cljc testing. PR outstanding in the boot-test repo.
Sorry about that
Thanks for the test case idea, was actually wondering how I can test this
how’s your clojure/java post coming along btw
@xeqi: is this what you had in mind kind of?
(deftest hashing
(let [cset (ccset/custom-comparator-set :k {:k "a"})
kmap (-> {} (assoc cset 1) (assoc cset 2))]
(t/is (= 2 (get kmap cset)))
(t/is (= 1 (count kmap)))))
ignore this
(deftest hashing
(let [cset1 (ccset/custom-comparator-set :k {:k "a"})
cset2 (ccset/custom-comparator-set :k {:k "a"})
kmap (-> {} (assoc cset1 1) (assoc cset2 2))]
(t/is (= 2 (get kmap cset1)))
(t/is (= 2 (get kmap cset2)))
(t/is (= 1 (count kmap)))))
this is better@ghadi: thanks, do you mean like this?
(defmethod print-method CustomComparatorSet [v ^java.io.Writer w]
(.write w "#CustomComparatorSet{")
(doseq [x (seq v)]
(print-method x w)
(.write w " "))
(.write w "}"))
would I use interpose
to add spaces between items?
@ghadi: if I want to elide the trailing space before the closing }
I’d use loop and check for rest?
@martinklepsch yeah, something like that to see if you needed to override those methods. Did the test fail without custom .hashcode/.equals?
@xeqi: yes they’re failing
@xeqi: is there some place where I can lookup protocols/interfaces for clojure types?
like how do I figure out what Interface I have to implement for .hashcode and .equals?
@martinklepsch https://github.com/ztellman/collection-check is where I would start
@xeqi: where you would start with testing?
@martinklepsch I meant for finding protocols/interfaces for Clojure types. For finding out what classes/interfaces those methods belog to higher up, I don't know a good place
ok. thanks!
in the process of adding collection-check to the tests
Though if I was testing your set, i'd highly consider throwing collection-check at (comparable-set identity)
compared to #{}
that’s exactly what I’m doing
@xeqi: do you think comparable-set
is a better name (just asking because you used it)
Though that might not be quite right, cause is (= (c-s identity) (c-s #(%1))
? How does the comparable effect equality? Etc etc
I hadn't though about it, just typed that cause I'm on mobile atm and didn't want to go back to the code to find real name
@martinklepsch back to actual review, could you delegate .contains
to (contains? data (comparator v))
? I think that would avoid building a set and walking every element each time.
@xeqi: good suggestion thanks!