[elixir-core:8895] Re: [Proposal] identity function

2019-07-02 Thread Vadim Safonov
+1 would be very convenient

вторник, 2 июля 2019 г., 12:23:47 UTC+3 пользователь Alexey Nikitin написал:
>
> Like Haskell's `id` or Clojure's `identity` or Ruby's `itself`
>
> It can be very useful sometimes. Instead of writing ugly `&(&1)` it would 
> much more attractive to write `&identity/1` or `&id\1`
> Moreover this function is already used as a default argument for some 
> higher-order function. For example `Enum.group_by(enumerable, key_fun, 
> value_fun \\ fn x -> x end)`
>
> Here are some examples
>
> ```
> #=> [1, 2, 3, true, 1234] 
>
> 'abcdaabccc' |> Enum.sort |> Enum.chunk_by(&identity/1) 
> #=> ['aaa', 'bb', '', 'd'] 
>
> [1, 1, 2, 3, 3, 1, 1, 5, 5] |> Enum.chunk_by(&identity/1) |> 
> Enum.map(&hd/1) 
> #=> [1, 2, 3, 1, 5] 
>
> Enum.group_by('abracadabra', &identity/1) 
> #=> %{97 => 'a', 98 => 'bb', 99 => 'c', 100 => 'd', 114 => 'rr'} 
>
> Enum.map([1, 2, 3, 4], &identity/1) 
> #=> [1, 2, 3, 4]
> [1,2,3,nil, true, false, 1234] |> Enum.filter(&identity/1) 
> ```
>

-- 
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/d965b4bb-21f1-46be-8852-aad06b7347c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elixir-core:8895] Re: [Proposal] identity function

2019-07-02 Thread Christopher Keele
Derp, I knew that. Good point.

On Tue, Jul 2, 2019 at 9:55 AM Michał Muskała  wrote:

> Because Elixir is a lisp-2 language, variables and functions are in
> different "namespaces". This means you can have local variables with names
> of local functions without any issues, but it also means you need different
> syntax when you want to call a function contained in a variable. Or
> formulated differently - variables can't shadow functions. For example,
> consider:
>
> bar = &foo/0
> bar.() #=> 1
> bar() #=> 2
> def foo(), do: 1def bar(), do: 2
>
> Having a Kernel.id/1 function would not preclude you from using variables 
> called id.
>
>
> Michał.
> On 2 Jul 2019, 18:41 +0200, Christopher Keele ,
> wrote:
>
> I'd cast my vote against this. The proposal seems to be:
>
> 1. Create a function named 'id' or some such
> 2. Put it in the Kernel namespace (so it need not be prefixed)
>
> I've been doing a lot of python lately and they have a lot of things like
> this, including the same 'filter' global function mentioned in this thread.
>
> Points against:
>
> 1. It'd suck to not be able to use 'id' as a variable name, and would
> conflict with a lot of existing code.
> 2. Alternative names to 'id' or namespacing it are not shorter than '&(&1)'
> 3. '&(&1)' is more open to change with requirements
> 4. Adopting 'id' within Kernel would encourage adding more utility
> functions to it, exacerbating 1, like the proposed 'filter' function
> 5. Not adopting it within the Kernel would be hard, as there's no real
> appropriate place for it elsewhere in standard lib, unlike Enum's 'filter'
>
> Generally it's a nice idea, but I can't think of a great way to make it
> work, and it'd open the floodgates to more utility functions that I've come
> to find grating in day-to-day python development.
>
> Just my two cents,
> Chris K
>
> --
> 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/fffd5b76-4385-40de-93bd-148f1b94bb27%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "elixir-lang-core" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/elixir-lang-core/tB61BHYIH1s/unsubscribe
> .
> To unsubscribe from this group and all its topics, 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/b2149582-b8ba-4759-99ac-a634f73f3243%40Spark
> 
> .
> 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/CAD9kT2R41gmZXU9_YAqAdyJQDP-M37j-mgUet-okoeBzF%3DdMDA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.