Is there a concise way to run some code 0 to N times in Elixir?
My specific use case is for star ratings in an Eex
template. If the rating is 0, output 0 stars; if 1, output 1 star, etc.
List.duplicate/2
and String.duplicate/2
are along the right lines, but don't work well for HTML in an Eex
template.
This is what I'm doing now:
<%= for _i <- List.duplicate(true, star_count) do %>
<svg...>svg data here</svg>
<% end %>
Is there a better way?
for i <- 0..n, i > 0, do: ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With