This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-07-13
Channels
- # beginners (18)
- # calva (6)
- # cider (9)
- # clara (1)
- # cljdoc (14)
- # clojure (25)
- # clojure-boston (4)
- # clojure-brasil (3)
- # clojure-czech (2)
- # clojure-italy (2)
- # clojure-sweden (6)
- # clojurescript (6)
- # cursive (6)
- # data-science (4)
- # datomic (2)
- # emacs (5)
- # fulcro (2)
- # kaocha (4)
- # off-topic (2)
- # other-languages (1)
- # pathom (5)
- # precept (1)
- # reagent (2)
- # reitit (1)
- # shadow-cljs (2)
- # spacemacs (49)
- # tools-deps (13)
- # vim (14)
- # xtdb (4)
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
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
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?
check out pipeline-blocking
in core.async
Does exactly what you're looking for. Takes a sequence and does some work at specified concurrency.
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
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)
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)))
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))
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 😁
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
.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 😞 .