Fork me on GitHub
Rachel Westmacott07:08:33

loving yesterday’s history lesson 🧡


@peterwestmacott I always feel the remarkable thing is when we actually talk about clojure on this channel. 😉

Rachel Westmacott07:08:08

this morning I want to talk theatre!

Rachel Westmacott07:08:09

And I’m super excited about it! But obviously we can talk Clojure too!


plays sound better


what is it like directing a play?

Rachel Westmacott07:08:31

@otfrom variable. Depends hugely on the cast.

Rachel Westmacott07:08:45

In this case, lots of fun. It's a smallish cast, and they're all excellent, so we can really sink our teeth into the text.

Rachel Westmacott07:08:21

At least half the battle is getting the right people to audition in the first place.




@dominicm I feel like I need to say - you know our partial vs anon fn conversation of a few weeks ago? I was doing some data structure wrangling at the weekend, reached for a partial, decided to do it your way, and it's actually probably more readable, so fair play 😉


turns out I may have been doing it wrong for oh, years lol


@alex.lynham It's good to hear my experience can be replicated 🙂


Sometimes I worry I live in too much of a bubble.


I think if I'm comping then maybe I'd still use partial


but for shifting the argument order in a thread, just defining an anon (and then refactoring if it's useful elsewhere) is actually super readable


good shout 👍


what was the upshot of the conversation? (I missed it) When to use (fn ...) and (partial...)?


@otfrom tl;dr never use partial, always use #() or (fn)


Morning 🙂 Is there a way to "unwrap" an instance of a java numeric type (e.g. java.lang.Double) when the numeric type might be a variety of different things (but guaranteed to be number?).


@cddr I don't know what unwrap means here?


Oh. get the primitive number


Aww... I like partial in some instances, esp when doing higher order functions that have lookups and other things passed in


yep 100% ... I think I'm won over in the case of threading (i.e. not using partial to shift argument order) but there are cases I'll still use it


yeah, I tend to avoid it in threading as well, but I like it in a map/filter/etc


@cddr I suspect you're into rolling your own function here, I've not encountered this.


@otfrom it's not as readable though, because the call interface isn't very well defined.


If it extends java.lang.Number it should have shortValue(), intValue() etc. methods available, I think


@conor.p.farrell I'm guessing that he wants to use the one appropriate for each type, automatically.


Yeah background is I'm trying to pass a value returned from one API that returns an object, to the other which has a method overload for each supported primitive type.

Rachel Westmacott08:08:03

I think you’ll need a code path for each primitive type you’re using. Even if it’s just a branch in a cond or something.

👍 4

Having to care about the data type (to me) usually means something is slightly wrong

Rachel Westmacott08:08:57

something is slightly wrong

Rachel Westmacott08:08:16

but in my opinion, it’s the scar across the Java language that is primitives vs. objects


The past cannot be changed, I've learned this from many science fiction stories

Rachel Westmacott08:08:56

many Java APIs have one method for objects and eight almost identical methods for primitives

Rachel Westmacott08:08:31

you could hide it a bit with a multimethod or something but I’m not sure that’s any better than an obvious / explicit branch

Rachel Westmacott08:08:00

if something is slightly wrong it’s usually better to make subsequent maintainers aware of it I feel



🌊 4

I've not been contributing much because I've been wading through season 3 of Twin Peaks.

❤️ 8

did you make it through it yet?


ep 10, ep 8 was the best bit of television I've seen in a long time.


and you still got 8 episodes to go, you're in for a treat :)


it just keeps getting better


oh god twin peaks 3


that reminds me I still have fwwm to watch


Regarding the question above... here's what I ended up with. Also replaces +-inf with +-max-value because I've seen influxdb (the eventual target) choke on infinity before.

(defn bridged-metric
  "Bridges the kafka metric API with the dropwizard API by taking the supplied `kafka-metric`
   and returning an object that satisfies both interfaces. This allows the underlying
   kafka metrics to participate in dropwizard's registry.

   The additional information provided in the `MetricName` is thus made available to the
   reporter for event tagging purposes"
  (let [metric-name (.metricName kafka-metric)
        value (fn [x]
                (let [-inf? (fn [n]
                              (= n (Float/NEGATIVE_INFINITY)))
                      +inf? (fn [n]
                              (= n (Float/POSITIVE_INFINITY)))]
                  (condp instance? x
                    Integer  (.intValue x)
                    Double   (cond
                               (-inf? x) (Double/NEGATIVE_INFINITY)
                               (+inf? x) (Double/POSITIVE_INFINITY)
                               :else (.doubleValue x))
                    Float    (cond
                               (-inf? x) (Float/MIN_VALUE)
                               (+inf? x) (Float/MAX_VALUE)
                               :else (.floatValue x)))))]
      (metricName [this]
        (.metricName kafka-metric))

      (metricValue [this]
        (value (.metricValue kafka-metric)))

      (getValue [this]
        (value (.metricValue kafka-metric))))))

Rachel Westmacott07:08:18

Does the -inf function defined with Float/NEGATIVE_INFINITY work for doubles? (it looks a bit odd, but I genuinely don’t know)