我想將一組函數應用於某個值並獲取一組值作爲輸出。我看到help?> groupby
(DataFrames包),我們可以這樣做:julia lang - 如何將多個函數應用於一個值
> df |> groupby(:a) |> [sum, length]
> df |> groupby([:a, :b]) |> [sum, length]
但我們可以做
> [sum, length](groupby([:a, :b]))
MethodError: objects of type Array{Function,1} are not callable
square brackets [] for indexing an Array.
eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:64
in macro expansion at ./REPL.jl:95 [inlined]
in (::Base.REPL.##3#4{Base.REPL.REPLBackend})() at ./event.jl:68
甚至
> [sum, length](1:5)
我期望的輸出:
[15, 5]
感謝您指出的源代碼。我可以擴展它以實現:'''import base。(|>) (|>){T <:Function}(a :: Array,fs :: Vector {T})= [f(a)for f in fs] > 1:5 |> collect |> [sum,length] 2元陣列{Int64,1}:''' – Phuoc