Bunch.Module (Bunch v1.6.3)

View Source

A bunch of functions for easier manipulation on modules.

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.

Functions

apply(module, fun_name, args, default)

@spec 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.

check_behaviour(module, fun_name)

@spec 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.

loaded_and_function_exported?(module, fun_name, arity)

@spec loaded_and_function_exported?(module(), atom(), non_neg_integer()) :: boolean()

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

struct(module)

@spec 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.