在Clojure中的广义线程宏 [英] Generalized Threading Macro in Clojure
问题描述
注意:这不是关于并发。这是关于线程宏。
Note: this is NOT about concurrency. This is about the thread macro.
我知道 - >
将对象放在第二个位置, code> - >> 将参数放在最后一个位置。
I know that ->
puts the object at the 2nd position and ->>
puts the argument at the last position.
现在,我很好奇,函数的#(...%)
的短手符号,是否有一个简短的符号,让我把参数放在任意位置?
Now, I'm curious, much like the short hand notation of #( ... % )
for functions, is there a short hand notation for threads that lets me place the argument at arbitrary location?
目标是,而不是让线程运行的固定位置...我可以写任意形式,并在特殊位置插入%% ,并且%%是线程插入的位置。
The goal would be that instead of having a fixed location for the thread to run through ... I can write arbitrary forms, and insert %% at special places, and the %% is where the thread gets inserted.
谢谢!
推荐答案
Swiss Arrows 图书馆的钻石棒可以满足您的要求:
The 'diamond wand' from Swiss Arrows library would do what you're asking for:
(-<> 0
(* <> 5)
(vector 1 2 <> 3 4))
; => [1 2 0 3 4]
也就是说,这不是你最终需要的东西或 )
That said, it isn't something you end up needing often (or ever in my Clojure experience)
这篇关于在Clojure中的广义线程宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!