Could we see some example usage?

On Thu, Jul 28, 2016 at 8:12 AM Michał Muskała <[email protected]> wrote:

> Filter would work for my case as well, but in general those are different.
> Should we add both or select just one?
>
> Michał.
>
> On 28 Jul 2016, at 17:03, José Valim <[email protected]>
> wrote:
>
> Why not make it a filter that applies it to all matching?
>
> On Thursday, July 28, 2016, Michał Muskała <[email protected]> wrote:
>
>> Hello everybody,
>>
>> I’d like to propose adding a new accessor function to Access -
>> Access.find/1. It works exactly like Access.at/1 <http://access.at/1>,
>> but instead of accessing an element by index (with Enum.at/1
>> <http://enum.at/1>), you can provide an arbitrary function that will be
>> used with Enum.find/2 to match the proper value.
>> I implemented this function in a project, since I needed it. Maybe it
>> would be generally useful? The implementation is rather simple:
>>
>>   def find(fun) when is_function(fun, 1) do
>>     fn(op, data, next) -> find(op, data, fun, next) end
>>   end
>>
>>   defp find(:get, data, fun, next) when is_list(data) do
>>     data |> Enum.find(fun) |> next.()
>>   end
>>
>>   defp find(:get_and_update, data, fun, next) when is_list(data) do
>>     case Enum.split_while(data, &(not fun.(&1))) do
>>       {preceding, []} ->
>>         {nil, preceding}
>>       {preceding, [elem | following]} ->
>>         case next.(elem) do
>>           {get, update} -> {get,  preceding ++ [update] ++ following}
>>           :pop          -> {elem, preceding ++ following}
>>         end
>>     end
>>   end
>>
>>   defp find(_op, data, _fun, _next) do
>>     raise "Access.find/1 expected a list, got: #{inspect data}"
>>   end
>>
>> Michał.
>>
>> --
>> 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/434356A9-EF6A-47F9-BEEB-0C7D4054B2F1%40muskala.eu
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
>
>
> *José Valim*
> www.plataformatec.com.br
> Skype: jv.ptec
> Founder and Director of R&D
>
>
> --
> 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/CAGnRm4L5yW9X%2BOFoq3S5ffs%3DMwbUXWrc4cbze9foKKDTsXo-Jg%40mail.gmail.com
> <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4L5yW9X%2BOFoq3S5ffs%3DMwbUXWrc4cbze9foKKDTsXo-Jg%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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/012DDE26-62B1-46C1-AA49-6945A75F47A5%40muskala.eu
> <https://groups.google.com/d/msgid/elixir-lang-core/012DDE26-62B1-46C1-AA49-6945A75F47A5%40muskala.eu?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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAOMhEnwagGsu0e_vvv_bmkV24gBKR-cFH3T%2BdVeH1XD2BUxT3w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to