clojure-europe

For people in Europe... or elsewhere... UGT https://indieweb.org/Universal_Greeting_Time
dominicm 2020-08-24T06:08:30.026600Z

Morning

synthomat 2020-08-24T06:52:14.026800Z

good morning!

ordnungswidrig 2020-08-24T06:56:12.027Z

Good morning!

2020-08-24T06:59:52.027200Z

morning

synthomat 2020-08-24T07:15:33.028200Z

(link leads to 404, but the preview works)

ordnungswidrig 2020-08-24T07:16:06.028600Z

Thanks, link fixed (again) ๐Ÿ™‚

synthomat 2020-08-24T07:17:43.029Z

haha she forgot to change the last dict to โ€œdictionaryโ€

ordnungswidrig 2020-08-24T07:19:08.029500Z

I always thought python was a dictionary based language. But this mean string keys, I guess

synthomat 2020-08-24T07:24:05.029900Z

is it about how dict() works?

plexus 2020-08-24T07:24:29.030500Z

morning!

synthomat 2020-08-24T07:24:50.030800Z

doesnโ€™t ** expand to method arguments, and using anything else than a string as a named parameter would fail anyway in python?

ordnungswidrig 2020-08-24T07:25:32.031500Z

I mean, in clojure we do (merge foo bar) without givin a single thought.

2020-08-24T07:26:01.032100Z

Morning

synthomat 2020-08-24T07:26:18.032400Z

oh yeah itโ€™s weird that python has so many ways of merging to dicts ๐Ÿ˜„ it makes me even wonder, that this post might get more attention than the manual

synthomat 2020-08-24T07:26:30.032700Z

because itโ€™s not documented well enough

jasonbell 2020-08-24T07:31:52.032900Z

Morning

2020-08-24T07:51:36.033500Z

Nice to talk about something other than elisp here ๐Ÿ˜‰

raymcdermott 2020-08-24T08:30:41.033700Z

morning

thomas 2020-08-24T09:37:51.033900Z

morning

dominicm 2020-08-24T09:54:46.034100Z

viml is pretty great

2020-08-24T10:16:05.034300Z

thx @dominicm

2020-08-24T13:25:20.034600Z

do you prefer by-key or by-reduce?

2020-08-24T13:25:29.034900Z

(def setting-groups [{:category 1 :name "foo"}
                       {:category 1 :name "bar"}
                       {:category 2 :name "baz"}
                       {:category 2 :name "quux"}])

  (def by-reduce (reduce
                  (fn [acc new]
                    (update acc (:category new)
                            (fnil conj #{}) (:name new)))
                  {}
                  setting-groups))

  (require '[net.cgrand.xforms :as x])

  (def by-key (into {}
                    (x/by-key :category
                              (comp (map :name)
                                    (x/into #{})))
                    setting-groups))

  (= by-reduce by-key)
  true

  by-key
  {1 #{"foo" "bar"},
   2 #{"baz" "quux"}}

2020-08-24T13:31:34.035200Z

you being everyone here ๐Ÿ˜‰

2020-08-24T13:32:04.035600Z

or what do you think the trade offs are and under what circumstances would you prefer one over another

2020-08-24T13:36:37.036700Z

I do a lot of things where I want to group by something (user id, date, other) and then want to process all the things in that group, so I like x/by-key but it melts my head occasionally so getting used to it with small examples helps me I think

dominicm 2020-08-24T13:49:23.038100Z

Both are equally opaque, but by-key has a docstring, tests and reuse, so I'd use that.

raymcdermott 2020-08-24T14:19:47.038900Z

I like by-reduce cos it's based on core functions so less to learn

raymcdermott 2020-08-24T14:20:26.039400Z

and that's not just cos I hate to learn ;-)

plexus 2020-08-24T14:53:32.040700Z

I think by-key is awesome, but I don't trust myself to remember how it works for more than a few weeks. It's a real mind-bender. So unless it's code that already heavily uses transducers and xforms I would probably prefer the reduce.

๐Ÿ‘ 1
dominicm 2020-08-24T15:12:13.041700Z

^ I like that caveat too. I'm assuming that you're using transducers and such elsewhere in your program and therefore further use of them is reduced confusion compared to custom solutions. It'd be like requiring ring and then re-implementing all the header parsing yourself ๐Ÿ˜„

2020-08-24T15:36:40.043800Z

Sorry, a bit unclear. I wouldn't create a new by-reduce function. I just as l wanted to show that the x/by-key and the reduce versions produce the same result

2020-08-24T15:38:02.046Z

I keep forgetting how by-key works, but do find it creates clearer code when I do remember how to use it, so I'm just wondering if I should use it more often to keep it fresh, or just use reduce most of the time

2020-08-24T15:38:40.047Z

The one big advantage is being able to put it in a transducer pipeline, and I do those a lot

2020-08-24T15:39:05.047700Z

And I'd presume it performs reasonably well with larger amounts of data