Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Pipeline or temporary var storage? #94

Closed
stephaneraynaud opened this issue Feb 8, 2018 · 3 comments
Closed

Pipeline or temporary var storage? #94

stephaneraynaud opened this issue Feb 8, 2018 · 3 comments

Comments

@stephaneraynaud
Copy link

stephaneraynaud commented Feb 8, 2018

Pipeline operator general purpose is to obtain better readability from chain3(chain2(chain1(value))) to value |> chain1 |> chain2 |> chain3.

Currently, without pipeline operator, we can do something like:

let value;
let chained1 = chain1(value);
let chained2 = chain2(chained1);
let chained3 = chain3(chained2);

From my understanding, pipe is about putting something into a temporary var and using this var later in the same expression.

Pipe is something about:

set(value) then
set(chain1(get())) then
set(chain2(get())) then
chain3(get())

Why not think about an operator whose global purpose would be to set a var into a temp variable then reusing it later?

Note: i'm using for set, for get and , for then, but it may not be the best proposal.

// Value is stored, then the stored value is checked.
let visible = value↑, ( != null && !.hidden);

pipeline would be:

value↑, chain1(), chain2(), chain3();

we can store variable at any time:

// Value is stored and used inside doSomethingWithValue
let something = console.log(array.filter(value↑)), doSomethingWithValue( * 2); 

and why not imagine storing vars with identifiers:

let myFilteredArray = myParameters↑p, anArray↑a, ↓a.filter(↓p);

It may be even more applications to such an operator.

It may seems to be a lot like the pipeline operator, but the purpose of this issue is to think wider about an operator that could be used in a less constrained way.
What do you think?

@js-choi
Copy link
Collaborator

js-choi commented Feb 8, 2018

If you’re doing nested explicit variable bindings, then do expressions would be usable here, wouldn’t they?

let myFilteredArray = do { const p = myParameters, a = anArray; a.filter(p) };

@stephaneraynaud
Copy link
Author

This
#95
and
https://github.com/gilbert/proposal-temporary-bindings
and
#89 (comment)
is quite related to what I proposed.

@tabatkins
Copy link
Collaborator

Closing this issue, as the proposal has advanced to stage 2 with Hack-style syntax. Also, see https://github.com/tc39/proposal-pipeline-operator/blob/master/README.md#temporary-variables-are-often-tedious for a more direct argument on this topic.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants