Skip to content

Commit

Permalink
refactor: remove custom implementation of Keyword.pop_values/2
Browse files Browse the repository at this point in the history
It has been present since Elixir 1.10
  • Loading branch information
ahamez committed Nov 15, 2024
1 parent ab4e225 commit 1e622a7
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions lib/mix/tasks/protox/generate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule Mix.Tasks.Protox.Generate do
def run(args) do
with {opts, files, []} <- OptionParser.parse(args, strict: @options),
{:ok, output_path} <- Keyword.fetch(opts, :output_path),
{include_paths, opts} = pop_values(opts, :include_path),
{include_paths, opts} = Keyword.pop_values(opts, :include_path),
{multiple_files, opts} = Keyword.pop(opts, :multiple_files, false),
{:ok, files_content} <-
generate(files, output_path, multiple_files, include_paths, opts) do
Expand All @@ -51,17 +51,6 @@ defmodule Mix.Tasks.Protox.Generate do
File.write!(file_name, content)
end

# Custom implementation as Keyword.pop_values/2 is only available since Elixir 1.10
defp pop_values(opts, key) do
{values, new_opts} =
Enum.reduce(opts, {[], []}, fn
{^key, value}, {values, new_opts} -> {[value | values], new_opts}
{key, value}, {values, new_opts} -> {values, [{key, value} | new_opts]}
end)

{Enum.reverse(values), Enum.reverse(new_opts)}
end

defp generate(files, output_path, multiple_files, include_paths, opts) do
Protox.Generate.generate_module_code(
files,
Expand Down

0 comments on commit 1e622a7

Please sign in to comment.