Morning
good morning!
Good morning!
morning
(link leads to 404, but the preview works)
Thanks, link fixed (again) ๐
haha she forgot to change the last dict
to โdictionaryโ
I always thought python was a dictionary based language. But this mean string keys, I guess
is it about how dict()
works?
morning!
doesnโt **
expand to method arguments, and using anything else than a string as a named parameter would fail anyway in python?
I mean, in clojure we do (merge foo bar)
without givin a single thought.
Morning
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
because itโs not documented well enough
Morning
Nice to talk about something other than elisp here ๐
morning
morning
viml is pretty great
thx @dominicm
do you prefer by-key or by-reduce?
(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"}}
you being everyone here ๐
or what do you think the trade offs are and under what circumstances would you prefer one over another
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
Both are equally opaque, but by-key has a docstring, tests and reuse, so I'd use that.
I like by-reduce
cos it's based on core functions so less to learn
and that's not just cos I hate to learn ;-)
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.
^ 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 ๐
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
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
The one big advantage is being able to put it in a transducer pipeline, and I do those a lot
And I'd presume it performs reasonably well with larger amounts of data