As I am starting to get extremely interrested in Erlang, Elixir and Phoenix, i started to browse the web, and offcourse, since we are talking about Erlang which is pretty old , but soooo cool we have a bunch of code which has been battle-tested and hardened for many years.
This example show how to use an erlang module.
The example is basically taken from here.
And get this, it was written on: Sunday, November 18, 2007 with the title:
I started the module like this:
mix new digraph
cd digraph
mkdir src
--- copy content from link into servers.erl - See the "Now the code" section.
mix compile
After this you can start iex like this so you get the environment:
iex -S mix
Now we can start playing with the library. These are almost verbatim to what can be read in the blog-post from easyerl.
iex(1)> dag = :digraph.new()
{:digraph, 90132, 94227, 98328, true}
iex(2)> :servers.add(dag, [:karoten,:ultraten,:muloaten])
:ok
iex(3)> :servers.connect(dag, :karoten, [:ultraten, {:muloaten, :http}])
:ok
iex(4)> :servers.links(dag, :karoten)
[{:karoten, :ultraten, []}, {:karoten, :muloaten, :http}]
iex(5)> :digraph.get_path(dag,:karoten, :muloaten)
[:karoten, :muloaten]
This shows how easy it is to use the library.
If available in Hex, the package can be installed as:
- Add
digraphs
to your list of dependencies inmix.exs
:
```elixir
def deps do
[{:digraphs, "~> 0.1.0"}]
end
```
- Ensure
digraphs
is started before your application:
```elixir
def application do
[applications: [:digraphs]]
end
```