Last active
November 24, 2021 22:00
-
-
Save cdesch/338a8d02d8f3c3011ee90c3156f441b7 to your computer and use it in GitHub Desktop.
Elixir Process ID to List, Tuple, String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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