Fork me on GitHub
#beginners
<
2018-05-25
>
noisesmith00:05:38

the missing step there is a mapping like {:val-1 [:prop-1] :val-2 [:prop-2] :val-3 [:prop-3 :nested-prop-1]} so it knows where to put them by key

noisesmith00:05:18

but that's still not as simple as just having the map literal with the values in the right places, so if you don't need the flexibility don't do it this way

athomasoriginal00:05:23

I see it now. The only issue I have with my map literal is I am repeating it 3 times, and there is only 1 property difference for each. It just did not feel idiomatic to do this.

noisesmith00:05:39

OK - in that case you can use the assoc-in / lookup to abstract it and reuse the repeated behavior, but whether it makes sense in your code is for you to figure out of course

Bruno Romero02:05:35

Hello Guys, I currently work with ruby on rails and I really want give clojure. Do you guys recommend any books/videos/tutorials for a clojure newbie with rails/spring background?

gklijs05:05:26

@stardiviner it’s java interop, calling the close function on ByteArrayInputStream

stardiviner05:05:25

@gklijs how can I know java interop calling the close function on which object like ByteArrayInputStream?

gklijs05:05:36

Cursive knows, I have no experience with other ide’s. Also with intellij it’s easy to go to the sources of ByteArrayInputStream

stardiviner05:05:26

I see. Thanks

gklijs05:05:54

Maybe you can ask in #cider how to get it in cider.

Mau09:05:12

I am using Soda-Ash (interface between reagent and semantic-ui-react) - Has anyone got the Sidebar working. I am struggling how to implement this using soda-ash.

rauh10:05:28

@klaus.azesberger The #js isn't nested automatically

kazesberger10:05:43

ah and the head.js import was missing too. now it works. gonna pr this. thx a lot for the quick help ❤️

gadfly36113:05:31

@mhsmit See my comment in this issue, there is an example of a sidebar https://github.com/gadfly361/soda-ash/issues/10

ScArcher18:05:21

What's the best way to handle an expiring oauth token in Clojure? I'm writing a simple REST API client to learn clojure, but I don't really know the best way to keep / replace the oauth token when it expires. (It lives 30 minutes) I have something like this {:client-id "123455689" :client-secret "1234512345" :token nil) I make a call to the authentication API, and get back the token and expiration time. I thought about just adding those properties to the map, but again i'm not sure where to put the map and how to mutate the token / expiration.

donaldball18:05:08

A simple place to start would be to use core.cache

donaldball18:05:47

Though that might be more sensible if you had e.g. multiple expiring tokens you were trying to manage

donaldball18:05:16

It sounds like you want an atom in which to store your client state

noisesmith18:05:48

with core.cache you'd need an atom - it doesn't handle persistence, just the cache management logic

bertofer18:05:56

Hi, I am working in a project where I connect to a websocket API and then subscribe to different channels and keep the state of that subscriptions, and also state related to the messages incoming. There are different levels of “calculated state”, so I was planning to have different agents. One of them even needs to (send) to itself sometimes, depending the messages coming from the websocket connection (saved in one of the agents too, as needs to be replaced for new connections sometimes), and also execute side effects inside the agent. I was thinking on initialize each of the agents with an object that references all the agents in the “platform” (they are around 3 to 5, still deciding), thus having references to themselves in the value (and to the others), so they can send data to each other. Is this a good / bad practice? Any advice on how to handle this situations? Any different / better approach? Thanks!

noisesmith19:05:08

an alternative to agents would be core.async, which is built around channels and events rather than mutations to an object in a container

noisesmith19:05:04

so instead of sending a function that takes your agent and returns the replacement for the data in the agent, you send a message that is consumed by someone listening to that channel, which then integrates the data as it likes, optionally sending more messages

bertofer19:05:29

Yes, it’s another option I had in mind, but I struggle to figure out how to save state then combined with reading from channel. Maybe atoms? And sync change them on the loop for reading from a channel?

noisesmith19:05:07

if you need to make the data globally visible outside the go block, that would likely be the simplest option yes

noisesmith19:05:44

it should be doable with agents, but anecdotally I've seen complex things like this done successfully in core.async and never with agents

noisesmith19:05:46

another pattern is a thread containing a reduce over some input source that updates an atom inside

noisesmith19:05:24

I've seen this sort of thing with kafka for example

bertofer19:05:37

Thanks @noisesmith, will try the core.async approach. As for the thread containing a reduce, do you have any example of that? Don’t really see what you mean there

noisesmith20:05:06

something like (future (reduce (fn [state input] (swap! external-store process state input)) @external-store (input-seq))

👍 1
noisesmith20:05:41

where the hypothetical process function takes the external state, the reduce local state, and the next input as args and returns a value used by both the external store and the next reduce step

SoV420:05:23

hello, when printing a sequence, how can i remove the surrounding parens or surrounding #{set} braces?

noisesmith21:05:26

(apply println c)

SoV421:05:21

gives me strange results, i'm trying to (println (str "your results are " (seq (first (result-set)))))

kazesberger21:05:49

(println (apply str (interleave asdf (repeat \space)))) ?

1
noisesmith21:05:49

well you called str, use string/join to remove parens at that level

noisesmith21:05:00

why do you want to call str though?

SoV421:05:24

What's best practice for printing to stdout?

noisesmith21:05:47

user=> (apply println "your results are:" (range 5))
your results are: 0 1 2 3 4

1
noisesmith21:05:13

I just don't know why you called str, and calling str is why apply println didn't work

SoV421:05:08

Aha, I don't need to call str at all! 😃

SoV421:05:22

although apply str interleave did the trick, too.

noisesmith21:05:14

but string/join does that, and is purpose built for it

justinlee22:05:17

could someone help me understand how this code isn’t circular

(extend-type default
     pt/IPromise
     (-map [it cb]
       (pt/-map (resolved it) cb))
It seems to me that -map is calling itself

noisesmith23:05:29

it's calling the same method on a different object

noisesmith23:05:52

if resolved on a promise returned the promise, this method looping wouldn't be your biggest problem

justinlee23:05:07

oh i see. so it’s calling (resolved it) first and then calls -map on that