Fork me on GitHub
#clojure
<
2016-09-10
>
stbgz00:09:17

hey all how can I transform the contents of a channel?

(defn download-pom-for-dependency [dependency-url]
  (println dependency-url)
  (map #(identity %2) [(make-request dependency-url)]))

stbgz00:09:09

where

(defn make-request
  [url]
  (let [out (chan)]
    (.get request #js {:url url}
          (fn [error response body]
            (put! out [error response body])))
    out))

darwin00:09:59

or you can use alts and implement your own loop https://clojuredocs.org/clojure.core.async/alts!

hiredman01:09:40

Or add a map transducer to the channel

mpenet10:09:47

All the other slack groups I know use #general as the main channel, what would be the equivalent of #C03S1KBA2. I am not sure why #C03S1KBA2 was created in the first place...

fellshard18:09:08

I believe it was to distinguish Clojure discussion from Clojurescript discussion

didibus19:09:50

I thought Clojure was to discuss Clojure, and ask questions. And ClojureScript is the same for ClojureScript.

didibus19:09:29

General feels like a non useful channel, like people would talk about even non clojure related things

didibus19:09:41

Speaking of discussing Clojure: What is the intent of metadata? I'm trying to figure out what I can reliably use it for. It can be added to symbols and collections, but not sequences, and I'm not sure if you can trust every collection and symbol function to keep and work properly with metadata.

didibus19:09:51

Is it mostly a reader specific feature? Or can I reliably use it to a add meta dimensions to my collections?

didibus20:09:03

Like imagine I had an algorithm that could be made more performant if it knew that a vector contained only odd numbers. So I want to start tagging my vectors with ^:odd when I know from their creation that they respect that property. Then my algorithm can transparently optimize when given an odd vector, and resort back to a slower implementation when the vector doesn't provide that info.

quoll20:09:02

Metadata is "data about the data”. Semantically, it should be some kind of out-of-band info about what is in the data structure, but in practice it could be anything. Your example is a good example of “data about the data”, so it would be fine.

quoll20:09:07

You’ve noticed that some things can’t have metadata (it needs to implement clojure.lang.IMeta)

quoll20:09:26

but I don’t know what you mean when you said it can’t be added to sequences?

didibus20:09:16

Well, maybe I'm wrong, but not everything that returns true for (sequence?) can have meta. Such as lazyseq

quoll20:09:18

Perhaps you meant something else?

quoll20:09:30

=> (meta (with-meta (map inc (range 3)) {:foo :bar}))
{:foo :bar}

quoll20:09:17

=> (class (map inc (range 3)))
clojure.lang.LazySeq

didibus20:09:57

Ok, I guess I'm wrong. I thought since the doc on metadata said symbols and collections only, it didn't include sequence

quoll20:09:23

sequences are collections though?

didibus20:09:27

So my second question is, can I trust all core fn to keep the meta?

gfredericks20:09:43

it's complicated

gfredericks20:09:52

especially with sequences

quoll20:09:13

you mean, when you create something new from a collection with metadata, then will the new thing have the same metadata as the original thing?

Alex Miller (Clojure team)20:09:39

My general experience has been that every time I tried to use metadata for out of band info, I ultimately decided that that metadata was really data and that it wasn’t worth the effort of retaining it

Alex Miller (Clojure team)20:09:44

b/c it’s not as visible, it takes another level of awareness about what you’re doing that makes the code harder to maintain and communicate with others

quoll20:09:57

I’d agree with this. The main benefit (for me) has been if I want to annotate data so I can cache some sort of work associated with it (where full memoization doesn’t quite fit)

quoll20:09:33

but if my code breaks when metadata isn’t present, then it probably should have been data

didibus20:09:04

@quoll Ya pretty much that

didibus20:09:38

How would I attach the kind of data as in my example without metadata though?

quoll20:09:49

sorry… I’ve lost track of your example?

didibus20:09:16

That all element are odd in the vector

quoll20:09:17

Well… two things. First, since it will successfully calculate (just less efficiently) without the annotation, then this is a case where I would be comfortable with using metadata.

quoll20:09:01

Second, if you really needed annotations, then: {:annotations {:odd true} :data [1 3 5 7 9]}

quoll20:09:42

Third (I’m great at keeping count): memoize the function that calculates oddness

quoll20:09:27

(def all-odd? (memoize (partial every? odd?)))

quoll20:09:09

not that I advocate memoize. I suggest core.cache 🙂

didibus20:09:53

Alright, I think I'm getting a good picture here

didibus20:09:14

Simply wrapping in a map is goid

mfikes22:09:26

Regarding the bounded-count core.async discussion of yesterday, the slightly concerning thing is that the arguments have been backwards the entire time too. Captured in http://dev.clojure.org/jira/browse/ASYNC-175