dkuku

dkuku

Looking for an easy way to set calculations from outside of source code

I wonder about a design pattern that may be used for setting for the function execution pipeline.
Lets say i have users from different countries and i want to calculate salary tax - the calculation changes for every country so I dont want to hardcode it but have a way to set it using json or something similar.

Marked As Solved

mindok

mindok

Depending on how dynamic you want the calculations to be, you could use something like this: https://github.com/narrowtux/abacus - it can parse and evaluate mathematical expressions at run time. That would allow you to carry the expressions around as data and match & apply them at run time.

Also Liked

LostKobrakai

LostKobrakai

At a high level you’re already on the right track: Pass things as data instead of trying to “pass logic around”. How you encode your invariants into data however depends quite a bit on what really is different between your cases. For simple cases just a struct/map with some keys might be enough. For more complex cases you can create a behaviour and require a module to be supplied, which implements the behaviour (like how genservers work).

LostKobrakai

LostKobrakai

For the behaviour/implementation part: Any email library, especially when allowing you to select the sending service via the parameters supplied. Also as already mentioned - genservers - otp provides the code, which runs it, while the module you pass in is in charge of implementing how it behaves.

dkuku

dkuku

thank you for the replays - I think abacus is exactly what I’m looking for:
iex> Abacus.eval("a * b", %{"a" => 10, "b" => 10})
{:ok, 100}

Where Next?

Popular in Questions Top

pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New

We're in Beta

About us Mission Statement