Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
612B

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Maps do
  5. def put_if_present(map, key, value, value_function \\ &{:ok, &1}) when is_map(map) do
  6. with false <- is_nil(key),
  7. false <- is_nil(value),
  8. {:ok, new_value} <- value_function.(value) do
  9. Map.put(map, key, new_value)
  10. else
  11. _ -> map
  12. end
  13. end
  14. def safe_put_in(data, keys, value) when is_map(data) and is_list(keys) do
  15. Kernel.put_in(data, keys, value)
  16. rescue
  17. _ -> data
  18. end
  19. end