Yes, would be really handy to have these features for .filter and .reject

четверг, 17 ноября 2016 г., 18:35:59 UTC+3 пользователь Bruce Tate написал:
>
> Every couple of months, we get a request for Enum.compact. So far, the 
> main argument against it is that Enum.reject list, &is_nil/1 is sufficient. 
>
> When you compare the difference in a pipe, you can see a significant 
> difference in readability. 
>
> It really is a pervasive use case. 
>
> list
> |> nil_or_result
> |> compact
>
> versus
>
> list 
> |> nil_or_result
> |> reject(&isnil/1)
>
>
>
> One possible solution is for Enum.reject to take a default function as an 
> argument. I suggest a default of  fn(x) -> x end
>
> That would make the above example: 
>
> list
> |> nil_or_result
> |> reject
>
>
> which reads just fine, I think. There is ample precedent for meaningful 
> defaults in enum. is_nil/1 and &(&1) are meaningful defaults. 
>
> Thoughts? 
>
> -bt
> -- 
> Bruce Tate
> President, RapidRed, LLC
> Phone: 512.772.4312
> Fax: 512 857-0415
>
> Author of Seven Languages in Seven Weeks, Deploying Rails Applications, 
> From Java to Ruby, Rails: Up and Running, Beyond Java, 6 others.
>

-- 
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/89f68fae-4534-4c28-a4b7-95ff89041599%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to