rust-lang / rust-lang/rfcs

Piping data to functions

Open
#2,049 57 comments 62 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-lang
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

Something I've seen elsewhere is the concept of piping data to functions, which can drastically increase readability in cases where someone would either use intermediate variables or call functions as parameters.

Pseudocode for a contrived example:

x = {1,-7,-5,3}

// Without pipes, intermediate variables.

a = sum(x)
b = abs(a)
c = sqrt(b)
result = round(c, 2)


// Without pipes, nesting functions.

result = round(sqrt(abs(sum(x))), 2)


// With pipes the result on the left of the pipe is passed as the first parameter
//of the function on the right, allowing the code to be read left to right.

result = x %>% sum() %>% abs() %>% sqrt() %>% round(2)


// It's particularly nice for splitting code across lines

result = 
  x %>% 
  sum() %>% 
  abs() %>% 
  sqrt() %>% 
  round(2)

The %>% operator is just an example (from R), it could be something else

I'm just learning rust, and know nothing about language development, so the complexities involved might make this impractical. At the same time, it would also be really interesting to see how something like this could be incorporated to work with tuples and multiple return values.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files, tests, or implementation entry points are named. Start by reviewing the proposed pipe semantics and the discussion around tuples and multiple return values; done would require a settled design suitable for an RFC.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.