Welcome! Please see the About page for a little more info on how this works.

0 votes
in Spec by

Sometimes it may help a lot if you can quickly check the shape of the local data, after series of transformations for example.

Is it possible?

And is it possible to spec (some) steps of thread-first/thread-last for instance?

As a random idea, something like this?

(->> xs
     ^:xs (map ...) ;; <- attaching spec for output via tag
      (filter ...)
      (remove ...)

2 Answers

0 votes
by
selected by
 
Best answer

No, this is not possible in the way you describe right now. It would however be possible to use a function that took a spec and a value, checked the value for spec compliance and either threw an exception or returned, then put that in your ->> chain as just another threaded fn.

A new macro could probably use metadata in the way you describe to accomplish something similar though.

0 votes
by

Not an answer, but just a rather unimaginative comment... I like the algebraic nature of the threading macros. I shuffle forms into and out of threading macros as I decide how to make their intent and effect most clear. Pegging any other behavior to the threading macro would introduce a complication. Because I can conform a thing to a spec any place, any time, but in fact I usually don't unless I am purposely troubleshooting, I would rather insert a step in the threading form to do it, in such a way that the behavior would be the same if I unrolled (expanded) the macro.

by
The intention is more to describe what shape of data is, not to conform.
...