Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Idea: pipe_safe/2 for cleaner piping. #19

Open
zachdaniel opened this issue Nov 10, 2018 · 0 comments
Open

Idea: pipe_safe/2 for cleaner piping. #19

zachdaniel opened this issue Nov 10, 2018 · 0 comments
Assignees

Comments

@zachdaniel
Copy link

zachdaniel commented Nov 10, 2018

For this I'll use a similar example to the one you used for Make Safe in the readme.

def max_of_row(nested_array, x, y) do
  toothless_fetch = safe(&Enum.fetch!/2)
  toothless_max = safe(&Enum.max/1)
  
  array
  ~> toothless_fetch(index)
  ~> toothless_max()
end

I think it would be great for readability if I could just say:

def max_of_row(nested_array, x) do
  array
  ~> pipe_safe(&Enum.fetch!(&1, x))
  ~> pipe_safe(&Enum.max/1)
end

If safe/2 didn't exist, then we would have been able to adapt the existing function to serve that purpose, but we would have to introduce a new name (or a new operator) to do it from where it is now.

As an operator (which I'm not necessarily advocating for, just including it for completeness' sake), that might look like

def max_of_row(nested_array, x) do
  array
  ~~> Enum.fetch!(x)
  ~~> Enum.max()
end
@expede expede self-assigned this Feb 14, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants