This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-28
Channels
- # beginners (35)
- # boot (5)
- # cider (16)
- # cljs-dev (22)
- # cljsrn (11)
- # clojars (1)
- # clojure (205)
- # clojure-uk (19)
- # clojurescript (76)
- # cursive (22)
- # duct (4)
- # editors (1)
- # emacs (4)
- # fulcro (1)
- # hoplon (3)
- # leiningen (5)
- # off-topic (25)
- # onyx (29)
- # other-languages (5)
- # parinfer (1)
- # re-frame (13)
- # reagent (8)
- # reitit (2)
- # shadow-cljs (3)
- # tools-deps (11)
- # vim (6)
@ackerleytng the same way you’d use spec to validate regular data; you’d read the edn config and then use s/valid or others means to check it against a spec
@dadair thanks! I found :req-un
really useful!
hey guys
I read two books ( brave of clojure - https://www.braveclojure.com/quests/reducers/know-your-reducers/#Eliminating_Intermediate_Collections) and Clojure High Performance ( https://www.amazon.com/Clojure-High-Performance-Programming-Second/dp/1785283642 ) .
I’m intrigued because both books talks about lazy-seq
brave of clojure
says that code below is super stupid because we are going to create intermediate collections and clojure high performance
says exactly the opposite (lazy seq does not produce intermediate collections and we are running the code in O(n) )
(->> (list "Shake" "Bake") ;
(map #(str % " it off")) ; 1
(map clojure.string/lower-case) ; 2
(into []))
my question is> Does the follow code will produce intermediate collections or not ?
my understanding is that will not create any intermediate collections , both lazy-seq ( 1 and 2 ) will memoize which will increase the memory footprint.
is that correct ? which book is correct ?1 and 2 will both create intermediate sequences
@alexmiller 1 will return a lazy-seq to 2, right ? ((map clojure.string/lower-case) lazy-seq-1)
seqs are collections
every map returns lazy-seq in order to run the code in 0(n) you have to use transducers
Yes, lazy seq memoizes computed values
yeah I see, so both 1 and 2 are memoizing the values which is considered intermediate collections
However I would still say the seq version is O(n)
Because this realization is pipelined
into is implemented with reduce, which walk the lazy seq asking for the next value, which asks the top lazy seq which asks the next lazy seq which asks the list
aaaaa now I understand
In this case, map is also chunking into 32 element batches to amortize the cost
The transducer version would create one composite reduce function, walk the list, and drop the results into the output vector
Still o(n), but no intermediate caching seqs
So less object creation and gc
Are there any guides on setting up a in-memory database for testing? Creating the database in a fixture, adding some records for one group of tests and so on?