This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-30
Channels
- # babashka (46)
- # beginners (234)
- # bristol-clojurians (4)
- # cider (7)
- # clj-kondo (39)
- # cljdoc (8)
- # cljs-dev (10)
- # cljsjs (10)
- # cljsrn (24)
- # clojure (84)
- # clojure-brasil (7)
- # clojure-europe (12)
- # clojure-germany (4)
- # clojure-italy (3)
- # clojure-nl (41)
- # clojure-spec (17)
- # clojure-uk (66)
- # clojurescript (64)
- # conjure (161)
- # cursive (12)
- # data-science (45)
- # datomic (20)
- # devops (11)
- # docker (2)
- # duct (9)
- # events (7)
- # figwheel (1)
- # figwheel-main (20)
- # fulcro (32)
- # graalvm (5)
- # helix (82)
- # jackdaw (9)
- # jobs-discuss (19)
- # kaocha (11)
- # local-first-clojure (1)
- # malli (6)
- # meander (3)
- # nrepl (12)
- # off-topic (2)
- # other-lisps (15)
- # pathom (14)
- # rdf (6)
- # re-frame (8)
- # reactive (1)
- # reagent (5)
- # reitit (4)
- # rum (3)
- # shadow-cljs (77)
- # spacemacs (3)
- # sql (9)
- # test-check (31)
- # tools-deps (13)
- # vim (62)
- # xtdb (18)
hey yall, lil help? i think im missing something obvious here:
(defn response-for [& args]
(log/info (apply io.pedestal.test/response-for args)))
;; fails with
Syntax error macroexpanding log/info at (example.clj:20:3).
No value supplied for key: (apply io.pedestal.test/response-for args)
"no value supplied for key" means that log/info uses keys destructuring, so it always needs an even number of args
which log lib is that?
keys destructuring is much less popular these days, so you run into it less often
oh, right, yes I mean keys of rest sequences, not keys generally,
but yea, adding the :msg
solved it, thanks @noisesmith
Getting a bunch of Unknown symbol
errors with clojure-lsp. Is this the right channel to ask about it?
@tim.smart just a guess but you might get answers sooner at editor-specific channels, e.g. #emacs or #vim or other
Hello everybody. I have a map, witch i need to check if the value of one key contains the value of i need.
{:name :test-table :col-specs {(contains {:id anything})} :extra-specs nil}
No success with this approach. Any insight?
what is the consumer of that hash map? also, I'd expect something like {:id (contains anything)}
because the current nested map isn't valid
This is a test that i'm adapting. Previously it receive multiple arguments and now i'm adopting a config map instead so i won't need change arity again
is the map literal above a pseudo-code?
Let me show you the test
(create-table-sql ..db.. :test-table (as-checker (contains {:id anything}))
That was before i change the arityso I wold turn that into {:name :test-table :col-specs [(as-checker (contains {:id anything}))]}
Il'l Check that . thanks
has anyone been using luminus with the +graphql profile? If so, can you direct me to how to actually test it out ? Looking over the code, I see a /graphql
route, but no mention of GraphiQL. Connecting to localhost:3000/graphsql
via GraphiQL (as a separate electron app), nothing seems to happen. No errors, but also no editor suggestions.
Admittedly I have no experience with GraphQL so that doesnât make things easier. If anyone knows of talks given, preferably where example code is also made available, that would be great.
(FWIW, Luminus uses Walmartâs Lacinia)
https://lacinia.readthedocs.io/en/latest/tutorial/pedestal.html?highlight=graphiql#id6
(lp/service-map {:graphiql true})
lp = com.walmartlabs.lacinia.pedestal
you need to enable it by passing the config above
Sorry I posted my work link LOL
it should work now
Yup. I see it đ It also seems like a good place to start is the lacinia tutorial on this page
Yes, the tutorial is fantastic! Highly recommended. If you are looking for a client library then I would suggest looking at re-graph library - https://github.com/oliyh/re-graph
Cool đ Will definitely keep in mind. A bit rusty on clojure, but Iâll manage. The major new thing is GraphQL, possibly getting the tooling stuff working (ClojureScript was somewhat temperamental at times when I last did Clojure). But the combined solution seems awesome
Is there a clojure function to search through a seq or vec with a predicate and return the first result that matches without processing the rest? In JS it would be like the .find array method.
(->> my-list (filter my-pred) (first))
Is close but even if a match is found, it will keep searching the rest of the list.I use the following idiom:
(some (fn [x] (when (pred x) x)) xs)
(->> my-list (filter my-pred) (first))
will not keep searching the rest of the list. filter returns a lazy sequence
some
is what you're looking for, but
> even if a match is found, it will keep searching the rest of the list.
Just that rest of that chunk, since filter
is lazy
user=> (first (filter #(do (println %) (= 5 %)) (range 10)))
0
1
2
3
4
5
6
7
8
9
5
user=>
user=> (first (filter #(do (println %) (= 5 %)) (range 100)))
0
1
2
3
4
5
6
...
26
27
28
29
30
31
5
user=>
usually up to 32 elements.this version prints once, and is efficient, you'd want to wrap it in something much less weird looking though
(transduce (filter (fn [x]
(println x)
(even? x)))
(completing (fn [acc el]
(reduced el)))
:invalid
(range 100))
maybe better?
(eduction (comp (filter (fn [x]
(println x)
(even? x)))
(take 1))
(range 100))
of course you'd put it in a function where you plug in the fn and the coll (and maybe call first on the result too), because in my experience collaborators go to a dark place when they see things like eduction
Although on one hand, I'm working with a list < 32 items long on the other filter feels like the wrong tool for the job.
(some #(do (println %) (= 5 %)) [1 2 3 4 5 6 7 8 9 10])
1
2
3
4
5
It looks like some doesn't go through all the items once it finds a matchoh, I thought some returned a boolean instead of your item
maybe that's OK in your domain, if so I missed that
đ
(loop [xs (range 100)]
(if (and (first xs) (even? (first xs)))
(first xs)
(recur (rest xs))))
At this point I'm just considering options. Personally I think that eduction very explicitly describes the intended behavior.
(defn find-first
[f xs]
(->> xs
(reduce #(if (f %2) (reduced %2) %1) nil)))
(find-first #(do (println %) (= % 5)) [1 2 3 4 5 6 7 8 9 10])
=>
1
2
3
4
5
5
Another option leveraging reducedreduce shares the property with eduction of utilizing the fast iteration path for supporting collections
(defn find-first
([f xs]
(find-first f nil xs))
([f not-found xs]
(->> xs
(reduce #(if (f %2) (reduced %2) %1) not-found))))
This one can take an optional not-found value. I'll run this and the eduction solution by my coworkers and see which one they think will be more useful\maintainable.also that function could be #(when (f %2) (reduced %2))
but that doesn't respect your not-found
Can JVM profilers show Clojure locals? (IIRC, the Cursive and CIDER debuggers do. I'm simply gathering knowledge about profilers) ...If that helps I use Yourkit. I feel that I'm always missing out on some of its features đ
clojure does something called "locals clearing" to prevent massive heap usage with lazy-seqs, and there's a compiler option to turn that off so debuggers can see your locals
the local values are intentionally deleted otherwise, so there's nothing for the debugger to find
Yes, I know about the flag Now I wonder where to actually see these locals in a specific profiler's UI
oh, carry on
Why does Clojure re-create a map in map destructuring if it's already a map -- EDIT: missed the question mark, never mind.
user=> (macroexpand '(let [{:keys [:a :b]} {:a 1 :b 2}]))
(let* [map__142 {:a 1, :b 2} map__142 (if (clojure.core/seq? map__142) (clojure.lang.PersistentHashMap/create (clojure.core/seq map__142)) map__142) a (clojure.core/get map__142 :a) b (clojure.core/get map__142 :b)])
Would something break if there was an (if (map? map__142) map__142 ...)
there?varargs keys destructuring in function arg lists?
that's the big one I can think of
oh! you mean the optimization to just use the map if it is one
*me hasn't been getting enough sleep
Pretty sure not since there's no a JVM-powered formatter that vertically aligns things No formatter -> no linter :)
One could toy with Emacs in batch mode if you really consider it worth the effort. IMO emacs isn't exactly the best canonical formatter (the best being a mixture of cljfmt, cider and hand-tuned things)
i.e. if our team decides to pick one style or another (see https://github.com/bbatsov/clojure-style-guide/issues/10), is there an existing linter that will detect the âwrongâ style?