Bunch v0.1.2 Bunch.Module View Source

A bunch of functions for easier manipulation on modules.

Link to this section Summary

Functions

Works like Kernel.apply/3 if module exports fun_name/length(args), otherwise returns default

Determines whether module implements a behaviour by checking a test function

Ensures that module is loaded and checks whether it exports given function

Returns instance of struct defined in given module, if the module defines struct. Otherwise returns nil

Link to this section Functions

Link to this function apply(module, fun_name, args, default) View Source
apply(module(), fun_name :: atom(), args :: list(), default :: any()) :: any()

Works like Kernel.apply/3 if module exports fun_name/length(args), otherwise returns default.

Determines if function is exported using loaded_and_function_exported?/3.

Link to this function check_behaviour(module, fun_name) View Source
check_behaviour(module(), atom()) :: boolean()

Determines whether module implements a behaviour by checking a test function.

Checked behaviour needs to define a callback with unique name and no arguments, that should return true. This functions ensures that the module is loaded and checks if it exports implementation of the callback that returns true. If all these conditions are met, true is returned. Otherwise returns false.

Link to this function loaded_and_function_exported?(module, fun_name, arity) View Source
loaded_and_function_exported?(module(), atom(), non_neg_integer()) :: boolean()

Ensures that module is loaded and checks whether it exports given function.

Link to this function struct(module) View Source
struct(module()) :: struct() | nil

Returns instance of struct defined in given module, if the module defines struct. Otherwise returns nil.

Raises if struct has any required fields.