Elixirで部分適用
どうしてもやってみたくなったので・・・
def a3(a1,a2,a3) do a1 <> a2 <> a3 end def portion(f,v1) when is_function(f) do {f, [v1]} end def portion({f,arg},v) do Logger.debug "ca #{inspect f} #{inspect arg} #{inspect v}" {f , [v | arg]} end def portion({f , args}) do Logger.debug "endc #{inspect f} #{inspect args}" apply(f, Enum.reverse( args )) end test "" do f1 = portion(&a3/3,"1") f2 = portion(f1,"2") f3 = portion(f2,"3") assert portion(f3) == "123" end
結局関数使わないと今のところ出来なかった・・・
他に良い方法あるのかなぁ〜