Skip to content

Latest commit

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Prototype

An Elixir library that implements prototype inheritance for dynamic function calling over a chain of modules. These prototypes can be user-defined struct modules or any other modules.

Usage

To specify a module's prototype module, implement the __prototype__/0 function like so:

defmoduleYourModuledodef__prototype__,do: AnyOtherModuleend

Then to call functions wherever they are found up the prototype chain you might:

casePrototype.apply(YourModule,:function_name,["argument","list"])do{:ok,return_value,_meta}->return_value,{:missing_fun,_function_name,_args,_meta}->{:error,"function not found"}end

Where _meta contains tracing metadata about the call chain that executed. As you might suspect, if the function cannot be found in any of the modules then the result is a :missing_fun tuple because it's not very fun to have multiple attempts to call a function fail!

Installation

This package can be installed by adding prototype to your list of dependencies in mix.exs:

defdepsdo[{:prototype,"~> 1.0.0-alpha"}]end

Feedback welcome!

If you use this library and have suggestions for how to make it better, please file an issue.

About

An Elixir library that implements prototype inheritance for dynamic function calling

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages