Fork me on GitHub
#beginners
<
2019-12-23
>
lackita00:12:47

Trying to wrap my head around using core.async in clojurescript to get around an ajax callback in a reagent template, any advice on places to look?

seancorfield01:12:23

There are channels for #reagent #clojurescript and #core-async that might be able to help (but things tend to be pretty quiet on a Sunday)

lackita01:12:59

ok, cool, I think I may have figured out what I needed for now, but I'll keep those in mind the next time I have questions

Cam11:12:23

Hey everyone, is there a canonical formatting and or linting used in the clojure{script} world? I have done a lot of Golang, and in Go, formatting and basic linting is provided by the complier, which silences all the arguments. I'd love to just use the "generally accepted" formatting and linting right off the bat

delaguardo12:12:53

I can recommend clj-kondo as a “generally accepted” linter, and this blog post about formatting will explain why there is no such tool (at least not “generally accepted” 🙂 ) - https://tonsky.me/blog/clojurefmt/

Cam12:12:06

Ok, thanks @U04V4KLKC thats very helpful

littleli15:12:40

Hi, I need a hand with interop... In Java I have following scenario: I have a builder with a bunch of methods on it. It has signatures with varargs and there are also overrides like this:

Builder someAction(String s, Operation... ops);
Builder someAction(Pattern p, Operation... ops);
I didn't find a way to call any of these from Clojure. Is there a way how to hint types in such case? Operation[] hint would be handful, but I don't know how to declare it.

alexmiller15:12:43

Use (into-array Operation [ ...operation instances... ])

littleli15:12:40

🆒 into-array was exactly what I was looking for 🙂 I tried make-array and object-array but it's clearly wrong because target type is then Object[] Thanks Alex! It would be great if there is an example in the faq page below.

alexmiller15:12:36

sounds like a good idea

alexmiller16:12:33

added

👍 1
💯 1
alexmiller15:12:27

(.someAction builder "foo" (into-array Operation [])) - like that

Ramon Rios16:12:52

Is there a way for execute two side effects on a function?

dpsutton16:12:31

(defn effects [] (fire-missiles) (delete-all-users) (utter-chaos!))

dpsutton16:12:10

not sure what you're looking for but you can use a do expression. And defn's have an implicit do body

Ramon Rios17:12:50

I would like to have to call two assoc-in in a function

Ramon Rios17:12:56

To set 2 different values

Ramon Rios17:12:25

I'm asking it cause in my lein midje autotest i see that it's only recognizing the last assoc on the function that i'm calling

dpsutton17:12:57

if you have something like this

(let [foo {:a 1}]
  (assoc foo :b :2)
  (assoc foo :c 3))
you aren't changing foo but making a new value. So the first assoc call creates a map with the b key on it but that doesn't change foo.
(let [foo {:a 1}]
  (-> foo
      (assoc :b :2)
      (assoc :c 3)))
Compare that to this threaded version

dpsutton17:12:50

exactly. this is saying "take foo, make a copy of it with the b key as two, and then to that copy put the c key.

Ramon Rios17:12:18

This is a macro, right?

Ramon Rios17:12:09

I saw it a lot on java or other functional stuff, but the concept of this and ->> doens't fit on my mind

dpsutton18:12:53

yes its a macro

dpsutton18:12:00

and a quite popular one in clojure

dpsutton17:12:28

which is equivalent to (assoc (assoc {:a 1} :b 2) :c 3)

Ramon Rios17:12:54

(defn check-correspondence [db]
  (assoc-in db [::current :policy-correspondence] :prod-manager)
  (assoc-in db [::current :invoicing-correspondence] :prod-manager))

Ramon Rios17:12:05

That´s my code

dpsutton17:12:51

yup. common mistake. Clojure's data structures are immutable. So in your first assoc-in call you don't keep that value so it is effectively thrown away

dpsutton17:12:40

Read you statements as "to a copy of db, add the prod-manager under policy-correspondence. to a different copy of db, add prod-manager at invoicing-correspondence"

Ramon Rios17:12:55

I think now it's main main challange, to refactor my way of think for functional and immutable data

Ramon Rios17:12:19

And how should be the right way for do it?

dpsutton17:12:45

try those two different forms i put above in a repl

hindol17:12:07

Can we yield a map from an anonymous function? Something like this? #({:document %}) What would be the correct syntax?

dpsutton17:12:52

(#(do {:a %}) 1) but the syntax doesn't buy anything over ((fn [x] {:a x}) 1) in my opinion

hindol17:12:45

Thanks you for confirming my suspicion. Yeah, it does not buy anything. fn it is.

👍 1
seancorfield18:12:10

#(hash-map :a %) is another option

👍 1
hindol17:12:05

Sorry to cut you off @ramon.rios @dpsutton. Did not notice you were in a conversation.

dpsutton17:12:26

we should have threaded. that's just kinda the way channels works. no reason to apologize 🙂

👍 1
dpsutton17:12:43

but nice of you to think that 🙂

Ramon Rios17:12:41

No problem @hindol.adhya 🙂 . We should had opened a thread for that

👍 1
Ramon Rios18:12:24

Is there some way of use a !false in clojure?

Ramon Rios18:12:28

For example. i want to check a value with contains? but actually, i would like to check if this value not exist in the map

Ramon Rios18:12:58

like a not-contains?

jaihindhreddy19:12:18

See in clojure.core: 1. not 2. if-not 3. when-not 4. complement 5. not=

hindol20:12:30

Also, if you are filtering a sequence, remove is a drop in replacement that does the opposite. Filter preserves the matches, remove drops them.

Enyert Vinas18:12:26

for example you can use this (not (contains? coll key))