Fork me on GitHub
#beginners
<
2017-02-08
>
ghadi02:02:09

@upgradingdave you're on the right track: the File objects will not have normal Clojure equality semantics (value equality). You can look for dups though if you can grab something unique about them, like their name property:

(into #{} (map (fn [file] (.-name file)))  list-of-files)

fothaggenda02:02:56

hello! what would be the idiomatic way to generate a vector of vectors (fixed size)? my solution uses recursion but i think there is a simpler way to achieve than this:

fothaggenda02:02:58

(defn generate-vector-of-vectors
  ([n] (generate-vector-of-vectors n []))
  ([n vector-of-vectors]
   (if (zero? n)
    vector-of-vectors
    (generate-vector-of-vectors (dec n) (conj vector-of-vectors (vec (repeatedly 10 #(rand-int 11))))))))

seancorfield02:02:18

You just want a vector of empty vectors?

seancorfield02:02:33

(into [] (repeat n [])) perhaps?

fothaggenda03:02:26

no, a vector of vectors containing random integers

fothaggenda03:02:56

hmmm... (vec (repeat n (repeatedly 10 #(rand-int 11)))) is almost there 😛

tap03:02:51

yeah, then you just want (mapv vec ..)

roelof06:02:33

someone who can help me mock-up this part

"home.html" {:data {:paintings (-> (client/get url options)  
so I can test this function :
(defn fetch-paintings-and-images-front-page

  [ids]

  (let [paintings (pmap (comp get-data-front-page get-art-object read-json-data) ids)

        images (pmap (comp get-image-url read-image-data) ids)]

  (mapv merge paintings images))) 
which is in another namespace

roelof06:02:21

before I forget I work with spec tests

roelof06:02:50

and is this good :

:args (s/cat :args (s/coll-of ::objectNumber)) 
the args schould be a collection of objectnumbers where objectnumbers is a string.

janvanryswyck07:02:27

Is throwing an exception (e.g. version check of a db record for optimistic concurrency) an idiomatic use in Clojure? I've read about failjure (https://adambard.com/blog/introducing-failjure/) and ex-info (https://clojuredocs.org/clojure.core/ex-info). My current feeling is that failjure is appropriate for not so exceptional cases, while throwing an exception might be reasonable in truly exceptional cases (like optimistic concurrency?). I would love to read some opinions on this.

roelof07:02:08

I try to solve this failing spec :

:data #:clojure.spec{:problems [{:path [], :pred map?, :val nil, :via [:paintings2.api-get/artObject], :in []}]} 

roelof07:02:47

all the code pf my site can be found here : https://github.com/rwobben/paintings

noturegora14:02:39

Trying to use reduced. Using this code sample from https://clojuredocs.org/clojure.core/reduced (reduce (fn [a v] (if (< a 100) (+ a v) (reduced :big))) (range 10)) I get the following error

CompilerException java.lang.ClassNotFoundException: clojure.core.reduced, compiling:(NO_SOURCE_PATH:1)

noturegora14:02:48

Aha, I see the problem. Though I have the latest clojure, the version of clooj that I have is using 1.4.0.

rubek14:02:49

The exact code copy/pasted into the Leiningen repl works fine for me. What version do you have?

rubek14:02:19

🙂 Alright

josh_tackett17:02:42

Anybody do slack webhook integrations? Code (http/post "https://hooks.slack.com/services/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" {:debug true :form-params {:payload (json/encode {"text:" “TEST”})}}) Error status: 500 body: missing_text_or_fallback_or_attachments

jjfine17:02:57

not sure how json/encode works, my code uses a json/generate-string eg:

(json/encode {:text "TEST"})

josh_tackett17:02:42

it was the : after text in string

ghadi18:02:17

if you're using clj-http @josh_tackett , no need to call json/encode. https://github.com/dakrone/clj-http#post Use :content-type :json and :form-params