DEV Community

Discussion on: Functional Programming: Composition of Functions

Collapse
pengeszikra profile image
Peter Vivo

Why we don't use proposal pipeline operator? Which is give composition without any library or helper function, and very useful in multiple case.

42 |> f |> g;
Enter fullscreen mode Exit fullscreen mode

Pipeline operator handy even simple log:

data |> functionForTest |> console.log;
Enter fullscreen mode Exit fullscreen mode

in react also handy this syntax sugar.

  const getTextAreaValue = ({target:{value}}) => value;
  <TextArea onChange={event => event |> getTextAreaValue |> myAction}</TextArea>
Enter fullscreen mode Exit fullscreen mode

or better

  const inputFromTextArea = action => ({target:{value}}) => value |> action;
  <TextArea onChange={myAction |> inputFromTextArea}</TextArea>
Enter fullscreen mode Exit fullscreen mode
Collapse
vonheikemen profile image
Heiker

I think there are two proposals for the pipeline operator. There is one where the operator behaves exactly like pipe() and the other proposal adds more features to it (they call it smart pipeline).

I like the idea of the simple pipeline but I imagine that a large part of the javascript community would not like such a limited feature. It would force them to learn about partial application, unary functions, and currying; in other words it would impose a specific style of programming on them. If it doesn't make their life easier they would just ignore it.

Collapse
pratiksharm profile image
Pratik sharma Author

Thanks to both of you! I was not aware of this new experimental pipeline operator. I like the syntax that peter has used. as per the current mozilla docs it is still in stage 1, so i don't think we can use the operator just for now. Operators have made our life easier a bit, so much time i use ? : , then using if else. I think we are moving to more simplified and less bracket world of programming.

Thread Thread
pengeszikra profile image
Peter Vivo

If you would try pipeline operator, then you found in this parcel bunlder setup: github.com/Pengeszikra/react-base , react can easy remove from this.
Eslint give correct result. But one more trick for VS-Code don't show error in

"javascript.validate.enable": false,
Enter fullscreen mode Exit fullscreen mode
Thread Thread
pratiksharm profile image
Pratik sharma Author

Sure will give it a try!