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

@ -99,11 +99,6 @@ defmodule Pleroma.Web.ControllerHelper do
render_error(conn, :not_implemented, "Can't display this activity")
end
@spec put_if_exist(map(), atom() | String.t(), any) :: map()
def put_if_exist(map, _key, nil), do: map
def put_if_exist(map, key, value), do: Map.put(map, key, value)
@doc """
Returns true if request specifies to include embedded relationships in account objects.
May only be used in selected account-related endpoints; has no effect for status- or