【发布时间】:2017-04-20 22:25:41
【问题描述】:
我在玩 Elixir。只是想知道是否可以使用管道 |> 运算符将参数传递给匿名函数。这就是我的意思。
a = [1,2,3] #=> [1,2,3]
m = fn ([h|t]) -> [ h*h | m.(t) ] end #=> head squared and call m with tail. Not sure how to use & shortcut for this.
m.(a) #=> [1,4,9]
a |> m #=> undefined function m/1 (understood. Arity is 1)
a |> m.(&1) #=> unhandled &1 outside of capture
【问题讨论】:
-
m = fn ([h|t]) -> [ h*h | m.(t) ]会报错
标签: elixir