Created
April 24, 2019 03:20
-
-
Save RichMorin/ffaa6dbc66ffc44cf4df5cbb3efd0b6c to your computer and use it in GitHub Desktop.
filter/2
This file contains 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
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