Fork me on GitHub
#clojure
<
2021-08-07
>
isak00:08:56

Not really what you are asking for, but it reminds me of http://pedestal.io/api/pedestal.log/io.pedestal.log.html#var-spy from pedestal.log, which is quite useful

potetm00:08:16

clojure.tools.logging also has a spy

ghadi00:08:54

Why spy/print when you can tap> ?

💯 12
ghadi00:08:20

With tap you still retain the ability to print later, yet it opens up so much more possibilities

6
💯 3
seancorfield00:08:16

loves tap>

3
isak00:08:21

Tap is cool, changes the return value though

3
potetm00:08:50

clojure has a built-in async queue with a dropping buffer

potetm00:08:09

It’s (always?) used for debugging.

seancorfield00:08:36

@isak (doto x tap>) -- works really well in threading too (-> x (f1) (doto tap>) (f2 :a) (doto tap>) (f3))

3
👍 6
potetm00:08:36

lmao I have never in my life considered using doto with not-a-java-object

seancorfield00:08:25

I don't remember where I first saw that suggestion but I used to use it with println in threading pipelines prior to tap> appearing.

potetm00:08:01

yeah looks like a really good, general purpose spy replacement imo

potetm00:08:36

You can add handlers via add-tap and then drop things on the queue with tap>

seancorfield00:08:30

I use it all the time for debugging. I have Reveal as a tap> "listener" so when I run code I see all the values show up in Reveal and I can browse them structurally.

seancorfield00:08:40

My RDD videos show tap> in action

isak00:08:38

For tap if you are using cursive, something that makes it work pretty well in development:

(require '[puget.printer])
  (let [print-taps-fn
        (fn [x]
          (puget.printer/with-options
            {:width 40 :map-coll-separator :line}
            (puget.printer/cprint x)))]
    (add-tap print-taps-fn))

noisesmith15:08:54

my only issue here is add-tap on a local means you have no handle to call remove-tap on

isak15:08:26

true, but I'm just evaluating it once when starting the program in development mode, so it hasn't been a problem for me

noisesmith15:08:10

ahh, I use tap> in a repl and often add/remove functions

2
isak00:08:31

Hmm might still work

devn01:08:33

@deleted-user tap is like Ruby’s tap, if that helps at all

devn01:08:37

im coming in late!

devn01:08:14

i guess i just meant to underscore it is used in practice an awful lot like a .tap in rubyland

devn01:08:00

also, hi @ghadi 😄

devn01:08:09

i need to hang in here more often :X

devn01:08:56

oh cool, like embedded lucene or something?

devn01:08:20

oh, like the web interface, nvm

devn01:08:42

can i search for +?

devn01:08:46

or am i misunderstanding?

devn01:08:02

oh gosh, this is next.jdbc docs

devn01:08:37

yeah i had to do some stuff for getclojure (which is still down :X) to tokenize myself

devn01:08:59

but it might get you most of the way

devn01:08:10

this is from 2013, and i have barely any recollection as to how it worked

devn01:08:29

i think there was something funky about elasticsearch where certain chars would be treated like special chars within the query

devn01:08:49

so i had to make search dumber to make it better or something

devn01:08:07

rad you’re working on making cljdoc better. doc projects are fun and communal good

devn01:08:27

much appreciated ❤️

💜 5
devn01:08:47

the more the merrier

indy11:08:27

I’m guessing text-decoration.core. There is a refer all from that ns.

Drew Verlee11:08:00

yep. makes sense.

dabrazhe13:08:50

What's the best way to figure out a shape of a nested data structure? Ie, the outline of the shape with empty structures, eg

'([{{}{}}][{{}}]) etc.

vemv15:08:16

nice q, I gave it a shot:

(->> [[[1 {2 2}] {3 []}]]
     (walk/postwalk (fn [x]
                      (cond
                        (not (coll? x))
                        x

                        (map-entry? x)
                        x

                        (map? x)
                        {}

                        true
                        (into (empty coll)
                              (remove (complement coll?))
                              x)))))
it doesn't go deep into maps b/c I don't have it clear what to do for an input like {1 []} . If you remove the 1, you'd get an invalid map entry

Drew Verlee18:08:11

The best way depends on the context. I use clojure fns at the repl to explore clojure data.

tessocog19:08:20

was wondering about a function that takes instances of a data structure and returns a valid spec for it

tessocog19:08:13

[data samples] -> Spec

tessocog19:08:22

perhaps it could be applied to itself too if future versions of spec look more like data ([data samples] -> Spec) -> Spec

Drew Verlee20:08:20

> was wondering about a function that takes instances of a data structure and returns a valid spec for it (edited) Such things exist, but they likely won't help you in a real application with so much going on. Your best bet is that a) there are tests b) you can repl in at the point of inspection c) visibility tools like tap or spy

Drew Verlee20:08:50

d) there are specs

dabrazhe21:08:32

The background of my question is that the nested structure I'm getting from an api is way too long (thousands of records) to explore in repl. Moreover I'd be useful to check the right shape as one of the test cases. @U45T93RA6 snippet is interesting to explore further

Drew Verlee21:08:38

thanks for explaining. There are also tools like revel or ciders inspect which will pretty print data and let you explore it. but i just wanted to give an overview. I usually end up using mix of everything all at once.

vemv21:08:59

mandatory link to https://github.com/stathissideris/spec-provider cheers :)

🎉 4
😃 4
✔️ 6