DEV Community

Wade Zimmerman
Wade Zimmerman

Posted on

7

JS Pipeline Operator

What are your thoughts on the new Pipeline operator being proposed for JavaScript?

Currently they are working out the flavor of the syntax. Looks like it's between Hack and F# syntax.

Hack Flavor

Provides explicit placeholders. The operation pipes the previous result to the parameter holding the % sign.

value |> one(%) |> two(%) |> three(%)

value 
|> one('foo', %) 
|> two('bar', %) 
|> three('baz', %)
Enter fullscreen mode Exit fullscreen mode

F# Flavor

Provides implicit syntax but could easily be paired with lambdas for more complex pipelines.

value |> one |> two |> three

value 
|> x => one('foo', x) 
|> x => two('bar', x) 
|> x => three('baz', x)
Enter fullscreen mode Exit fullscreen mode

My Hot Take

Personally I don't like the Hack Flavor. I mainly crave the implicit syntax from F#. Adding an explicit special character to act as a placeholder seems rather annoying.

However, it sounds like the F# flavor comes with some performance pitfalls and could be more difficult to use with async code.

What do you think?

Top comments (4)

Collapse
 
vaiton profile image
VaiTon

I think Kotlin did it the right way with .let. The default lambda parameter is it, but you can change it for clarity.

kotlinlang.org/docs/lambdas.html#i...

Collapse
 
mistval profile image
Randall

I tend to be pretty conservative about adding new language syntax because I feel the costs in terms of learning curve and cognitive load aren't always worth it.

I think this feature is one of those that complicates the language without giving us enough utility in return. It makes some code a bit more concise is all.

Maybe I should just go and use Go instead 🙃

Collapse
 
jankapunkt profile image
Jan Küster 🔥

F# Syntax feels more intuitive and more like function composition.

Collapse
 
archijain profile image
archi-jain

But I think it makes code easier to understand for beginners

11 Tips That Make You a Better Typescript Programmer

typescript

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields

...

Read the whole post now!

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay