Fork me on GitHub

is there a quick way to mark “this entire thing is optional” via plumatic/schema?


i.e. I have {:foo 1 :bar 2 :baz 3 … :zzz 26}, but each one of those keys is optional.


I would prefer not having to do (schema/optional-key down the line, if possible


lwhorton: you could do it programmatically


I wrote a function called optionalize-key once


you could use it to optionalize all the keys via (reduce optionalize-key map-schema (keys map-schema))


any number of similar tactics would work too


Is there anything like a for loop (allowing iteration over multiple variables) with reduce-like accumulation rather than generating a seq?


I occasionally end up having to do nested reduces, where each level uses closed-over bindings from outer levels so I can’t easily extract them into reducing functions.


@cfleming: are you familiar with loop/recur? It sounds like that's what you need, and I've used it before to un-nest multiple reduces.


@josh.freckleton: I could do that, but it’s a pain having to manage the seq iteration manually.


what do you mean? loop/recur doesn't need to accumulate to a seq...


@cfleming: could you be more specific about what you're trying to solve?


@josh.freckleton: What I mean is that if I use loop/recur, I need to use code like:

(loop [items (some-seq)
       accumulator (some-initial-value)]
  (if-not (seq items)
    (let [item (first items)]
      (recur (rest items) (do-some-processing accumulator)))))


That’s just one loop level, it gets worse with multi-level.


Compare that with (reduce do-some-processing (some-initial-value) (some-seq))


I'm not crystal clear what you're trying to solve, but I've had (what I assume are) similar situations that I've solved in one loop, where the loop keeps track of a few items, and then your conditional can be a cond or case that accounts for the multiple different items... would that help?


Here’s what I’m working on:


(WIP, contains bug right now where intermediate map levels are not created correctly, but you get the idea)


So here I’m iterating over modules, and within modules I’m iterating over namespaces.


It’s an ideal match for a for loop, except I’d rather not create a potentially large intermediate seq just to do (into {})


That function is just too big, but I can’t trivially extract the reducing functions because they close over outer values.


I need to leave soon, so regrettaly dont have time to dig in. But to explain my solution to similar situations, imagine in your loop you have modules and nss, you only exit when both modules, and nss are empty. If nss is not empty, process one, loop on the rest. If nss is empty, then load the next module, fill up nss for the next go-round, and process until both of those seqs are empty.


This case isn’t too bad, but with another level (which I’ve had from time to time) it gets pretty hairy.


ya, I think my solution is an elegant way have handling arbitrarily many seqs to loop over


(if I'm understanding)


Sure, but like I say, you end up with a lot of manual seq management - I’ll try it, but I suspect that it’ll be a wash.


Thanks for the suggestion though, I’ll definitely try it.


no problem, I hope it helps! is my proposal clear? it would look something like this: (working up an example...)


(let [rr (comp reverse range)]
  (loop [a   (rr 3)
         b   (rr 3)
         c   (rr 3)
         acc []]
      (empty? a) acc
      (empty? b) (recur (rest a)
                        (rr (first a))
                        (rr (first a)) acc)
      (empty? c) (recur a (rest b)
                        (rr (first b)) acc)
      :else      (recur a b (rest c)
                        (conj acc (apply str (map first [a b c])))))))


@cfleming: (not my cleanest code, but it gets my idea across. It effectively looks like one loop, even though the seqs a b c are all getting looped over)


@cfleming: so you start with 3 seqs, a is the highest level, followed by b then c. When c is empty, it fills up again from b. Same with b from a. When a is empty, you know that there's nothing left to process. The last line of code with conj ... is where you do the work using the relevant parts of a b c.


@josh.freckleton: Thanks - that does actually look pretty clean. I’ll give that a go, thanks!


if I have a java object that implements an interface (`WebDriver`) and a clojure protocol (`IDriver`) that is extended over that interface (`(extend-type WebDriver IDriver …)`) should the protocol work over any java objects that also implement the interface?


@cfleming: is reductions helpful?


hello, someone know why when i am try to insert values into postgres like this: (sql/insert! db :users {:email (:email user) :password (:pass user) :username (:username user)}) in db i had field with free spaces? most of columns 100 symbols length according db scheme. but when i try to compare same values from db and (noir.util.crypt/encrypt ourpass) its different, because i think problem if free spaces? db gives me pass like this "somehashingpass " - my pass to compare is "somehashingpass" i use [org.clojure/java.jdbc "0.6.1"] and driver [org.postgresql/postgresql "9.4.1208.jre7"]


Hi, I need to use rdf4j repository with lucene index. These all things are provided but it seems it is not thread safety somewhere in deep on the lucene side. So I should assume the pessimistic variant that thread safety is not provided at all. I would like to wrap the repository in one thread and communicate with the rest through the channel. Multiple threads will do input file reading and populate the channel. What do you think about that. Is it possible to implement it in a quick-and-dirty solution?


@agi_underground: is the password column defined as CHAR or as VARCHAR?


That’s why then. CHAR always pads out to the full width of the column, use VARCHAR to keep only the actual length of the string


(I’m hoping that’s right anyway, I haven’t done postgres for a while, but I think that’s standard SQL)


@manutter51: yes, thank you, it`s work!


hi there! are there any opinions on the new "Professional Clojure" book yet? My google searches came out empty :(


I find myself doing quite a bit of this: (remove nil? (map :some-key heterogeneous-collection)) Wondering if it's a code smell


Read it and be the first? >:)


unless you care about false nevermind it actually checks for nil? so you're fine


nope! thanks!


What do folk use/suggest in Clojure (or ClojureScript) for mesh manipulation (remeshing, extruding, etc ...) ?


(I do not need the rendering part, only the processing of it)


I'm curious to know the explanation behind this:

user=> (clojure.set/difference #{"foo" "bar"} ["bar" "foo"])
user=> (clojure.set/difference #{"foo" "bar"} ["bar" "foo" "quux"])
#{"bar" "foo"}


What I understand is that clojure.set/difference expects sets for all of its arguments.


What I don't understand is why it does what it does when given vectors.


That’s just what happens as a result of the implementation (which expects sets) - you can read the impl to understand why. The result you’re seeing won’t make sense as it violates assumptions in the impl.


Oh I see; it uses a different code branch based on the sizes.


If contains? worked on lists in the way I wish it worked, then the set difference algorithm would work with lists as the second argument as well.


if contains? worked the way you wish it worked, it wouldn't be contains? :)