0
我想運行在某個目錄功能的仙丹功能,所以我有這樣的代碼:如何傳遞IO到傳遞到另一個函數
def main(args) do
args |> directory |> File.cd!(&Cli.run/0) |> IO.puts
end
def directory([]) do
"."
end
def directory(args) do
hd(args)
end
我現在想IO傳遞到CLI的.run,以便我可以測試它 - 目前IO只是直接用於Cli.run。
我該如何傳遞它?
我不完全知道你在做什麼在這裏。如果你想傳遞一些東西(IO)到Cli.run,你需要將它添加到主'def main(args,io \\ IO)do ...'的參數中,然後加到Cli.run' fn - > Cli.run(io)end' 如果你想檢查測試中的IO,有http://elixir-lang.org/docs/stable/ex_unit/ExUnit.CaptureIO.html#capture_io/1 – manukall
是,通過匿名函數'fn - > Cli.run(io)end'到'File.cd!'中工作,謝謝。 – user2355213
您應該發佈正確的解決方案作爲答案,以便搜索此問題的其他人可以輕鬆找到答案。 –