DEV Community

Cover image for Functional Programming: Composition of Functions

Functional Programming: Composition of Functions

Pratik sharma on May 15, 2021

Input of one function comes from the output of another function. πŸ‘† simple defination of function composition that i could find. In functiona P...
Collapse
 
algorhymer profile image
sassenheimer

You see... I cannot even write a technical comment - without the platform dropping it - anymore.

You know... some days ago I made a comment where I introduced the concept of Z-combinator for call-by-value languages for the author of an article.
I used that Cat from Shrek El Gato con Botas to weave it into a Zorro narrative.
Well that got deleted too.

Dev.to nowadays is sort of like a crossbreed of the movie Idiocracy and 1984.
A sort of... really heavy marketing-only, corporate, adultkindergarten.

Collapse
 
biomathcode profile image
Pratik sharma

That's true to some level, I don't know why you comment got delete, maybe because of too long or similar to how youtube AI detector is not working correctly. Explaing with analogy is the best way to learn.
Software domain is just sad rn and dieing faster and i would have thought

Collapse
 
algorhymer profile image
sassenheimer

You should check your Github Issues.
You have a message waiting for you.

Thread Thread
 
biomathcode profile image
Pratik sharma

ohh thanks for the problem to solve. But i don't want to compete with ThePrimeagen.

Thread Thread
 
algorhymer profile image
sassenheimer

Please... pretty please do it.
That guy's code can beaten from Python (vs. Rust release build, optimized).

Thread Thread
 
algorhymer profile image
sassenheimer

@biomathcode I've been looking for a single dev for 2 years... I'm running out of Jon Snows.

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
 
biomathcode profile image
Pratik sharma

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
 
biomathcode profile image
Pratik sharma

Sure will give it a try!