This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-07-22
Channels
- # admin-announcements (1)
- # aws-lambda (1)
- # beginners (38)
- # boot (48)
- # cider (11)
- # clara (4)
- # cljs-dev (61)
- # cljsrn (9)
- # clojure (68)
- # clojure-austin (3)
- # clojure-greece (9)
- # clojure-mexico (6)
- # clojure-russia (40)
- # clojure-spec (165)
- # clojure-uk (134)
- # clojurescript (37)
- # cursive (5)
- # datomic (25)
- # defnpodcast (2)
- # hoplon (1)
- # jobs (1)
- # juxt (1)
- # lein-figwheel (3)
- # leiningen (4)
- # mount (14)
- # off-topic (8)
- # om (29)
- # onyx (9)
- # protorepl (4)
- # quil (1)
- # re-frame (56)
- # reagent (3)
- # rethinkdb (1)
- # spacemacs (4)
- # specter (12)
- # test-check (2)
- # testing (1)
- # vim (12)
- # yada (4)
oh well, for the size of my trees (less than 100 nodes) it looks like a linear search will be fast enough:
(def data
[
{:span [21 22] :id 13}
{:span [10 20] :id 12}
{:span [17 19] :id 11}
{:span [16 17] :id 10}
{:span [15 17] :id 9}
{:span [13 14] :id 8}
{:span [11 12] :id 7}
{:span [8 11] :id 6}
{:span [7 9] :id 5}
{:span [6 9] :id 4}
{:span [6 8] :id 3}
{:span [3 5] :id 2}
{:span [0 2] :id 1}])
(defn find-intervals [data, n]
(filter
(fn [{span :span}]
(and
(>= n (first span))
(< n (second span))))
data))
(time
(dotimes [n 20000000]
find-intervals data (mod n 22)))
"Elapsed time: 480.723187 msecs"
or (reduce conj [0 1 2 3] [4 5 6 7])
into
is really great. I should remember to use it more.
tastes even better with transducers
(into [] cat [[0 1 2 3] [4 5 6 7]]) ;;=> [0 1 2 3 4 5 6 7]
And the transducer solution works with arbitrarily many vectors, though it doesn't use transients. Nice!
it does use transients
it does? that's awesome
it will collect into the vector at the front (made transient)
it’s way more efficient than the vec concat version above
it uses transients because into
uses transients?
nice, thanks
plus you get to have your cat
around
so it’s internet friendly
what does “bouncing the repl” mean?
@drewverlee: shutting it down and starting it back up, I believe.
@d-side: thanks that makes sense in the context i was reading.
can one use transients with a sorted-map? I get errors but nowhere in the documentation does it say that transients can't be used with a sorted-map
(def tmap (transient sorted-map))
CompilerException java.lang.ClassCastException: clojure.core$sorted_map cannot be cast to clojure.lang.IEditableCollection, compiling:(form-init206135609334303987.clj:1:11)
It looks like the core sorted maps don't implement the right protocol, but there's https://github.com/clojure/data.avl which demonstrates using them with transient.
Hi. Have a cljs question regarding foreign-libs. I have this in my dev cljs build:
:foreign-libs [{:file "resources/browserified/foo.js"
:provides ["js.foo"]}
And in my cljs file I have (:require [js.foo])
. This works, I get access to the stuff in foo.js from the browser console.Problem is, when I try to load that same cljs file in the figwheel REPL I get java.lang.IllegalArgumentException: Namespace js.foo does not exist
@polymeris: Best channel to ask is #C0B22RS2Y, it's pretty active.
Ok. I'll try that. Thanks, @shaun-mahood & @dg