Create Pleroma.Maps.put_if_present(map, key, value, value_fun // &{:ok, &1})

Unifies all the similar functions to one and simplify some blocks with it.
This commit is contained in:
Haelwenn 2020-06-05 14:48:02 +00:00
commit 54bae06b4f
14 changed files with 59 additions and 106 deletions

View file

@ -17,14 +17,6 @@ defmodule Pleroma.Helpers.UriHelper do
|> URI.to_string()
end
def append_param_if_present(%{} = params, param_name, param_value) do
if param_value do
Map.put(params, param_name, param_value)
else
params
end
end
def maybe_add_base("/" <> uri, base), do: Path.join([base, uri])
def maybe_add_base(uri, _base), do: uri
end