Coming from OO languages, the functional approach of Elixir is still a bit difficult for me. I’m now facing the following problem that I don’t know how to solve:
My application consists of multiple models (db tables) that have a couple of fields in common. For example, they have a field “order” that is used to have a custom ordering of the records in a list.
I have implemented two functions in model A two move down or up the position of the record in the list by swapping the value of the field order with the previous or next record in the list.
What is the best approach to “copy” those two functions to the other models as well? In an OO language I’d create a superclass and implement the functions there.