DEV Community

Discussion on: Intro To Functional Programming

Collapse
 
jcshartz profile image
jcshartz

I'd love to see some functional programming patterns that deal with async operations, such as networking.

Collapse
 
kvsm profile image
Kevin Smith 🏴󠁧󠁢󠁳󠁣󠁴󠁿 • Edited

The short answer to this is that those type of operations (side effects), are dealt with by pushing them out to the edges of your code, by extracting them from the core logic of your program and evaluating them lazily.

An example of this is making a network request for some data which you then have to do some processing on. We can return something like a Promise which allows us to define the processing we want to do with whatever the result might be, and only execute that Promise at a later time.

Unfortunately the short answer still leaves a lot of questions which are best answered by a more in depth look at topics like Option/Maybe types. I've just started a series on basic functional topics and hopefully I'll eventually get to covering more advanced topics too.

Collapse
 
siy profile image
Sergiy Yevtushenko

Promises, probably, one of the most convenient patterns for async code. And they are FP as well.