# Tips for golfing in Elixir

Elixir is a relatively new functional language, which I've taken a deep interest in. I'd like to get general tips about golfing in Elixir and learn techniques that can be applied to code-golf problems that are somewhat specific to Elixir in general.

Based on so many similar questions about Python, Ruby, Javascript, etc. I'll also try to post tips as I learn more about the language.

• What does Elixir running on the Erlang VM have to do with the Erlang language? – Alex A. Dec 5 '15 at 4:03

### String and char arguments don't need spaces

For example, IO.puts"Hello, World!" and IO.puts'cat' are valid programs.

### Don't use the Pipe operator or parenthesis for calling methods

# With Pipe
arg |> M.a |> M.b |> M.c   # 24 Bytes
arg|>M.a|>M.b|>M.c         # 18 Bytes

# With Parenthesis
M.c(M.b(M.a(arg)))         # 18 Bytes

# Only Spaces
M.c M.b M.a arg            # 15 Bytes


## Inject code into strings

Instead of concatenating something into a string, like:

"prefix"<>code<>"suffix"


You can use #{} to insert it into the string:

"prefix#{code}suffix"


This will save 3 bytes.

### Map Arguments don't need spaces either

Like LegionMammal978's answer, you can leave out space when passing Map as an argument to a method:

IO.inspect%{a: 1,b: 2}

• Can you similarly remove the spaces after the colons? – Alex A. Dec 5 '15 at 20:51
• Sadly, no. But you can remove spaces after semicolons and commas. – Sheharyar Dec 5 '15 at 23:12