ITADN

Alternative implementation idea using comma operator.

#308Closedhaydenlauer 创建于 2024-11-27
H
haydenlauercommented
Instead of making a pipeline operator we make an expression-scoped variable assignment operator, and then use the comma operator to achieve the pipeline functionality. I think this may give us the best of both worlds. ``` value |>x, foo(32,x) ``` This lets you name variables like the F# style but also lets you use arbitrary expressions like the hack style. As an added benefit, you can access any previously defined variable like so: ``` max-min |> range, pos-min|>pos1, console.log(pos1,range), pos1/range*100 |> percent, percent>50 ``` Also because it uses the existing comma operator, any performance issues or conflicts with other proposals are pre-existing. The only performance hit would be from expression-scoped variables which I would think should be equivalent to this: ``` (()=>{ let range=max-min; let pos1=pos-min; console.log(pos1,range); let percent=pos1/range*100; return percent>50})(); ``` Side note: it would be nice if the |> could be used without commas, but that might be harder to implement: ``` (pos2/(max-min|>range)-pos1/range) ```
关闭于 2025-01-03 27 条评论