driech here today
GOd morgen
morning!
So in some talk or another Rich says that sets are undervalued and underutilized data structures, and I see from our code that in many places where we could have used sets, we end up using lists or vectors.
Much because map/filter et al don't preserve the type of the input collections.
But I have a feeling that that adding maps
and filters
would probably be the wrong approach and that this should rather be handled with transducers in some way? Thoughts?
Btw this one is rather nice:
user=> (disj #{"foo" "bar" "baz" nil} nil)
#{"foo" "bar" "baz"}
user=>
compared to
user=> (filter identity ["foo" "bar" "baz" nil])
("foo" "bar" "baz")
or
user=> (remove nil? ["foo" "bar" "baz" nil])
("foo" "bar" "baz")
user=>
morning
morning
@slipset interesting. I've noticed lately that I'm only really using filter/map/etc in the context of transducers so I'm usually preserving the type of the collection by doing into or transduce with a collection type (same w/reduce)
so I've not had that problem
I love sets and use them for deduplication and as predicates quite a lot
(into #{} (filter identity) [:foo :bar :baz nil])
I frequently have things like
(if (#{:foo :bar} (:my-key my-map)) do-this do-that)
Yeah, I love the fact that sets and maps acts as fns.
One could choose to get annoyed by the fact that keys
doesn't return a set
yeah, keys should return a set (as they are unique by contract)
(fnil conj [])
seen and used before 🙂
This use of transducers is a bit interesting:
Any reason for that instead of
(->> (get tagged-episode ::edit) (map ::command) (into #{}))
Since you're not composing the transducer?
Morning
@slipset not a good one other than consistency and every time I end up having a single thing in my trasnducer pipeline the universe laughs and says "ha! you need another"
when I write them I tend to do the following:
(into #{}
my-coll)
and then put the transducing functions in the middle as I work through itI used to write my ->>
like this
(->> my-coll
)
so moving from thread last to into wasn't a big shift for me really
most of the things about transducers go on about the internals and are a bit light on the using, which wasn't too hard once I grokked how to go from one to another
@slipset literally comping in another xf into an into as I need to filter some things out before I do a sort. 😉
Good afternoon
good day to you sir!
What an honor!
What are the most useful Java classes to use reify
with in your opinion?
clojure.lang.IReduceInit
?
is that cheating?
java.util.Iterator
and java.util.Iterable
are also big favourites
All of them
I doubt you could get a non biased answer. Maybe try a github search or something.
@dominicm I already analyzed a bunch of code: https://github.com/borkdude/analyze-reify
Ah, so deref then :)