Off late, I have been learning Haskell programming language. Suddenly the thought of how Fizz Buzz would look like in Haskell strike my mind.
After 5 minutes, a working version using guards and map was ready.
1 2 3 4 5 6
Then simply mapping the function to a range of first 100 was enough.
The beauty is the ability to chain multiple functions and get a working program. More or less the similar is possible in imperative languages as well. But, imagine a scenario where one need to know how many numbers are there which are divisible by both 3 and 5. Same can be obtained from the FizzBuzz function, just by chaining two more functions.
This may be a bad example of reusing function, but one gets the point. Just like the *NIX shell’s ability to chain multiple programs and get the output quickly and elegantly.