Skip to content

Commit

Permalink
add elixir pipe macro
Browse files Browse the repository at this point in the history
  • Loading branch information
jbr committed Nov 28, 2015
1 parent 8ae9e50 commit 5088583
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/macros.sibilant
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,15 @@

(macro set (arr ...kv-pairs)
(interleave "\n" (bulk-map kv-pairs (#(k v) `(assign (get @arr @k) @v)))))


(macro pipe (...calls)
(inject undefined calls
(#(value item)
(var cloned (clone item))
(if (undefined? value)
cloned
(merge-into cloned
{ contents [ (first cloned.contents)
value
...(rest cloned.contents) ] })))))
5 changes: 5 additions & 0 deletions test/test.sibilant
Original file line number Diff line number Diff line change
Expand Up @@ -674,3 +674,8 @@ b();"))
(assert-translation "(default foo 1 bar 2)"
"foo = ((typeof foo !== \"undefined\")) ? foo : 1;
bar = ((typeof bar !== \"undefined\")) ? bar : 2;")


(assert-translation "(pipe a (b c) (d e) (+ 1) (send to-string) (send to-upper-case))"
"(d(b(a, c), e) + 1).toString().toUpperCase()")

0 comments on commit 5088583

Please sign in to comment.