Skip to content

Instantly share code, notes, and snippets.

@RichMorin
Created April 24, 2019 03:20
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 RichMorin/ffaa6dbc66ffc44cf4df5cbb3efd0b6c to your computer and use it in GitHub Desktop.
Save RichMorin/ffaa6dbc66ffc44cf4df5cbb3efd0b6c to your computer and use it in GitHub Desktop.
filter/2
The input tuple is emitted by `Toml.decode/2`.
@spec filter({atom, any}, String.t) :: map
# @spec filter( {:ok | :error, any}, String.t) :: map
defp filter({status, payload}, trim_path) do
#
# Filter the parsing results, reporting and removing cruft.
# If a problem is detected, report it and return an empty Map.
# Otherwise, return the parsed data.
cond do
status == :error ->
IO.puts "\nIgnored: " <> trim_path
IO.puts "Because: " <> inspect(payload)
%{}
not(is_map(payload)) ->
IO.puts "\nIgnored: " <> trim_path
IO.puts "Because: Payload is not a Map."
%{}
Enum.empty?(payload) ->
IO.puts "\nIgnored: " <> trim_path
IO.puts "Because: Payload is empty."
%{}
true -> payload
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment