Fork me on GitHub
#beginners
<
2019-07-13
>
ec13:07:14

How would you write this? from readability and performance perspective

Drew Verlee20:07:02

That approach seems reasonable to me on both accounts. Small notes: 1. consider not mirroring clojure.core names like seq maybe use xs which can mean "a list of anything". 2. fn-name isn't common either (as far as i know) " " gets used to mean "a value you can ignore". The most complex part of this is that the patterns and the seq aren't really the same, the _contains method shows that sometimes the seq contains a set which contains the pattern item. Though a tad longer, its still the same big O. Also requires less special cases:

;;following the convention here:
(set/subset? #{1 2} #{1 2 3})
;; => true

(defn ordered-subset?
  "is xs1 a ordered (by index) subset of xs2?"
  [xs1 xs2]
  (= xs1 (filter (set xs1) xs2)))


;; matching
(let [c1 [1 2 3]
      c2 [1 3]]
  (ordered-subset? c2 c1))
;; => true

;; not matching because not all patterns matched
(let [c1 [1 2]
      c2 [1 3]]
  (ordered-subset? c2 c1))
;; => false

;; not matching because patterns not in order
(let [c1 [3 1]
      c2 [1 3]]
  (ordered-subset? c2 c1))
;; => false


Drew Verlee20:07:51

err this naming also works and is a bit more clear to use c1 and c2 in this case as those seem to indicate its a collection

dharrigan16:07:37

Let say I have a file of 10,000 lines that I read in and partition into 1,000 line partitions, now I want to send each of those partitions to something to execute in parallel (e.g., use all the cores), i.e., to send each line across each partition to a RESTful api, would there be a nice way to do this, using standard clojure libraries, or some useful async library?

jaihindhreddy17:07:59

check out pipeline-blocking in core.async

jaihindhreddy17:07:36

Does exactly what you're looking for. Takes a sequence and does some work at specified concurrency.

dharrigan17:07:45

nice, thanks. will explore.

andy.fingerhut17:07:52

Also the iota library does exactly this for files with records terminated by a single-character separator of your choice, parallellizing across cores on a single machine: https://github.com/thebusby/iota

💯 8
dharrigan17:07:12

excellent, thank you.

dmaiocchi21:07:12

in a doseq what is the clojurian way to skipping through the next iteration in the seq? (https://stackoverflow.com/questions/7491360/how-do-you-return-from-a-function-early-in-clojure)

dmaiocchi22:07:07

I might need to filter before the data 😁

mfikes22:07:43

If inside a doseq and I knew I needed to skip the current element, I might use a when. Here is an example:

(doseq [x (range 10)]
 (when (odd? x)
  (println x)))

mfikes22:07:43

But, yeah, if you can do more work in the "functional domain" then filter would be better, as you suggest.

(doseq [x (filter odd? (range 10))]
 (println x))

dmaiocchi22:07:03

thx! yep I was thinking to use println for skipping. but I think that I need to fliter data before passing to the sequence. My OOP imperative lazyness 😁

blck23:07:54

Hi all! New clojurian here. I am working through a tutorial involving luminus with h2 db, but when trying to migrate, I get the following in nREPL:

2019-07-14 01:23:49,540 [nRepl-session-5aebc560-c6e2-4db8-b7d9-8b84e1bfd014] INFO  migratus.core - Running up for [20190713232257] 
2019-07-14 01:23:49,540 [nRepl-session-5aebc560-c6e2-4db8-b7d9-8b84e1bfd014] INFO  migratus.core - Up 20190713232257-guestbook 
2019-07-14 01:23:49,541 [nRepl-session-5aebc560-c6e2-4db8-b7d9-8b84e1bfd014] INFO  migratus.core - Migration reserved by another instance. Ignoring. 
2019-07-14 01:23:49,541 [nRepl-session-5aebc560-c6e2-4db8-b7d9-8b84e1bfd014] INFO  migratus.core - Ending migrations 
:ignore
The problem is that I am not sure how to deal with Migration reserved by another instance.

Justin Duncan01:07:38

Ooh, I wanna know an elegant way to solve this too. I followed the same tutorial(I think) and messed up by doing something in the book before they asked and I had this error until I started over 😞 .

jumar04:07:55

You may want to ask in #luminus channel

👍 4