GVA (global_variable v0.1.1) View Source
Global VAriable utilities.
All commands are prefixed with the letter g
to prevent any clash with future Kernel
functions.
To use it in your script be sure to run at least Elixir 1.12
then import functions like the following:
Mix.install([:global_variable])
import GVA
An ETS table is used underneath meaning you can use any funky tricks to manipulate it data, pattern match and so on.
No variable table is created by default, you have to do it by yourself.
Examples
Mix.install([:global_variable])
import GVA
gnew :var
gput :var, :answer, 42
gget :var, :answer # 42
gget_and_update :var, :answer, fn x -> 1 + x end # 43
Link to this section Summary
Functions
Get an variable's value from a table by it's key.
Get and update a variable from a table by a function. Operation is probably not atomic and won't save you from race condition. (are you sure to write a script if you have these requirements?)
Create a new table to hold your variables. A table can hold as much variables (and associated data) as your RAM allows you.
Put a value in a variable table.
Link to this section Functions
Get an variable's value from a table by it's key.
Get and update a variable from a table by a function. Operation is probably not atomic and won't save you from race condition. (are you sure to write a script if you have these requirements?)
function
must be a function with an arity of 1.
Create a new table to hold your variables. A table can hold as much variables (and associated data) as your RAM allows you.
Put a value in a variable table.