Skip to content

Instantly share code, notes, and snippets.

@blackode
Created February 17, 2017 02:00
Show Gist options
  • Save blackode/15ddca326d604fbef68ae833504ac37e to your computer and use it in GitHub Desktop.
Save blackode/15ddca326d604fbef68ae833504ac37e to your computer and use it in GitHub Desktop.
Custom Sigils

Custom Sigils

defmodule MySigils do
  #returns the downcasing string if option l is given then returns the list of downcase letters
  def sigil_l(string,[]), do: String.Casing.downcase(string)
  def sigil_l(string,[?l]), do: String.Casing.downcase(string) |> String.graphemes
  
  #returns the upcasing string if option l is given then returns the list of downcase letters
  def sigil_u(string,[]), do: String.Casing.upcase(string)
  def sigil_u(string,[?l]), do: String.Casing.upcase(string) |> String.graphemes
end

usage

Load the module into iex

iex> import MySigils
iex> ~l/HELLO/
"hello"
iex> ~l/HELLO/l
["h", "e", "l", "l", "o"]
iex> ~u/hello/
"HELLO"
iex> ~u/hello/l
["H", "E", "L", "L", "O"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment