Today I Learned

hashrocket A Hashrocket project

Custom Sigils In Elixir

You can create custom sigils by following the sigil_{character} definition pattern. Let's make an addition sigil sigil_a that sums up space separated numbers.

defmodule CustomSigil do
  def sigil_a(string, []) do
    |> String.split(" ")
    |> String.to_integer(&1))
    |> Enum.sum()

# ~a(2 4 6)
#=> 12
# ~a(12 12)
#=> 24
See More #elixir TILs
Looking for help? At Hashrocket, we 💜 Elixir! From our many Elixir client projects, to sponsoring the Chicago Elixir Meetup, to the source code for this application, we are invested in this community. Contact us today to talk about your Elixir project.