This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-08
Channels
- # aws (3)
- # beginners (126)
- # boot (19)
- # cider (31)
- # cljs-dev (324)
- # clojure (96)
- # clojure-boston (2)
- # clojure-denver (9)
- # clojure-dusseldorf (2)
- # clojure-greece (4)
- # clojure-italy (5)
- # clojure-losangeles (1)
- # clojure-spec (18)
- # clojure-uk (59)
- # clojurebridge (1)
- # clojurescript (184)
- # community-development (29)
- # cursive (2)
- # datascript (2)
- # datomic (5)
- # emacs (1)
- # figwheel (6)
- # fulcro (270)
- # hoplon (2)
- # jobs (1)
- # jobs-discuss (1)
- # keyboards (2)
- # leiningen (2)
- # london-clojurians (2)
- # luminus (10)
- # mount (1)
- # off-topic (26)
- # onyx (8)
- # other-languages (1)
- # parinfer (1)
- # protorepl (6)
- # re-frame (23)
- # reagent (61)
- # reitit (5)
- # shadow-cljs (100)
- # spacemacs (3)
- # sql (19)
- # unrepl (90)
- # vim (25)
Since :id
will either be present or not, just testing (:id item)
is all you need.
But for group-by
you need to detect presence so (group-by #(contains? % :id) seq-of-items)
should be sufficient.
That will produce a map with two keys (`true` and false
) and the value of the true
key entry will be a sequence of all the maps that contain an ID and need to be updated, and the value of the false
key entry will be a sequence of all the maps without an ID that need to be bulk-inserted.
I suppose, if the sequence is gigantic, and you want to be lazy, and the values under :id
are truthy, then (filter :id seq-of-items)
and (remove :id seq-of-items)
would be another way to produce the two lists
I figured it out with group-by (group-by #(true? (= (:d %) 0) seq-of-items)
but how would I do that with filter
or remove
?
@josmith2016 that call to true? can be removed
and any (= x 0) can (and should) be replaced with (zero? x)
@josmith2016 to do that with filter or remove, use the same function you provided to group-by
(remove f seq-of-items)
Thanks @noisesmith I must have typed something wrong the first time I tried it, it worked this time
so with both my suggested changes your function does the same thing but is clearer #(zero? (:d %))
Hi, is there a uri predicate for clojurescript?
I'm interested in using REPLs in a more complex way, as described here: https://github.com/jafingerhut/talk-transcripts/blob/master/Halloway_Stuart/REPLDrivenDevelopment.md
(also the repl captures my input, it's not like my usual CIDER repl.... but, one step at a time)
Oh! Perhaps this is a bug in CIDER: https://github.com/clojure-emacs/cider/issues/2017
Perhaps I don’t understand secretary
well.
I have an anchor like this:
[:a.btn.btn-primary
{:on-click #(do
(println i)
(secretary/dispatch! "/device"))}
"Details"])))
My route before I click the anchor is
.
After I click, it’s still the same. But the device
component gets displayed. Because of this, The home component (corresponding to
gets hidden.
Does this make sense? How to actually go to
when anchor is clicked?@suryapjr Yes, but the JVM has a bit of a startup overhead. If you use clj
, that is minimized.
@duminda what you are attempting to do looks correct to me. Is that the code you are actually using? I only ask because you have a (println i)
in the click handler but there’s no i
declared anywhere
@lee.justin.m: Yes, part of the actual code. The println
is just for debug puropses.
yea sorry i can’t see why that wouldn’t work. i actually use accountant
and secretary
together, so I call accountant/navigate
, but they function similarly, and if the href
works the dispatch!
should work
@lee.justin.m: Ok, I will have a look again.
@seancorfield cool !! Thank you !!
(java.util.Random.)
creates the random instance, then (.nextInt <instance> 100)
calls nextInt on it with n=100
(ns magic)
(defn -main[]
(println "Lets generate a random number")
(import java.util.Random)
(def magic (.nextInt (java.util.Random.)100) )
println(magic)
)
The above code gives me : ClassCastException java.lang.Integer cannot be cast to clojure.lang.IFn magic/-main (core.clj:7)
So that error is saying your trying to call something as a function but it’s not a function
$ clj
Clojure 1.9.0
user=> (def magic (.nextInt (java.util.Random.) 100))
#'user/magic
user=> (println magic)
30
nil
@pooelfbin Note that def
will make a “global” variable. If you want to define variables inside a function, you should use let
:
(let [magic (.nextInt (java.util.Random.) 100)]
(println magic))
comparison of different testing framework for clojure http://jakemccrary.com/blog/2014/06/22/comparing-clojure-testing-libraries-output/
My code :
(defn clojurify [def a]
(import java.util.Random)
(.nextInt (java.util.Random.) a))
you have 'def a' in the arg list
why the def?
it's just a, no def needed in Clojure
And i wanted to know in the project.clj - :url , Do i have to create a github repo and paste the link there aur lein will automatically publish it with after pasting the link with lein deploy
maybe you could just use rand-int, take a look: https://clojuredocs.org/clojure.core/rand-int
@suryapjr no, the :url is just metadata it doesn't even have to be there
@tbaldridge cool!! Thanks a ton!
this might not be a total beginner question, but googling isn’t helping me much - so.. 🙂
for example, i have a function which performs a db action, and i’d like to be able to override that particular require with some mock
There are ways of mocking and stubbing calls to vars, but it's not a generally recommended approach. Look at with-redefs in core
@dazld this is probably a sign that you should hide your db behind a protocol.
@dazld Take a look at https://github.com/clojure-cookbook/clojure-cookbook/blob/master/03_general-computing/3-09_polymorphism-with-protocols.asciidoc
The idea of a protocol is that you define a bundle of operations and give it a name. Then you can implement that bundle for different data types. Sort of like interfaces in Java, if you know Java.
aah, ok - so, would be able to pass it a mock connection, for example, and leave the rest alone
If I'm following you correctly, yes.
Hi, I would like to use this JS-lib in my re-frame-app (https://github.com/graphhopper/directions-api-js-client/blob/master/src/GraphHopperOptimization.js). How do I resolve the js-deps in my re-frame project? Would you use npm for that? I guess I would have to disable advanced compilation then, right? Would you rather implement it yourself? (I am quite new and it would take me a while)
(good for you)
that sounds like something to try next - but with-redefs
as @ghadi mentioned is working great
Yeah with-redefs is fine for tests, I think if you were looking for a more general solution then protocols or multi methods are the way to go.
Major rework of my draft of a Clojure REPL guide for http://clojure.org. Feedback from beginners is still very welcome 🙂 https://clojureverse.org/t/feedback-wanted-draft-of-a-clojure-repl-guide-soon-to-be-submitted-on-clojure-org/1703
Hey guys, I have compojure-api project which I'm using the lein ring
plug in for developement. However, because of they way our paas is set up, I can't use lein ring uberjar
but only lein uberjar. So I had to include a main.clj in my source for lein uberjar. I'm having trouble having with the setup for the uberjar file to include the main.clj in the resources/production directory.
(defproject ss-prescribers-spi-api "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.9.0"]
[metosin/compojure-api "2.0.0-alpha18"]
[com.auth0/jwks-rsa "0.3.0"]
[com.auth0/java-jwt "3.3.0"]
[clj-time "0.14.2"]
[org.clojure/tools.logging "0.4.0"]
[clj-adapters "0.1.20-SNAPSHOT"]
[clj-fhir-lib "0.1.08-TEST-SNAPSHOT"]
[org.apache.logging.log4j/log4j-slf4j-impl "2.10.0"]
[org.apache.logging.log4j/log4j-api "2.10.0"]
[org.apache.logging.log4j/log4j-core "2.10.0"]
[jsonevent-layout "2.1-SNAPSHOT"]
[io.sentry/sentry-log4j2 "1.7.0"]
[slingshot "0.12.2"]]
:ring {:handler api.handler/app
:auto-reload? true}
:uberjar-name "server.jar"
:profiles {:dev {:dependencies [[javax.servlet/javax.servlet-api "3.1.0"]
[cheshire "5.8.0"]
[ring/ring-mock "0.3.2"]]}
:uberjar {:aot :all
:source-paths ["resources/production"]
:main main
:dependencies [[ring/ring-jetty-adapter "1.6.3"]]}}
:plugins [[lein-ring "0.12.0"]
[s3-wagon-private "1.1.2"]]
:repositories [])
I figured out my own issue I moved the main.clj file to another directory...it didn't like the resources directory
The interop would be pretty easy, but I'd suggest taking a look at the core rand-int
fn
great stuff @mfikes..ill stick with interop..want to make a simple clojure wrapper around the java.util.Random for the beloved community
@dazld what @russ767 suggested is a much better approach. Hide your interactions behind polymorphism, then pass around the implementations explicitly
yep, was just reading this: https://www.reddit.com/r/Clojure/comments/4wrjw5/withredefs_doesnt_play_well_with_coreasync/d6az4c9/
@dazld I ended up turning that into a blog post: http://blog.cognitect.com/blog/2016/9/15/works-on-my-machine-understanding-var-bindings-and-roots
Let’s assume I don’t entirely understand yet, but isn’t the race condition in the 2nd last paragraph that with-redefs
has gone out of scope by the time the future looks up the var, and that the root is reset to 42
? The text says reset to 0
.
Yeah, while I was in the middle of writing Getting Clojure I realized that I didn't actually understand how Vars worked and spent a couple of weeks figuring it out. I think that is a common experience even with folks who have been doing Clojure for a while. Of course @tbaldridge published that article about 5 minutes after I figured it out on my own. Thanks Tim!
Ok, added [cljsjs/chartjs "2.7.0-0"]]
dependency in project, required [cljsjs.chart]
. Then ran lein cljsbuild once
and I get this error inside the stacktrace:
Caused by: clojure.lang.ExceptionInfo: No such namespace: cljsjs.chart, could not locate cljsjs/chart.cljs, cljsjs/chart.cljc, or JavaScript source providing "cljsjs.chart" in file src/cljs/ppserver/views/device.cljs {:tag :cljs/analysis-error}
@russ767 do you cover vars in detail in your book? I spent a whole day just asking questions in clojurians and got a ton of helpful answers, but never feel like I got to the core of it 😞
The Joy of Clojure has a great chapter which covers all the reference types (atoms, agents, refs and vars), that chapter cleared up the confusion for me once and for all
@tkjone Chapters 8 and 9! 8 Covers vars, 9 covers namespaces.
@tacesofoca available memory and/or maximum length of a Java String.
(but if you slurp in a very large file you may not have enough memory left to actually process it)
My current project is grabbing some data out of a web service I've used, and cleaning/validating/classifying it. Later I intend to load it into Datomic to start doing experiments but for now I'm just saving it to flat files so it's hosted locally. I'm trying to decide how to handle some characters that, on the service, are rendered as "question mark in a diamond." I know this has to do with string encodings; it is messing up my pipeline somehow, but only for a dozenish records. Can someone point me at where I can learn enough to decide if it's worth caring vs just dropping a bit of data?