I like the idea as well. And I like the name maybe_update. -bt
On Fri, Jun 5, 2020 at 11:55 AM Davide Bettio <davide.bet...@ispirata.com> wrote: > Hello, > > I work with Riccardo so I frequently experience the same issue. > I really like José and Piotr solutions, however I'd like to point out that > they might introduce some clutter and in real world code they might cause > long lines that are broken from the formatter, which can be ugly when using > pipes. > For this reason I still think that Map.update_if might be a good idea, > anyway run_if already fixes the copy&paste helper function issue, which is > already better than nothing. > > Regards, > Davide Bettio. > > Il giorno venerdì 5 giugno 2020 15:27:51 UTC+2, José Valim ha scritto: > >> This is an interesting proposal! Unfortunately if the value you want to >> compute is expensive, then you need to fallback to the usual `if` approach. >> This is also specific to maps. It may be worth considering a more general >> purpose mechanism, for example: >> >> map >> |> update_if(foo != nil, &Map.put(&1, :foo, foo)) >> |> update_if(bar != nil, &Map.put(&1, :bar, normalize_bar(bar))) >> >> Being in Kernel also allows us to write it as a macro, which can be >> further optimized. Not sure if update_if is the best name though. >> Suggestions and comparisons to other languages are welcome. >> >> -- > 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/4ab01515-f870-493c-8544-a540badd63c8o%40googlegroups.com > <https://groups.google.com/d/msgid/elixir-lang-core/4ab01515-f870-493c-8544-a540badd63c8o%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Regards, Bruce Tate CEO <https://bowtie.mailbutler.io/tracking/hit/f8218219-d2a8-4de4-9fef-1cdde6e723f6/c7c97460-016e-45fb-a4ab-0a70318c7b97> Groxio, LLC. 512.799.9366 br...@grox.io grox.io -- 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/CAFXvW-7WNTZxDx%2B-z6B4z9ODxNwUHQtjOxKiCaRH6-5ycVMbyw%40mail.gmail.com.