In our codebase, the ideal function in many cases is just a series of piped 
calls. There are plenty of functions where something like `with` makes more 
sense, but we usually prefer pipes.

One of the patterns I see all over the place is this:

  def bad_example(map) do
    value =
      map
      |> get_in([:post, :comments, Access.all(), :likes])
      |> Enum.sum()

    Map.put(:sum_of_comment_likes, value)
  end

I think implementing something like this (I haven't though of the best 
name, but I'm sure there is a better one) would clean up a lot of code:

defmodule MyMap do  
  def set_into(value, map, key) do
    Map.put(key, map, value)
  end
end

This would allow cleaner piping, like so:

  def nice_example(map) do
    map
    |> get_in([:post, :comments, Access.all(), :likes])
    |> Enum.sum()
    |> Map.set_into(map, :sum_of_comment_likes)
  end

What would you all think of having something like this in the standard 
library in `Map`?

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/76bacff2-70fa-4a3c-9f75-b502a2ef4617%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to