DEV Community

Discussion on: Functional programming for your everyday javascript: Composition techniques

Collapse
 
aminnairi profile image
Amin

Hi Heiker,

In your article, you wrote this

$ cat .env | grep "HOST=.*"

Which is strictly equivalent to this when it comes to the output result.

$ grep "HOST=.*" .env

But is way different in the way it operates. See, when you are using a pipe in Shell, you are actually invoking another process, this is unnecessary because grep takes an input which can be a file, thus preventing the need for another process to pass the stdout of cat to the stdin of grep (which is what happens behind the scene when using the pipe operator).

So I'm not bombing your article just because of this, it's just a friendly reminder on what you can improve in this code. Actually I do it a lot of time and even now, but hey, if I can learn something to you or the reader I won't mind, plus it can save you some resources when used in large scripts or files.

By the way, really cool what you did with Monads and Maybe (reminds me a bit of the Rust API).

Collapse
 
vonheikemen profile image
Heiker

Thank you for your feedback. I appreciate the information.

I'm aware that cat is not necessary I just needed to compose three functions in every version of the example. I have added a link to your comment in the note I put before the code, so people know what is the correct use of grep.

By the way, really cool what you did with Monads and Maybe (reminds me a bit of the Rust API).

That's cool because I got the idea of making these types of articles because I saw that Rust takes some ideas from functional programming and uses them in a really smart way. I thought that if they are useful in Rust then they can be useful in javascript.