This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-18
Channels
- # aws (1)
- # aws-lambda (1)
- # beginners (48)
- # boot (15)
- # cider (3)
- # cljs-dev (4)
- # cljsrn (4)
- # clojure (241)
- # clojure-chicago (1)
- # clojure-dusseldorf (12)
- # clojure-greece (41)
- # clojure-italy (3)
- # clojure-russia (16)
- # clojure-spec (7)
- # clojure-uk (34)
- # clojurescript (88)
- # community-development (9)
- # cursive (8)
- # data-science (55)
- # datomic (40)
- # devops (1)
- # emacs (20)
- # fulcro (19)
- # graphql (3)
- # hoplon (46)
- # luminus (11)
- # lumo (4)
- # off-topic (27)
- # onyx (26)
- # other-languages (25)
- # pedestal (2)
- # powderkeg (6)
- # re-frame (11)
- # reagent (4)
- # ring-swagger (17)
- # rum (4)
- # shadow-cljs (103)
- # spacemacs (14)
- # specter (6)
- # unrepl (21)
- # yada (1)
mornings
@jonpither emacs every day
does anyone know a neat way to apply <
, >
, min
, max
to things that aren’t numbers, but could maybe be java Comparable
?
i've done a reduce
with a comparator fn in such circumstances @peterwestmacott - no neat trick though
I wanted to say eg. (< offset-date-time-1 offset-date-time-2)
yeah compare
is a good default comparator
(sort > [4 5 6])
there's definitely something going on with this. I think clojure functions implement the Comparator interface.
yes i think they do @dominicm - you can use any old 2-arg clojure-fn iirc
there’s min-key
which is quite nice
eg: (sort (OffsetDateTime/timeLineOrder) [(OffsetDateTime/now) (.minusSeconds (OffsetDateTime/now) 15)])
?
apart from it being long and ugly, I’m mostly checking if dates are before/after each other, rather than needing to sort a lot of them so it would likely be more performant to call .isBefore
I just wondered if there was a more general solution (either for all things, or more likely things that are already Comparable), but it sounds like I should just compose core lib fns or get specific
I think core has avoided have multimethods/interfaces for these things for performance reasons. But don't quote me on that.
@dominicm that sounds likely re: performance
really ? protocols boil down to java interfaces don't they and are fast - is it not just hysterical raisins ?
In the past I have experienced order of magnitude speed-ups by replacing collections of objects in Java with arrays of primitives. While Java interfaces may be ‘fast’ I suspect that numerical calculations have requirements that are a step beyond what other operations require. Being performant for intensive numerical work has fundamental implications for what your language can be practically used for.
right, yeah, arrays of primitives are often worth special-casing...
(where just ~ ∞)
‘just’ is my favourite dangerous word