說我有一堆類似的代碼如下:如何將私有函數抽象爲實用程序庫?
def dirs(path, regex_dir \\ ".+") do
path
|> normalize_path
|> do_dirs([], regex_dir)
end
# list of bitstrings
defp normalize_path([path | rest]) when is_bitstring(path) do
[path | normalize_path(rest)]
end
# list of character lists
defp normalize_path([path | rest]) when is_list(path) do
[to_string(path) | normalize_path(rest)]
end
defp normalize_path([]) do
[]
end
# bitstring
defp normalize_path(path) when is_bitstring(path) do
[path]
end
# character list
defp normalize_path(path) when is_list(path) do
[to_string(path)]
end
我想用normalize_path代碼的另一部分,什麼是抽象掉了normalize_path功能的最佳方式進入實用模塊或庫?我仍然希望保持該功能只能在內部使用,不能作爲公共功能使用。
讓東西在實用程序模塊/庫中,但隱藏它似乎是兩個相反的目標。 – 2015-02-12 13:22:20