Skip to content

Instantly share code, notes, and snippets.

@cdesch
Last active November 24, 2021 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdesch/338a8d02d8f3c3011ee90c3156f441b7 to your computer and use it in GitHub Desktop.
Save cdesch/338a8d02d8f3c3011ee90c3156f441b7 to your computer and use it in GitHub Desktop.
Elixir Process ID to List, Tuple, String
# Procss ID Util Functions as seen here: https://github.com/cdesch/ex_tool_chest
# Elixir Process ID Parsing to Tuple, List or String
# Related: https://stackoverflow.com/questions/70102293/transform-process-id-pid-in-elixir-to-tuple-or-string-parse-pid-to-other
# ExToolChest.Util.pid_to_string(self())
def pid_to_string(pid) do
pid_inspection = "#{inspect pid}" # gives the string "#PID<0.105.0>"
pid_inspection
|> String.slice(5, 100)
|> String.trim(">")
end
# ExToolChest.Util.pid_to_list(self())
def pid_to_list(pid) do
pid_inspection = "#{inspect pid}" # gives the string "#PID<0.105.0>"
pid_inspection
|> String.slice(5, 100)
|> String.trim(">")
|> String.split(".")
|> Enum.map(fn x -> String.to_integer(x) end)
end
#ExToolChest.Util.pid_to_tuple(self())
def pid_to_tuple(pid) do
pid_inspection = "#{inspect pid}" # gives the string "#PID<0.105.0>"
pid_inspection
|> String.slice(5, 100)
|> String.trim(">")
|> String.split(".")
|> Enum.map(fn x -> String.to_integer(x) end)
|> List.to_tuple
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment