What is the actual problem that you are trying solve with this particular approach?
Remember there are a multitude of other ways to compose and share functionality in Elixir - maybe one of them is more appropriate for the problem at hand.
defmodule MyMixin do
def inner(arg) do
"[[#{arg}]]"
end
def hello_mixin(arg, hello, out)do
arg
|> inner()
|> hello.()
|> outer()
|> out.()
end
def outer(arg) do
"((#{arg}))"
end
end
defmodule M1 do
def hello2(a) do
a
|> hello()
|> out()
end
def hello_mixin(arg),
do: MyMixin.hello_mixin arg, &hello/1, &out/1
def hello_mixin_alt(arg) do
arg
|> MyMixin.inner()
|> hello()
|> MyMixin.outer()
|> out()
end
def hello(arg),
do: "something22226677777 #{arg}"
def out(arg),
do: IO.puts "#{arg} cba"
end
defmodule M2 do
def hello2(a) do
a
|> hello()
|> out()
end
def hello_mixin(arg),
do: MyMixin.hello_mixin arg, &hello/1, &out/1
def hello_mixin_alt(arg) do
arg
|> MyMixin.inner()
|> hello()
|> MyMixin.outer()
|> out()
end
def hello(arg),
do: "something432432432 #{arg}"
def out(arg),
do: IO.puts "#{arg} 098"
end
defmodule M3 do
def mix_fun3(m, h, o),
do: fn arg -> m.(arg, h, o) end
def mix_fun4(i, h, p, o) do
fn arg ->
arg
|> i.()
|> h.()
|> p.()
|> o.()
end
end
def mix_fun_list(funs),
do: fn arg -> List.foldl funs, arg, &(&1.(&2)) end
def mix_fun_comp([]),
do: fn arg -> arg end
def mix_fun_comp([g | r]),
do: mix_comp r, g
defp mix_comp([], f),
do: f
defp mix_comp([f|r], g),
do: (mix_comp r, (comp f, g))
defp comp(f, g),
do: fn arg -> f.(g.(arg)) end
end
IO.puts (M1.hello_mixin 123)
IO.puts (M2.hello_mixin "fdsafds")
IO.puts (M1.hello_mixin_alt 123)
IO.puts (M2.hello_mixin_alt "fdsafds")
m1_3 = (M3.mix_fun3 &MyMixin.hello_mixin/3, &M1.hello/1, &M1.out/1)
m2_3 = (M3.mix_fun3 &MyMixin.hello_mixin/3, &M2.hello/1, &M2.out/1)
m1_4 = (M3.mix_fun4 &MyMixin.inner/1, &M1.hello/1, &MyMixin.outer/1, &M1.out/1)
m2_4 = (M3.mix_fun4 &MyMixin.inner/1, &M2.hello/1, &MyMixin.outer/1, &M2.out/1)
m1_fl = M3.mix_fun_list [&MyMixin.inner/1, &M1.hello/1, &MyMixin.outer/1, &M1.out/1]
m2_fl = M3.mix_fun_list [&MyMixin.inner/1, &M2.hello/1, &MyMixin.outer/1, &M2.out/1]
m1_cm = M3.mix_fun_comp [&MyMixin.inner/1, &M1.hello/1, &MyMixin.outer/1, &M1.out/1]
m2_cm = M3.mix_fun_comp [&MyMixin.inner/1, &M2.hello/1, &MyMixin.outer/1, &M2.out/1]
IO.puts m1_3.(123)
IO.puts m2_3.("fdsafds")
IO.puts m1_4.(123)
IO.puts m2_4.("fdsafds")
IO.puts m1_fl.(123)
IO.puts m2_fl.("fdsafds")
IO.puts m1_cm.(123)
IO.puts m2_cm.("fdsafds")
((something22226677777 [[123]])) cba
ok
((something432432432 [[fdsafds]])) 098
ok
((something22226677777 [[123]])) cba
ok
((something432432432 [[fdsafds]])) 098
ok
((something22226677777 [[123]])) cba
ok
((something432432432 [[fdsafds]])) 098
ok
((something22226677777 [[123]])) cba
ok
((something432432432 [[fdsafds]])) 098
ok
((something22226677777 [[123]])) cba
ok
((something432432432 [[fdsafds]])) 098
ok
((something22226677777 [[123]])) cba
ok
((something432432432 [[fdsafds]])) 098
ok
$