Fork me on GitHub
#clojure
<
2019-01-11
>
kwladyka11:01:23

((:close foo)) - how to write instead something like (-> (:close foo) ()). I want to make it more readable, but I confused myself 🙂

Michael Griffiths13:01:07

You could do

(let [{:keys [close]} foo]
  (close))

WhoNeedszZz20:01:31

Why complicate this? It's calling the function that is returned by the :close key. It's perfectly fine the way it is.

WhoNeedszZz20:01:03

Ah, nvm. Didn't see the text that followed.

kwladyka11:01:01

hmm or maybe ((:close foo)) is ok

kirill.salykin11:01:53

would this look more readable ? (invoke (:close foo))?

victorb11:01:25

@kwladyka maybe something like this?

(def foo {:bar #(println "nice")})
((-> foo (:bar)))

victorb11:01:52

I tend to not use -> unless it's more nested, one level usually just do ((:bar foo)) directly, but not sure that's idomatic

kwladyka11:01:03

well after rethinking ((:close foo)) is good

kwladyka11:01:52

It is more readable than I thought 🙂

burke12:01:04

hey all, I started using defmulti/defmethod. Is it intended that you can't use Destructuring with Keyword-arguments in defmethod?

jetzajac12:01:27

dispatch function (:type) is applied to three arguments. You should either rewrite youy dispatch function for it to be ready to accept vavarg or get rid of vararg and accept just one map

burke12:01:08

oh, didn't know that the dispatch-fn will be applied to every arg and not only the first.. Thanks. 👍 I'll use only one map

nwjsmith14:01:41

Clojure 1.10.0
user=> (take 2 [])
()
user=> (take-last 2 [])
nil
Is it likely that a patch would be accepted to modify take-last to return an empty seq when given an empty seq?

Alex Miller (Clojure team)15:01:21

in general, I would expect any code that uses the result of either of these to work in either case

Alex Miller (Clojure team)15:01:45

expectation for sequence functions should be that take something seqable and return something seqable

octahedrion15:01:56

with Spec, if I have (s/def my-map (s/keys :req [a b])) where a & b are (s/coll-of something), how can I say I want a & b to have the same length ?

octahedrion15:01:17

(not using :count - I don't care how long they are, only that they're the same length)

Alex Miller (Clojure team)15:01:12

write a function that checks that and s/and it to your spec

octahedrion16:01:54

@alexmiller much easier than I thought! thankyou

Alex Miller (Clojure team)16:01:56

you can pretty much write a predicate to check any arbitrary property of data and all predicates are specs

octahedrion16:01:05

it's a while since I used Spec, it's all coming back now

Lennart Buit17:01:43

Hijacking a question here, can you specify in an fspec what the side-effects of a function may be. That would basically entail doing something before the fn runs, and after.

Lennart Buit17:01:47

For example, I have a swap-vals! kinda thing for redis, I would very much like to assert that the first result you get is the state prior to the function being ran.

lilactown17:01:06

:thinking_face: :thinking_face: :thinking_face: well... nothing stops you from doing effects in your predicates

lilactown17:01:19

my first instinct is: oh god no

lilactown17:01:47

but, maybe fine? I wouldn't reach out to your redis instance each time the fn is called

Lennart Buit17:01:07

Right, its an obvious development-only kinda deal right

lilactown17:01:48

maybe you could have a custom instrumentation that swaps an atom with the before state, then compares in the :ret

Lennart Buit17:01:55

Its just that I don’t think you have a hook that is ran before the function is called

Lennart Buit17:01:23

(this is obviously more a code-golfing thing than actually useful, please don’t hate me)

borkdude18:01:17

How do I invite a bot to a channel that logs conversations to https://clojurians-log.clojureverse.org/

seancorfield18:01:38

Invite @logbot to your channel

fenton18:01:04

there is a web page somewhere that lists api's to third party clojure libraries...help?

seancorfield18:01:19

Also https://crossclj.info/ if you're searching for libraries to solve a specific task.

fenton19:01:23

Thanks Sean, I'll add that to my notes too 🙂!