View Source Bunch.Module (Bunch v1.6.1)

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

Link to this function

apply(module, fun_name, args, default)

View Source
@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.

Link to this function

check_behaviour(module, fun_name)

View Source
@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.

Link to this function

loaded_and_function_exported?(module, fun_name, arity)

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

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

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