Fork me on GitHub
#clojure
<
2018-10-01
>
emccue01:10:32

is this still relevant

the2bears02:10:02

@emccue I'd say that's still good advice in general to follow.

emccue02:10:28

Its wierd, because the mailing list had a solution

emccue02:10:42

i wonder why the patch wasnt accepted

andy.fingerhut06:10:01

The author may not have ever created a ticket in Clojure's JIRA tracker. Even if they did, that is no guarantee a suggested enhancement is even considered.

andy.fingerhut06:10:46

Probably just fell off the radar, if it was ever on the radar.

henrik07:10:45

This brings to mind RBBs again, and why it might be preferable to have data structures with fairly consistent performance across operations, even though theyโ€™re not faster in each individual case. https://github.com/clojure/core.rrb-vector

angrygami08:10:49

@crankyadmin (take 10 (cycle [1 2 3 4 5]))

angrygami09:10:11

Hello, I've found this:

user=> (pr-str {:user/aaa 1})
"#:user{:aaa 1}"
user=> (pr-str {:a 1 :user/aaa 1})
"{:a 1, :user/aaa 1}"
Is this some kind of bug?

mpenet09:10:00

no it's by design

mpenet09:10:46

there are a few rules, like all the keys in the map must be the same namespace

mpenet09:10:54

it's described on jira somewhere

mpenet09:10:20

> Maps will be printed in namespaced map form only when: > All map keys are keywords or symbols > All map keys are namespaced > All map keys have the same namespace

mpenet09:10:17

just learned about _

mpenet09:10:47

#:user{:_/a 1, :aaa 1, :bbb 2} -> {:a 1, :user/aaa 1, :user/bbb 2}

mpenet09:10:07

it's a bit weird heh

angrygami09:10:12

Ok, I see now. Thanks

mpenet09:10:05

makes me wonder: why not doing the same for sets: #:foo#{:a :b :c} (edit: actually it's mentioned in the jira)

angrygami09:10:31

"Added in Clojure 1.9" ๐Ÿ™‚ didn't expect that would need to review such basic stuff

mpenet09:10:32

I guess if you go down that rabbit hole that could become quite ugly

mpenet09:10:02

the syntax kinda collides

angrygami09:10:19

but this is neat feature non the less

mpenet09:10:36

yeah, I personally like ns'ed keywords a lot

Andreas Liljeqvist10:10:36

is there a function like the #:ns macro? - Something like (ns-map {:db/id 25 :attr 8} :myns.entity)

Andreas Liljeqvist10:10:50

#:myns.entity{:db/id :attr 8}

urzds10:10:22

Can someone recommend a way to reload a Clojure (server / backend) application when a source file changes?

urzds10:10:20

I'm currently doing it through the REPL with clojure.tools.namespace.repl/refresh, but maybe there is some more common way.

angrygami11:10:16

@andreas862 (reduce (fn [a [k v]] (assoc a (if-not (namespace k) (keyword "myns.entity" (name k)) k) v)) {} {:ccc 321 :aa 123})

urzds11:10:26

@lukas.rychtecky Thx!

lukas.rychtecky11:10:35

If you build new Clojure backend service from scratch, consider using https://github.com/duct-framework/duct a lot of handy stuff a la carte.

urzds11:10:51

thx again ๐Ÿ™‚

kenran_12:10:26

I am having trouble generating "recursive" data structures defined with clojure.spec.alpha. I found the issue https://dev.clojure.org/jira/browse/CLJ-1978?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#issue-tabs where I also posted this, but I'm not quite sure if that was the right place or if I should open a new issue for this. The first example in the original post works fine for me as well. This seems to have something to do with the s/spec call, since without that I can create such recursive maps just fine and with very high depth. Am I doing something wrong here? And if not, should I maybe open a new issue for this?

urzds13:10:38

In SQL Korma, does (create-db config) have a "delete" counterpart that I can use to destroy the connection pool?

urzds14:10:26

In addition, I do not see how I can define entities (tables) if the database connection is not yet available, e.g. because I will create it dynamically later.

lsund15:10:17

Hi there I have a programmatic issue that you guys maybe could help with: I have a sequence of maps

{:key "foo", :version 1}, {:key "foo" :version 2}, {:key "foo" :version 3}, {:key "bar" :version 1}, {:key "bar" version 2} 
and I would like to reduce this to all unique maps with the highest versions. In the example the correct result would be
{:key "foo" :version 3}{:key "bar" version 2} 
My problem is that I cannot find a function that takes a collection and removes duplicates (depending on a predicate that i specify). The only such function I know of in clojure is set, but this just compares by value. In my example, it would be necessary to first sort by :version and then remove duplicates by :key. In haskell I did something like
let sorted = sortBy (\x y -> _version y `compare` _version x) maps                                                                                                                  
nubBy (\x y -> _key x == _key y) sorted
hope someone that knows can help1

jthibaudeau15:10:46

If your version is going to be a number then you could use

(apply max-key :version coll)
where coll is your sequence of maps

jthibaudeau15:10:35

that would give you the highest version but maybe not exactly what you need

jaawerth15:10:12

@lsund You could write a variant on the distinct core transducer function (call it distinct-by) that takes a predicate. See (source distinct) for more info on how to do it, but it shouldn't be too bad

bbrinck15:10:26

distinct-by is a fairly common util function that is added to many libs, so thereโ€™s quite a bit of reference code ๐Ÿ™‚ https://crossclj.info/clojure/distinct-by.html

bbrinck15:10:01

(even in cljs.util ๐Ÿ™‚ )

jaawerth15:10:06

yeah I'm a bit surprised there isn't one in core

Jan K15:10:07

just reduce the collection into a hash-map with the appropriate key, then use the vals

lsund15:10:32

Looks good! thanks

lsund15:10:29

I really appreciate it!

jaawerth16:10:03

Personally I like to write them following the same pattern as the core library's transducers, so you can use them as a stateful transducer in a composed pipeline or as a method that returns a lazy-seq based on the arity you pass

angrygami16:10:38

@lsund

(->> [{:key "foo", :version 1} {:key "foo" :version 2}, {:key "foo" :version 3} {:key "bar" :version 1}, {:key "bar" :version 2}]
     (reduce (fn [a {:keys [key version] :as o}]
               (update a key (fn [{v :version}] (if (and v (< version v)) v o)))) {})
     (vals))