This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-25
Channels
- # announcements (4)
- # babashka (58)
- # beginners (21)
- # calva (42)
- # clj-kondo (15)
- # cljdoc (16)
- # cljs-dev (11)
- # clojure (57)
- # clojure-denmark (1)
- # clojure-europe (24)
- # clojure-france (4)
- # clojure-nl (1)
- # clojure-norway (16)
- # clojure-spec (6)
- # clojure-uk (2)
- # clojurescript (19)
- # clr (4)
- # conjure (1)
- # core-logic (3)
- # cursive (5)
- # data-science (2)
- # datascript (6)
- # datomic (3)
- # emacs (4)
- # events (3)
- # fulcro (17)
- # gratitude (2)
- # hyperfiddle (4)
- # introduce-yourself (3)
- # jobs-discuss (2)
- # lsp (27)
- # malli (22)
- # pathom (73)
- # portal (21)
- # re-frame (5)
- # releases (1)
- # vim (8)
- # xtdb (28)
Hi! I'm trying to get data from a database (PostgresSQL), and I getting back each row with a function, how I can receive only the value? my code: (def db {:dbtype "XXX" :dname "XXX" :host "XXX" :user "XXX" :port "XXX" :password "XXX"}) (def ds (jdbc/get-datasource db)) (jdbc/execute! ds ["select * from my-table"])) It return: {#my-table-name {key val, key val,..] {#my-table-name {key val, key val,..] {#my-table-name {key val, key val,..] .... ??
What jdbc lib are you using? If next.jdbc then perhaps you want one of the options from https://github.com/seancorfield/next-jdbc#usage
> you can specify {:builder-fn rs/as-arrays}
and produce a vector with column names followed by vectors of row values. rs/as-maps
is the default for :builder-fn
but there are also rs/as-unqualified-maps
and rs/as-unqualified-arrays
if you want unqualified :<column>
column names (and there are also lower-case variants of all of these).
I would strongly recommend you get used to qualified keys in maps -- they are idiomatic in Clojure.
user=> {:foo/bar 1 :foo/quux "two"}
#:foo{:bar 1, :quux "two"}
☝️:skin-tone-2: Not a function -- that's just shorthand notation for the hash map with qualified keysHow to flatten parent-child map?
I have:
[{"name" "father", "children" [{"name" "son", "children" [{"name" "grandson" "children []"}]]}}]
And I need flat structure like this:
[{"name" "father", "children" []}
{"name" "son", "children" []}
{"name" "grandson" "children []"}]
look at the tree-seq
function
https://clojuredocs.org/clojure.core/tree-seq#example-62780fc7e4b0b1e3652d75ea
that was exactly what I was looking for, thx. I probably missed the solution when I was reading it prev
Hey, everyone! Working on a kind of coding challenge where I implement sorting of a given vector of integers without using the built in sort. Thought I had a good thought going until I hit this roadblock! Here's my code first:
(defn loop-sort
[initial-coll]
(loop [remaining-coll initial-coll
final-coll []]
(if (empty? remaining-coll)
final-coll
(recur (rest remaining-coll) (into final-coll (vector (apply min remaining-coll)))))))
Running this with an input of [2 3 1 4 5] gives me an output of [1 1 1 1 5]. An input of [2 3 4 5 1 6 9 8 7] gives me an output of [1 1 1 1 1 6 7 7 7]. It's not obvious to me why exactly this is happening, but I expect it to be a problem stemming from using apply. What am I doing wrong here? Happy to answer any questions on anything unclear, as well!
Hello! This seems like a fun exercise 🙂 I think it would help if you considered the shape of what you’re passing into each step of your loop. One way to gain some insight is to use a println
in a version of your function at the repl. For example:
(defn loop-sort-with-println
[initial-coll]
(loop [remaining-coll initial-coll
final-coll []]
(println remaining-coll) ;; add this here, and run a small sample
(if (empty? remaining-coll)
final-coll
(recur (rest remaining-coll) (into final-coll (vector (apply min remaining-coll)))))))
your algorithm is to kick out the first item of remaining-coll (rest remaining-coll)
and add in the lowest element of remaining-coll
. Which means you choose one element and discard a random element, not the element you chose
so sorting [2 3 1 4 5]
:
• [1]
and [3 1 4 5]
• [1 1]
and [1 4 5]
• [1 1 1]
and [ 4 5]
etc
Oh, that makes sense now! Thanks!
Is http://clojuredocs.org the closest thing to Haskell's Hoogle? I want to know where to park my browser for when I need to find appropriate functions and libraries for the things I want to do.
and https://clojure.org/api/cheatsheet is pretty darn useful imo
awesome, thank you
I know your message was answered, but I thought I should share. I asked this previously in this same channel and got some responses.
Re-find will not help you find any 3rd party libraries. No fancy lookup-by-arguments or anything like that, but this will help for locating relevant libraries. https://phronmophobic.github.io/dewey/search.html