This version would be more idiomatic:

`not Enum.empty?(enumerable) and Enum.all?(enumerable, &(&1 == :some))`

If were were to choose a name for the new functions I would go with 
`Enum.every_one?(enumerable, fun)`

On Thu, 21 Jan 2021 07:04:43 +0000
Anil Kulkarni <[email protected]> wrote:

> Given that the functionality is very similar to Enum.all?/2, I would
> suggest one of the following:
> 
> 1) Solve this outside of the core elixir library with something like
> case myList do
>   [] -> false
>   myList -> Enum.all?(myList, &(&1 == :some))
> end
> 
> or
> 
> 2) add a default parameter to Enum.all? to specify the default value
> when the list is empty. E.g.
> defmodule Enum do
>   def all?(list, fun \\ fn x -> x end, default \\ true) do
>    ...
>   end
> end
> 
> Regards,
> Anil
> 
> > On Jan 20, 2021, at 10:39 PM, Randson <[email protected]> wrote:
> > 
> > Hi all, recently I opened I pull request on Elixir repo. Which is:
> > 
> > https://github.com/elixir-lang/elixir/pull/10664
> > 
> > Adding the Enum.every? function on the Enum module.
> > 
> > I had case where, given a list of atoms, all of the needs to return
> > true:
> > 
> > Enum.every?([:some, :some, :some], fn x -> x == :some end)  
> > ...> true  
> > 
> > Enum.every?([])  
> > ...> false  
> > 
> > I tried with functions like Enum.all?/2 and Enum.any?/2. But the
> > cases are follow:
> > 
> > Enum.all?/2 - Returns true in case of an empty list;
> > Enum.any?/2 - Returns false, which is correct but if there is a
> > different value on the list. Probably this will return true.
> > 
> > So I took the name every because I'm used to use like this on JS.
> > But as Valim mentioned on the PR, it could be all_non_empty? or
> > something else.
> > 
> > What do you guys think?
> > 
> > -- 
> > 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/977fcb5e-3d81-4017-b993-7d27a695937an%40googlegroups.com.
> >  
> 
> 

-- 
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/6009777e.1c69fb81.465c3.6c92SMTPIN_ADDED_MISSING%40gmr-mx.google.com.

Reply via email to