otuv
Passing private functions
Hi,
I have a simple helper function to clock stuff.
I want to put it in a my X.Helper module (assuming my project is X) to use it wherever I need.
def clock(mark, fun, args) do
{time, result} = :timer.tc(fun, args)
IO.puts(mark <> ": #{Kernel.inspect(result)} Time: #{time} μs")
result
end
But when I pass a function from the module Y I get an error module Y is not available
Reluctantly (as it would break the decoupling) I tried to alias the Y function but that does not seem to work either.
What is the common approach to this kind of stuff?
Marked As Solved
NobbZ
Ah, now I remember…
&M.f/a exposes the remote call to the receiving module, which then isn’t allowed to do that, you need to omit the module name and do Helpers.clock("Append", &append_as_binary/2, [data_path(key), value]) instead…
Also Liked
NobbZ
Could you please tell us the exact error you get?
From a first glance over what we have seen so far, it should work.
otuv
Total turnaround ![]()
It does work and I can remove all of the aliases from the helper.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #podcasts
- #code-sync
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








