O'Reilly logo

Functional Programming: A PragPub Anthology by Michael Swaine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

What’s Different About This Code

When you write in a language such as Java, C#, or Ruby, you’re working at a number of levels simultaneously. Part of your brain is thinking about the specification—what has to get done. The other part is thinking about the implementation—the nuts and bolts of how to do it. And that’s where things often get bogged down.

But look at that last example. We’re iterating over a set of digits. We’re selecting those with odd or even positions. We’re performing conditional calculations. We’re summing the result. And there isn’t a single control structure in the program. No ifs, no loops. The code pretty much reflects the specification of what we want to happen.

And that’s one of the reasons I’m a fan of functional ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required