Add tail threading (->>)
This commit is contained in:
parent
546e7ff50b
commit
bfc71e4a60
@ -94,6 +94,20 @@ def threading_macro(tree):
|
||||
return ret
|
||||
|
||||
|
||||
@macro("_>>")
|
||||
def threading_tail_macro(tree):
|
||||
tree.pop(0)
|
||||
ret = tree.pop(0)
|
||||
for node in tree:
|
||||
if not isinstance(node, HyExpression):
|
||||
nnode = HyExpression([node])
|
||||
nnode.replace(node)
|
||||
node = nnode
|
||||
node.append(ret)
|
||||
ret = node
|
||||
return ret
|
||||
|
||||
|
||||
@macro("car")
|
||||
@macro("first")
|
||||
def first_macro(tree):
|
||||
|
@ -235,6 +235,12 @@
|
||||
["X" "B" "C" "D"])))
|
||||
|
||||
|
||||
(defn test-tail-threading []
|
||||
"NATIVE: test tail threading macro"
|
||||
(assert (= (.join ", " (* 10 ["foo"]))
|
||||
(->> ["foo"] (* 10) (.join ", ")))))
|
||||
|
||||
|
||||
(defn test-threading-two []
|
||||
"NATIVE: test threading macro"
|
||||
(assert (= (-> "a b c d" .upper (.replace "A" "X") .split)
|
||||
|
Loading…
x
Reference in New Issue
Block a user