Re: [elixir-core:6227] [PROPOSAL] Pipe operator enhancement

2016-08-15 Thread Theron Boerner
You may find these links helpful:


   - *[RFC] Pipe modifiers* —
   
https://groups.google.com/forum/#!searchin/elixir-lang-core/pipe$20argument|sort:relevance/elixir-lang-core/NvZtZco7CeU/HozThRcCTJ0J
   - *Pipe Operator* —
   
https://groups.google.com/forum/#!searchin/elixir-lang-core/pipe$20argument|sort:relevance/elixir-lang-core/jKOJ1zUYwaE/SIKql6ybAQAJ
   - *Pipeline to second argument and precedence of &/1 and ./2* —
   
https://groups.google.com/forum/#!searchin/elixir-lang-core/pipe$20argument|sort:relevance/elixir-lang-
   core/WDePSnaiR5w/frCzs5xbG2wJ
   - *Pipe here operator? *—
   
https://groups.google.com/forum/#!searchin/elixir-lang-core/pipe$20argument|sort:relevance/elixir-lang-core/wTK072BdJus/GOUMaUrEEQAJ


On Mon, Aug 15, 2016 at 10:51 AM Aleff Souza  wrote:

> We all know that the pipe operator is very powerful and elegant, but what
> I think that is annoying sometimes is that it ONLY passes the result to the
> FIRST parameter of the next expression. So, I think it'd be nice to have
> some way where I could choose which parameter the left result would be
> passed.
>
> In Example, given a function foo/3:
>
> "Elixir"
> |> String.upcase
> |> foo(param1, _, param3)
>
> Where '_' is where the result from the previous expression would be passed
> on.
>
> --
> 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/b07c635a-0155-44f2-8fb3-b996f4d33fc7%40googlegroups.com
> 
> .
> 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/CAOtk34e0SqERn9t-APn-cdWW6U8wcY5sXU0hg-hk3F-KLZmaPg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elixir-core:6224] Elixir way to handle errors in pipes

2016-08-15 Thread Alexei Sholik
The Elixir way is to use the pipe and `with` where each is more suitable
for the task. So if you need to write a sequence of function calls where
some or all are expected to return an error, `with` would be the most
appropriate tool to use.

One key difference between a pipeline and `with` is that the latter stops
evaluation as soon as it encounters the first failed match. Whereas with a
pipeline you'd have to wrap all constituent functions to pass the error
from a previous step down to the next one. I see it as a downside to trying
to use the pipe in places where it is more important to explicitly handle
errors.

On Mon, Aug 15, 2016 at 2:12 PM, Alvise Susmel 
wrote:

> Hi,
>
> I've started thinking about this, as maybe many of you, when I needed to
> stop the pipe when an error is returned. I've seen that there are different
> conversation about this, but I haven't clear what is the *elixir way* to
> handle errors using pipes.
>
> I see two ways for achieving the same result.* The first* is to use the
> *pipe* *|>* and for each function catch the error and propagate it down.
> The error has to be always returned with the same pattern, like {:error,
> reason}
>
> connect
> |> receive_image
> |> resize
> |> rotate
> |> save
>
>
> If *receive_image* returns an error,  *resize* needs to handle it
>
> def resize({:error, _}=error), do:error
>
> and to propagate it down through the pipe. So *rotate* needs to do the
> same, etc..
>
> *The* *second* way I see is using the *with*, which to me seems to be
> more generic (and less clean)
>
> with {:ok, pid} <- connect,
>{:ok, image} <- receive_image(pid),
>{:ok, resized_image} <- resize(image),
>   {:ok, rotated_image} <- rotate(resized_image),
>   :ok <- save(rotated_image)
> do: IO.puts "saved"
>
>
> Now, the cool thing about *with* is that when one of the assignments
> fails, it exits returning the value that failed the pattern match.
>
> So, to you, what is the elixir way on handling the return errors on pipes
> ? Could *"with" *be seen as a new (and more generic) way of piping with
> error handling ?
>
> Thanks
>
> Alvise
>
> --
> 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/1dc86df2-eca0-4fa5-b883-
> 7b9c2df36444%40googlegroups.com
> 
> .
> 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/CAAPY6eOixE%3DTyrvFgabb-ErY%2BKOSz52x_A6uNeD_SSDQACEWDA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elixir-core:6223] Elixir way to handle errors in pipes

2016-08-15 Thread Louis Pilfold
Hi!

with is the right tool when you want this kind of error handling in these
function pipelines :)

Cheers,
Louis

On 15 Aug 2016 12:12, "Alvise Susmel"  wrote:

> Hi,
>
> I've started thinking about this, as maybe many of you, when I needed to
> stop the pipe when an error is returned. I've seen that there are different
> conversation about this, but I haven't clear what is the *elixir way* to
> handle errors using pipes.
>
> I see two ways for achieving the same result.* The first* is to use the
> *pipe* *|>* and for each function catch the error and propagate it down.
> The error has to be always returned with the same pattern, like {:error,
> reason}
>
> connect
> |> receive_image
> |> resize
> |> rotate
> |> save
>
>
> If *receive_image* returns an error,  *resize* needs to handle it
>
> def resize({:error, _}=error), do:error
>
> and to propagate it down through the pipe. So *rotate* needs to do the
> same, etc..
>
> *The* *second* way I see is using the *with*, which to me seems to be
> more generic (and less clean)
>
> with {:ok, pid} <- connect,
>{:ok, image} <- receive_image(pid),
>{:ok, resized_image} <- resize(image),
>   {:ok, rotated_image} <- rotate(resized_image),
>   :ok <- save(rotated_image)
> do: IO.puts "saved"
>
>
> Now, the cool thing about *with* is that when one of the assignments
> fails, it exits returning the value that failed the pattern match.
>
> So, to you, what is the elixir way on handling the return errors on pipes
> ? Could *"with" *be seen as a new (and more generic) way of piping with
> error handling ?
>
> Thanks
>
> Alvise
>
> --
> 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/1dc86df2-eca0-4fa5-b883-
> 7b9c2df36444%40googlegroups.com
> 
> .
> 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/CAM-pwt4N2w6sqUOkemo-q--FrZKcrvNBPYMpBMb4A9O2qOWOhQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[elixir-core:6223] Elixir way to handle errors in pipes

2016-08-15 Thread Alvise Susmel
Hi, 

I've started thinking about this, as maybe many of you, when I needed to 
stop the pipe when an error is returned. I've seen that there are different 
conversation about this, but I haven't clear what is the *elixir way* to 
handle errors using pipes. 

I see two ways for achieving the same result.* The first* is to use the 
*pipe* *|>* and for each function catch the error and propagate it down. 
The error has to be always returned with the same pattern, like {:error, 
reason} 

connect
|> receive_image
|> resize
|> rotate
|> save


If *receive_image* returns an error,  *resize* needs to handle it

def resize({:error, _}=error), do:error

and to propagate it down through the pipe. So *rotate* needs to do the 
same, etc..

*The* *second* way I see is using the *with*, which to me seems to be more 
generic (and less clean)

with {:ok, pid} <- connect,
   {:ok, image} <- receive_image(pid),
   {:ok, resized_image} <- resize(image),
  {:ok, rotated_image} <- rotate(resized_image),
  :ok <- save(rotated_image)
do: IO.puts "saved"


Now, the cool thing about *with* is that when one of the assignments fails, 
it exits returning the value that failed the pattern match. 

So, to you, what is the elixir way on handling the return errors on pipes ? 
Could *"with" *be seen as a new (and more generic) way of piping with error 
handling ?

Thanks

Alvise

-- 
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/1dc86df2-eca0-4fa5-b883-7b9c2df36444%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.