MT103/202 DIRECT WIRE TRANSFER PAYPAL TRANSFER CASHAPP TRANSFER ZELLE TRANSFER LOAN DEAL TRANSFER WISE WESTERN UNION TRANSFER BITCOIN FLASHING BANK ACCOUNT LOADING/FLASHING IBAN TO IBAN TRANSFER MONEYGRAM TRANSFER IPIP/DTC SLBC PROVIDER CREDIT CARD TOP UP DUMPS/ PINS SEPA TRANSFER WIRE TRANSFER BITCOIN TOP UP GLOBALPAY INC US SKRILL USA UNIONPAY RECEIVER
Thanks. NOTE; ONLY SERIOUS / RELIABLE RECEIVERS CAN CONTACT. DM ME ON WHATSAPP +1(786) 588-4571 On Saturday, February 26, 2022 at 3:24:21 AM UTC+1 qh...@pnq.cc wrote: > I've found myself repeatedly need to replace some key name in the map. > > For example, to change the key name from "_id" to "id": > > data = fetch_some_data_from_db() > {id, data} = Map.pop(data, "_id") > data |> Map.put(data, "id", id) > > It gets messy when the target is deeply nested. > > To help deal with it, I wrote two util functions: > > defp replace_key_in(data, [old_name], new_name), > do: replace_key(data, old_name, new_name) > > defp replace_key_in(data, [_ | _] = path, new_name) do > {path, [old_name]} = Enum.split(path, -1) > > update_in( > data, > path, > &replace_key(&1, old_name, new_name) > ) > end > > defp replace_key(data, old_name, new_name) do > {value, rest} = Map.pop(data, old_name) > Map.put(rest, new_name, value) > end > > Do you think we can add it to the Map module? > -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/b36eef20-6c0d-4a3e-a49c-35dcb7d32a01n%40googlegroups.com.