Fork me on GitHub
#clojure-europe
<
2022-08-14
>
genRaiy09:08:15

A mighty good morning

😮 3
👌 2
pavlosmelissinos12:08:39

Good afternoon!

😮 3
😍 4
genRaiy18:08:50

just doing this the other day and thought that this is where Java interop shines ... no mutability escapes the expression. Does this pattern of usage have a name?

vemv13:08:40

almost sure the JCIP book gives it a name, I don't have it at hand though

vemv14:08:00

thread confinement

genRaiy20:08:56

Using the threading macro for extra pwnage 😂

genRaiy18:08:00

(-> (doto (Signature/getInstance (if (string? algorithm) algorithm (name algorithm)))
      (.initVerify public-key)
      (.update data-bytes))
    (.verify signature))

slipset06:08:22

Beside the point, but I believe you can safely call name on a string, so you can get rid of the if expression

1
genRaiy18:08:21

or this ... I weep when I compare the simplicity of this to the Builder Pattern

genRaiy18:08:50

(let [data (.getBytes (pr-str edn-data-to-sign) "UTF-8")]
    {:signature (-> (doto (Signature/getInstance "SHA256withECDSA" BouncyCastleProvider/PROVIDER_NAME)
                      (.initSign private-key)
                      (.update data))
                    (.sign))})

1
borkdude19:08:49

I think this pattern is called doto :)

genRaiy20:08:46

well, it has a thread too ( you really should learn how to read Clojure code and not rely so much on tools 😛 ) .... so that would be too minimal... thread-doto seems very German.

genRaiy20:08:42

make object -> get result

borkdude21:08:12

Yes. The Clojure syntax/macros are very useful even when not dealing with FP/immutable stuff.

borkdude21:08:10

I find (doto long-expression prn) also useful for debugging

💯 2