This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-04
Channels
- # arachne (2)
- # bangalore-clj (3)
- # beginners (34)
- # boot (22)
- # cider (1)
- # cljs-dev (86)
- # cljsjs (3)
- # clojure (42)
- # clojure-argentina (6)
- # clojure-austin (10)
- # clojure-chicago (1)
- # clojure-france (3)
- # clojure-russia (135)
- # clojure-spain (1)
- # clojure-uk (4)
- # clojurescript (69)
- # core-async (13)
- # cursive (11)
- # datascript (6)
- # datomic (8)
- # dirac (2)
- # emacs (10)
- # euroclojure (1)
- # events (1)
- # gsoc (13)
- # jobs-rus (9)
- # lumo (7)
- # off-topic (18)
- # om (16)
- # perun (3)
- # planck (1)
- # portland-or (1)
- # re-frame (25)
- # ring (22)
- # spacemacs (1)
- # untangled (14)
what does the ... mean in:
(d/q '[:find [(pull ?e ?selector) ...]
:in $ ?selector
:where [?e :app/title]]
(context: datascript)search for “collection binding” here: http://docs.datomic.com/query.html
> A collection binding binds a single variable to multiple values passed in as a collection.
https://clojuredocs.org/clojure.core/binding <-- this is NOT a clojure feature, and is a datomic/datascript feature ?
can you define local variables in a defrecord
that is accessible to all methods in the body?
e.g. something like
(defrecord Foo [bar]
(let [thing (compute bar)]
p/Protocol1
(method1 [this] (do-something thing))
p/Protocol2
(method2 [this] (do-something-else thing))))
you can add another field thing
to the defrecord and add a custom contructor
(defn make-foo [bar] (->Foo bar (compute bar)))
or, I could write a super complicated macro which lets me bind stuff in the record body? right? 😄
or just recompute thing every time you use it 🙂
is this because compute
is slow?
is it possible (read: worth it) to write unit tests for JDBC code that don’t use a real database?
Mocking the database is possible, but probably not worth it. Most of the app tests I’ve seen spin up a local sqlite or use a pool of test mysql instances to do functional testing against a real db
(cross-post from #beginners ) how would I chain str/replace-first
?
(-> (str/split (message :content) #" ") first (str/replace-first "what here? %1?" #"!" ""))
(in other words how do I chain a function with a multiple arity)
Tried #(str/replace-first %1 #"!" "")
it didn't like that.
@schmee If you need to test that your db-related code really writes/reads as expected than it's better to use the real database for such tests. On the other hand, it is worth to mock/stub the db calls away when, say, you test "business logic" "units". Because for such tests you shouldn't care if they modify the real db instance or even if the value is really written somewhere. Without the real db such tests will be much faster. To make it work the JDBC invoсations should be encapsulated in the dedicated component which is injected as a dependency to your business logic components. Such db layer will be easier to stub/mock than trying to isolate low-level stuff such as JDBC connections.
@eslachance ^ You almost had it there, but you can’t nest function literals (`#()`). Try using the function literal inside a spelled-out anonymous function instead (ie (fn [s] … #( … ))
)
hmmm.... why is (-> (str/split "!ping me" #" ") first (fn [s] (str/replace-first s #"!" "")))
giving me CompilerException java.lang.IllegalArgumentException: Parameter declaration first should be a vector,
?
(as you can tell I like to do fancy things but I'm still kinda new to clojure in some basic aspects and I feel like a noob)
ooooh wait maybe it's simpler than that. the threading macro inserts the result of the previous as the 2nd element, exactly what I need.
Smart, clojure. Smart.
@eslachance user=> (macroexpand-1 '(-> (str/split "!ping me" #" ") first (fn [s] (str/replace-first s #"!" "")))) (fn (first (str/split "!ping me" #" ")) [s] (str/replace-first s #"!" ""))
(-> (str/split "!ping me" #" ") first (str/replace-first #"!" ""))
actually works great 😄
right now my API uses a record that encapsulates the DB connection, so I can write unit test for the code that uses that, and integration tests for the record itself
@eslachance I guess the exception is about (fn (first
🙂
but you've already figured that out
I love clojure. most of the time 😄
@schmee yes, it's similar to what I usually do
@eslachance what’s your avatar? I don’t recognize it.
It's the icon for my library, which I know for a fact is probably breaking rules about the Clojure logo
but it's so damn nice though.
Anyone wanna comment on how sexy and clean this looks?
(defn handle-message [session message]
(let [command (-> (str/split (message :content) #" ") first (str/replace-first (config :prefix) ""))
args (drop 1 (str/split (message :content)))]
(cond
(= command "ping") (dithcord/send-message session "pong!" (message :channel_id))
(= command "say") (dithcord/send-message session (join " " args) (message :channel_id))
:else nil)))
❤️ Clojure