Skip to content

"Replace Pipeline with a function" isn't quite that #4

@novaugust

Description

@novaugust

Replace pipeline with a function

The given example of "replace a pipeline with a function" is really an example of "use a higher order version of a function to reduce the number of functions called and enumerations performed". The reason I bring this up is that if there were further pipes in the example, the refactor wouldn't remove the pipes - it would simply be changing the function call.

# given
list
|> Enum.filter(&is_foo/1)
|> Enum.count()
|> do_more_work()

# the refactor would be
list
|> Enum.count(&is_foo/1)
|> do_more_work()

adobe's styler tool performs a large number of these optimizing refactors across pipes whenever code is formatted via mix format

(the exact filter |> count implementation is here)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions