Agreed, and I have them in my own libraries. Thought they might be useful 
to others :)

On Thursday, May 19, 2016 at 2:57:39 PM UTC-7, Andrea Leopardi wrote:
>
> Hey Chris,
>
> thanks for your proposal! Personally, I'm not a fan of adding such 
> functions. I feel they assume too much; why limit to only :ok and :error? 
> They of course are common in Elixir/Erlang, but one may want to return 
> {:value, something} or :no_values, or any other API that doesn't use :ok 
> and :error. Also, it's a bit restrictive to assume that we want to return 
> {:ok, something} instead of something like {:ok, something, something_else} 
> (this is what your implementation in 
> https://github.com/elixir-lang/elixir/pull/4650 assumed at least).
>
> It's really trivial to implement such helper functions like these that can 
> be specific to your project, so I think that's where these belong :).
>
> Andrea
>
>
> Andrea Leopardi
> [email protected] <javascript:>
>
> On Thu, May 19, 2016 at 11:47 PM, Chris <[email protected] <javascript:>
> > wrote:
>
>> These are a couple of small wrapper functions which I think would be very 
>> useful to developers. They create an idiomatic pathway for returning tuples 
>> from a pipeline.
>>
>>
>> The intended use case is in any module-level function that is entirely a 
>> pipeline, and where you would like to return the value that is the result 
>> of a pipeline of functions in tuple form, and
>> where you know the result of your pipeline will be either :ok or :error 
>> with certainty.
>>
>> For a simplistic example, suppose I have a list of ids and I write a 
>> simple function to take the first id and return it in an
>> :ok tuple. Normally I would have to do something like this:
>>
>>
>> def return_first(id_list) do
>>   first_id = id_list |> List.first!()
>>   {:ok, first_id}
>> end
>>
>>
>> And that is okay, but somehow it doesn't *feel* like idiomatic
>> Elixir. Here you could just do this:
>>
>>
>> def return_first(id_list), do: id_list |> List.first!() |> put_ok()
>>
>>
>> To me, that feels a lot cleaner and clearer. It allows me to express my 
>> intention the in a way that feels closer to how Elixir
>> asks me to think about programming.
>>
>> -- 
>> 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] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elixir-lang-core/60d8054e-7f88-48ad-9ead-5ccc8ba1eccf%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/elixir-lang-core/60d8054e-7f88-48ad-9ead-5ccc8ba1eccf%40googlegroups.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/e457c985-88d9-4362-8810-08baaa906880%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to