:) all good. I do think that both & &1 and fn x -> x end and & &1 are both harder to scan than &identity/1 as it's almost always better to name a concept for a beginner (or most anyone, for that matter). In my classes we often write an identity function as an intermediate teaching step because I can name the concept. There's less to grok at once.
But no big deal... if we're closing this I will respect your decision. José, what would you say to have the identity function as a default to things like Enum.filter and Enum.group_by? Some of the other Enumerable functions have defaults, such as sort. There's no breaking change and it obviates the need for the identity function in quite a few places. Examples: a word counter, where the words might be nil: words |> Enum.filter |> Enum.group_by |> Map.new(fn {x, y} -> {x, length(y)} end) Solves the problem of identity for some of the important use cases; no breaks of backward compatibility; discoverable through existing docs. -bt On Fri, Jul 12, 2019 at 1:21 PM José Valim <jose.va...@plataformatec.com.br> wrote: > If the goal is teaching, then I think "fn x -> x end" beats both > "&identify/1" and "& &1" in terms of clarity, as identity itself is still a > concept that needs to be explained. > > > *José Valim* > www.plataformatec.com.br > Skype: jv.ptec > Founder and Director of R&D > > > On Fri, Jul 12, 2019 at 7:18 PM Bruce Tate <br...@grox.io> wrote: > >> > Why should we add this to Elixir core, instead of "extending" with >> module? >> >> I have been a big proponent of this for a long time because just about >> every code base uses the identity function and it's a barrier to those who >> would learn Elixir. >> >> Rather than import or call &FP.identity/1, most would just continue to >> use something like & &1, and that's generally tough on beginners. >> >> -bt >> >> On Fri, Jul 12, 2019 at 12:59 PM Chulki Lee <chulki....@gmail.com> wrote: >> >>> I'm happy to see Elixir adopting FP concept here ([identity function]( >>> https://en.wikipedia.org/wiki/Identity_function)), but I'm not sure >>> it's good to add it to `Kernel` (as it's imported by default!) - or even in >>> Elixir core. >>> >>> Why should we add this to Elixir core, instead of "extending" with >>> module? >>> >>> ```elixir >>> defmodule FP do >>> def identity(a), do: a >>> end >>> >>> def module YourApp do >>> import FP >>> >>> def hello do >>> 'abcdaabccc' |> Enum.sort |> Enum.chunk_by(&identity/1) >>> end >>> end >>> ``` >>> >>> For example, that library can be de-facto helper for such FP utility >>> functions. >>> >>> -- >>> 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/2e98526b-e83c-4b92-8035-26bce95da822%40googlegroups.com >>> <https://groups.google.com/d/msgid/elixir-lang-core/2e98526b-e83c-4b92-8035-26bce95da822%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> -- >> >> 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-5vOv15iAWWH6qvbyUPf7KrY2Smw0oBKdf56%3DLPiH9BNA%40mail.gmail.com >> <https://groups.google.com/d/msgid/elixir-lang-core/CAFXvW-5vOv15iAWWH6qvbyUPf7KrY2Smw0oBKdf56%3DLPiH9BNA%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- > 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/CAGnRm4LX2L155aA6koxFGFmKdBoNoaRYmX83BQMFBnQRw-fLhA%40mail.gmail.com > <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4LX2L155aA6koxFGFmKdBoNoaRYmX83BQMFBnQRw-fLhA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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-6xhMw0UbpO7hL0Lm7bOp1Q%3D2EG6axNcH530BDN_U6i5A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.