Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

When to use private functions in elixir school?


Asked by Alex Pace on Dec 03, 2021 FAQ



Summary: Functions pattern-match the data passed in to each of its arguments independently. We can use this to bind values to separate variables within the function. When we don’t want other modules accessing a specific function we can make the function private. Private functions can only be called from within their own Module.
Likewise,
Elixir provides us the ability to define private functions that can be accessed from within the module in which they are defined. To define a private function, use defp instead of def. But if we just try to explicitly call phrase function, using the Greeter.phrase() function, it will raise an error.
Additionally, We could use require to tell Elixir you’re going to use macros from other module. The slight difference with import is that it allows using macros, but not functions from the specified module: If we attempt to call a macro that is not yet loaded Elixir will raise an error.
One may also ask,
Kernel is Elixir's default environment. basic language primitives, such as arithmetic operators, spawning of processes, data type handling, and others macros for control-flow and defining new functionality (modules, functions, and the like)
Moreover,
In Part III we’ll examine Phoenix and Ecto’s out-of-the-box Telemetry events and use Telemetry.Metrics to observe a wide-range of such events. In this series, we’re instrumenting a Phoenix app and sending metrics to StatsD with the help of Elixir and Erlang’s Telemetry offerings.