Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An Elixir library that implements prototype inheritance for dynamic function calling

Notifications You must be signed in to change notification settings

typesend/prototype

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

3 Commits

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:

defmodule YourModule do
 def __prototype__, do: AnyOtherModule
end

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

case Prototype.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:

def deps do
 [
 {: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

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /