1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Maps do
6 def put_if_present(map, key, value, value_function \\ &{:ok, &1}) when is_map(map) do
7 with false <- is_nil(key),
8 false <- is_nil(value),
9 {:ok, new_value} <- value_function.(value) do
10 Map.put(map, key, new_value)
16 def safe_put_in(data, keys, value) when is_map(data) and is_list(keys) do
17 Kernel.put_in(data, keys, value)
22 def filter_empty_values(data) do
23 # TODO: Change to Map.filter in Elixir 1.13+
29 {_k, %{} = v} -> Map.keys(v) != []