Elixir tips and tricks

Image of Author
September 21, 2022 (last updated September 11, 2023)

IO.write with \r

I can find no reference to this online. If you want to console.log a value without clogging up your logs, you can use \r to replace the value in a string. In the example below, you do not get 1 million printouts. You get 1 printout that replaces the number 1 million times.

for x <- 1..1_000_000 do
  IO.write("\rnum: " <> Integer.to_string(x))
end

Maybe I'm a noob and this is not just an elixir thing? It seems related to \n for newline, so it might be a thing in general

Mix

  • Remove old dependencies: shell mix deps.clean --unlock --unused

Resources