Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kefniark
Copy link
Contributor

@kefniark kefniark commented May 5, 2021

Description

To avoid heavy nesting, add a pipe operator |> which allow to chain expression together

The 2 following expression are totally equivalent

Without

a = List.sort(List.map(List.filter([1,2,4,5,6], (val) => val < 5), (val) => 10 / val))
  • Can lead to long expression, hard to read
  • Can be hard to know how many parentheses are needed at the end of the line
  • Hard to see which lambda is used by which function

With Pipe |>

a = [1,2,4,5,6]
  |> List.filter($, (val) => val < 5)
  |> List.map($, (val) => 10 / val)
  |> List.sort($)
  • the $ is used as the replacement to the result of the previous Expression in the chain (compatible with any existing function)
  • more verbose but each expression is now separated and easier to read
  • a will be = to the result of the last line

@sonarqubecloud
Copy link

sonarqubecloud bot commented May 5, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@kefniark kefniark merged commit 777bd3d into develop May 5, 2021
@kefniark kefniark deleted the feature/pipeOperator branch May 9, 2021 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants