added warning to use old keys
[akkoma] / lib / pleroma / maps.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
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)
11 else
12 _ -> map
13 end
14 end
15 end