Fork me on GitHub
#beginners
<
2018-12-24
>
jaihindhreddy03:12:09

Is there an equivalent of (juxt #(filter % %2) #(remove % %2)) in clojure.core that does the work in one pass?

jaihindhreddy03:12:48

Please ignore. group-by takes care of this for predicates that return a boolean.

seancorfield03:12:08

See also partition-by

seancorfield03:12:04

(for another take on splitting up data based on the results of applying a function)

Denis G11:12:18

what is the common way of designing async api in Clojure. Callback based param? Returning channels like in CSP

jaihindhreddy13:12:36

@denisgrebennicov you can use pedestal. You can return a channel in an interceptor

danieroux14:12:01

I don't understand lazy-seq with take, as in this example: https://techblog.roomkey.com/posts/clojure-kafka.html My expectation is that take will return everything available from the lazy-seq, up to the n given. It's not doing that, it seems the lazy-seq is waiting for more data to fulfil the take. (in my example, there are 8004697 messages - and I get exactly 8000000 of them, with a batch size of 10000)

Lennart Buit14:12:05

Hey, I am starting to look into datomic, but I cant seem to find the agreed upon way to store and migrate the schema. Is there some form of library/convension of doing so?

Lennart Buit14:12:30

In the non-datomic world, frameworks like rails and django have a table with migrations and a set of files in vcs, but that appears to be no convension in datomic is it?

Lennart Buit14:12:32

is that supported for datomic client?

Lennart Buit15:12:02

It appears to be not the case 😢

mfikes16:12:35

@danie It is possible to have an infinite lazy seq where elements take a while (block) in order to be returned, and take will also block. For example:

(defn slow-seq [n] (Thread/sleep (* n 1000)) (lazy-seq (cons n (slow-seq (inc n)))))
(take 3 (slow-seq 1))

mfikes17:12:22

That Kafka example is perhaps more like

(defn infinitely-slow [] (Thread/sleep 10) (lazy-seq (concat nil (infinitely-slow))))
(take 3 (infinitely-slow))

lilactown17:12:26

is hashmap key order stable/guaranteed?

lilactown17:12:53

e.g. if i do

(for [[k v] {:key "val"}]
  ...)

mfikes17:12:56

Yes, at least for a given object. Its order will match other things, like that produced by seq or vals

lilactown17:12:24

great, thanks!

victorb17:12:50

hm, any way I can reset all dependencies somehow? I'm using a docker clojure client, and at first, everything worked great, then I think the import of org.apache.commons.compress.archivers.tar screwed something up, and I'm unable to recover. lein clean doesn't help and everything works fine when creating a new project, but not in my existing one. Here is the error I'm getting + the snippet of code that works in one project but not the other: https://gist.github.com/victorb/e547e6fb02a6855500a4f308dea06da7

victorb20:12:18

only thing that helped was explicitly putting [org.apache.commons/commons-compress "1.18"] in my list of dependencies

jaihindhreddy17:12:42

(s/def ::a (s/with-gen (s/coll-of any?) #(s/gen (s/coll-of int?)))) ::a is a sequence of anything but for example generation and property based testing ints are used. Does this make sense or is this an anti-pattern? s is clojure.spec.alpha and gen is clojure.spec.gen.alpha

mfikes18:12:40

@jaihindh.reddy It is certainly the case that generators often generate a subset of what is spec’d. But your example seems to go pretty far on that theme. 🙂

jaihindhreddy18:12:26

I get it. any? and int? are pretty far off 🙂

jaihindhreddy18:12:22

Is (s/coll-of any?) good for generative testing though, because any? value here are used as keys in a map, and it really doesn't (shouldn't) matter what type they are. Testing with int? is way faster.

mfikes18:12:43

Two points: • any? is not used above for keys in a map, but for elements in a collection • Oftentimes generators are written in a way that is pragmatic wrt perf

mfikes18:12:28

In general, what you are doing makes complete sense, IMHO.

mfikes18:12:38

Sometimes, putting an upper bound on the collection size being generated is a good pragmatic thing to consider.

jaihindhreddy18:12:35

Thank you for your insight sir.

Andreas Edvardsson18:12:27

Is there a way to alias part of a namespace? i.e. alias a directory. Example: let's say the following namespaces exist: example.store.user example.store.order example.store.etc... I'd like to get an alias for example.store :as store say.

seancorfield18:12:57

No, you can't do that. You can only alias the whole namespace name.

Andreas Edvardsson18:12:36

Okey great, now I know. Thanks Sean!

Lucas Barbosa19:12:52

Are the basic uninformed search algorithms (e.g. dfs, bfs, ucs) implemented in any core Clojure library?

Lennart Buit19:12:39

there is loom, for graph algorithms. Also, there is clojure.walk for navigating maps

Lucas Barbosa19:12:47

I'm going to take a look at loom, thanks!

Lennart Buit19:12:08

^^ happy holidays

andy.fingerhut19:12:04

Also ubergraph, similar to loom -- I have not dug into both of those enough to tell the difference between them.

jaihindhreddy19:12:00

Loom implements graph algorithms based on abstractions (protocols). Ubergraph depends on loom, and is an implementation of Loom's protocols, a very flexible one at that. Loom itself gives you concrete graph representations but Ubergraph is more flexible (allows mixture of directed and undirected edges, multiple weights per edge, etc.)

stardiviner23:12:42

How to add project local JAR into dependencies path with clj-new generated deps.edn?

stardiviner23:12:54

@seancorfield HI, morning