DEV Community

Discussion on: Introduction to Functional Programming

Collapse
 
jackmellis profile image
Jack

Agreed. I can only assume that first example because it's logging to the console (side effect).

Yes there can be minimal impure functions because otherwise your code would do nothing. But I'd say if a function is impure, you should look for a way to make it pure, and only leave it impure as a last resort, most of the time function composition/partial application is the key.

Your greet function I would pass the console in as a parameter. Even better would be to create an abstraction over logging to the console so your function isn't coupled to the console implementation!

Collapse
 
cappe987 profile image
Casper

Yes of course you could improve the function. I just put his code in a function to show as example.