I’m trying to wrap my head around functional programming, and feel like I might be breaking a few rules here.
def get_published do
query = from p in Post,
where: p.published == true
Repo.all(query)
end
It doesn’t accept any arguments. As I understand it, that should be a dead giveaway that you’re creating side-effects instead of transforming something. I’m not sure how a function like this could be more ‘functional’ though. Is there another way I should be doing this?
Just by using a external database you can assume that your function is impure.
There’s an extent that you can call your code functional in real world applications.