Fork me on GitHub
#beginners
<
2021-09-10
>
Benjamin05:09:58

does somebody know an open source project using core.async to look at?

seancorfield06:09:46

@benjamin.schwerdtner mostly core.async is a "glue" technology so you find it in apps, rather than libraries.

👍 2
Duane Bester22:09:16

Curious about this. Was planning on using core.async for some socket stuff-- would you recommend something like manifold for building a lib around sockets? Thanks in advance!

seancorfield22:09:22

@UN8GKGSBG Depending on what you are trying to do, I'd use core.async. We use core.async at work for a web socket app.

Duane Bester22:09:58

Basically wanting to wrap a socket talking to postgres in a functional (clj / cljs) library and as byte buffers move up in abtraction (e.g. buffer -> frontend/backend messages -> query/commands), to pass that data via channels. But I just want to make sure that's an okay approach for a library

seancorfield22:09:44

Possibly. It's hard to design a library that uses core.async "correctly". It's hard to design any async library.

💯 2
raspasov23:09:54

Most core.async libraries you can find are usually enhancements/additions to the core.async library rather than building something completely new on top of it. CSP is a pretty powerful paradigm, you can express a ton of things with it, esp. when you combine it with transducers. One of my favorite libraries to use together with core.async is https://github.com/cgrand/xforms

raspasov23:09:53

For example, you can easily compute a running average of number values as they flow through a core.async channel.

🙌 2
Benjamin07:09:26

;; what is the difference between
(a/put! c "fo")
;; and
(go (>! c "fo"))

hiredman07:09:46

They are equally bad

hiredman07:09:22

The call to put! is maybe, not so you'd notice, ever so slightly more effecient

hiredman07:09:59

Are you asking in the general case, what is the difference between put! and >! or asking about those literal snippets?

Benjamin07:09:50

The use case is to put something on a channel from synchronous code, if that makes sense

hiredman07:09:03

In the general case, channels are places for threads to meet and exchange values

hiredman07:09:51

put! ignores the "meeting" part and just throws a value on the channel without regard for of anyone wants it

hiredman08:09:03

It is bad, don't do it

catjam 4
hiredman08:09:15

If you must, then try and use the arity of put! that takes a callback

Benjamin08:09:35

And I guess doing (go (>! .. has the same issue ?

hiredman08:09:57

If you use put! with the call back, the callback won't be called until the put! value is consumed (more or less, if it is a buffered channel and there is space in the buffer too)

hiredman08:09:31

So you can "meet" via the callback, do something; use put! with cb; do it again in the cb

👍 2
Ryan15:09:13

Whats the best way to get a value out of a map when I don't know the key? Trying to access value of a iteration over a list of indexed entities (e.g. {23 {:id 23 :name "Steve"}}) and trying to write some predicates that will work regardless of the id

Fredrik15:09:49

Are you thinking of something like this?

(let [m {1 :a 2 :b 3 :c 4 :d}]
    ;; extract keys that are even
    (reduce-kv (fn [acc k v]
                 (if (even? k)
                   (assoc acc k v)
                   acc))
               {} m))

Fredrik15:09:26

You want to extract out a submap, or only the values associated to keys satisfying some predicate?

Ryan15:09:44

I think the whole submap

Ryan15:09:58

Its an object wrapped in a map indexed by its ID

Ryan15:09:04

for a re-frame db

Fredrik15:09:26

A shorter way: (into {} (filter #(even? (key %))) m)

Ryan15:09:43

right I forget about into{}!

Fredrik15:09:03

Cool, you think this solves your problem?

Ryan16:09:03

I think so! thanks

dgb2321:09:09

I want to write (defmulti foo identity) but I’m somewhat hesitant. My questions are: Why not let the user define what they want to dispatch on? Am I misusing mulitmethods this way? Is this method underspecced in the sense that it is likely hard to identify how dispatching works when enough multimethods are added? Edit: it doesn’t work like I was thinking does it?

sova-soars-the-sora23:09:13

the user is accessing the source code ?