Last active
January 20, 2020 16:35
-
-
Save emadb/49551f9c072e348dbd53a4401f07a182 to your computer and use it in GitHub Desktop.
Tramp data in Elixir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Foo do | |
def execute_command(data, coeff) do | |
data = prepare_data(data, coeff) | |
persist(data.name, coeff) | |
end | |
def prepare_data(data, coeff) do | |
w = calculate_w(data.x, data.y, data.z, coeff) | |
%{ | |
name: "foo", | |
weight: w | |
} | |
end | |
def calculate_w(x, y, z, coeff) do | |
x * y * z * coeff | |
end | |
def persist(name, w) do | |
# save data | |
IO.inspect {name, w}, label: "saving" | |
:ok | |
end | |
def main do | |
data = %{ | |
name: "foo", | |
x: 10, y: 20, z: 30 | |
} | |
# read from ENV | |
coeff = 5 | |
execute_command(data, coeff) | |
end | |
end | |
Foo.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment