Thanks for the quick reply Ben!
I’m indeed mostly dealing with booleans. I like the idea of reducing a set pre-defined conditions to produce the list, it didn’t occur to me at all
Usually I need to do some work before I can produce the element to be added to the list (preload data, call other functions to calculate something, etc), so I’d probably modify your solution a little:
conditions =[
{cond1, :cond1},
{cond2, :cond2},
{cond3, :cond3}
]
list = Enum.reduce(conditions, [0], fn
{true, :cond1}, list ->
result = do_some_work()
[result | list]
{true, :cond2}, list ->
# ...
[result | list]
_, list -> list
end)
Something like this would work nicely ![]()


















