Looping through a list of maps

One possible variation:

  @prop_names [:entity_name, :image_file, :product_div, :product_sub_div, :product_sub_div_id]

  defp extract_props(e),
    do: Map.take(e, @prop_names)

  def collect_details(e, tail),
    do: [Map.drop(e, @prop_names) | tail]

Still trying to understand the few lines of code used to achieve this.

My personal preference would have been:

defmodule Demo do
  @prop_names [:entity_name, :image_file, :product_sub_div, :product_sub_div_id]
  defp entity_props(e),
    do: Map.take(e, @prop_names)

  @detail_names [:amount, :charge, :reference, :req_date, :status, :status_msg]
  defp entity_details(e),
    do: Map.take(e, @detail_names)

  defp make_entity({props, details}),
    do: Map.put_new(props, :details, details)

  def run(list) when is_list(list) do
    list
    |> Enum.group_by(&entity_props/1, &entity_details/1)
    |> Enum.map(&make_entity/1)
  end
end

I believe it makes the code more “scannable” - i.e. my brain only has to recognize one standard function per line and pick up on the concepts expressed by the names of the custom functions rather than continually mentally parse each line of code which tends to be fatiguing.