diff --git a/apps/transport/lib/registry/engine.ex b/apps/transport/lib/registry/engine.ex index 17198d3e9c..0ebbeec0fb 100644 --- a/apps/transport/lib/registry/engine.ex +++ b/apps/transport/lib/registry/engine.ex @@ -19,13 +19,13 @@ defmodule Transport.Registry.Engine do create_empty_csv_with_headers(output_file) enumerate_gtfs_resources(limit, formats) - |> Extractor.traverse(&prepare_extractor/1) + |> Extractor.map_result(&prepare_extractor/1) |> Task.async_stream(&download/1, max_concurrency: 10, timeout: 120_000) # one for Task.async_stream - |> Extractor.keep_results() + |> Extractor.cat_results() # one for download/1 - |> Extractor.keep_results() - |> Extractor.traverse(&extract_from_archive/1) + |> Extractor.cat_results() + |> Extractor.map_result(&extract_from_archive/1) |> dump_to_csv(output_file) end diff --git a/apps/transport/lib/registry/extractor.ex b/apps/transport/lib/registry/extractor.ex index 34ebb9e14d..19ab45308b 100644 --- a/apps/transport/lib/registry/extractor.ex +++ b/apps/transport/lib/registry/extractor.ex @@ -11,16 +11,16 @@ defmodule Transport.Registry.Extractor do @callback extract_from_archive(path :: Path.t()) :: result([Stop.t()]) - @spec keep_results(Stream.t(result(term()))) :: Stream.t(term()) - def keep_results(enumerable), do: Stream.flat_map(enumerable, &keep_result/1) + @spec cat_results(Stream.t(result(term()))) :: Stream.t(term()) + def cat_results(enumerable), do: Stream.flat_map(enumerable, &keep_ok/1) - defp keep_result({:ok, result}), do: [result] - defp keep_result(_), do: [] + defp keep_ok({:ok, result}), do: [result] + defp keep_ok(_), do: [] - @spec traverse(Stream.t(term()), (term() -> result(term()))) :: Stream.t(term()) - def traverse(enumerable, mapper) do + @spec map_result(Stream.t(term()), (term() -> result(term()))) :: Stream.t(term()) + def map_result(enumerable, mapper) do enumerable |> Stream.map(mapper) - |> keep_results() + |> cat_results() end end diff --git a/apps/transport/test/registry/extractor_test.exs b/apps/transport/test/registry/extractor_test.exs index 462196cea3..da60497735 100644 --- a/apps/transport/test/registry/extractor_test.exs +++ b/apps/transport/test/registry/extractor_test.exs @@ -4,23 +4,23 @@ defmodule Transport.Registry.ExtractorTest do require Integer alias Transport.Registry.Extractor - test "keep_results" do - assert [] == keep_results([]) - assert [] == keep_results([{:error, "Error message"}]) - assert [1, 3] == keep_results([{:ok, 1}, {:error, "Error message"}, {:ok, 3}]) + test "cat_results" do + assert [] == cat_results([]) + assert [] == cat_results([{:error, "Error message"}]) + assert [1, 3] == cat_results([{:ok, 1}, {:error, "Error message"}, {:ok, 3}]) end - test "traverse" do - assert [] == traverse([], &even_is_forbidden/1) - assert [1, 3, 5, 7, 9] == traverse(1..10, &even_is_forbidden/1) + test "map_result" do + assert [] == map_result([], &even_is_forbidden/1) + assert [1, 3, 5, 7, 9] == map_result(1..10, &even_is_forbidden/1) end - defp keep_results(enumerable) do - enumerable |> Extractor.keep_results() |> Enum.to_list() + defp cat_results(enumerable) do + enumerable |> Extractor.cat_results() |> Enum.to_list() end - defp traverse(enumerable, mapper) do - enumerable |> Extractor.traverse(mapper) |> Enum.to_list() + defp map_result(enumerable, mapper) do + enumerable |> Extractor.map_result(mapper) |> Enum.to_list() end defp even_is_forbidden(i) when Integer.is_odd(i), do: {:ok, i}