Refactoring from the Imperative to the Functional Style

This page was contributed by Venkat Subramaniam under the UPL

This part of the tutorial helps you to learn the functional style equivalent of the imperative style code we often find. As you move forward in your projects, wherever it makes sense, you can change imperative style code to functional style code using the mappings you learn in this tutorial.

In this series we cover the following conversions from the imperative to the functional style:

Tutorial Imperative Style Functional Style Equivalent
Converting Simple Loops for() range() or rangeClosed()
Converting Loops with Steps for(...i = i + ...) iterate() with takeWhile()
Converting foreach with if foreach(...) { if... } stream() with filter()


  1. Converting Simple Loops

    Converting Simple Imperative Loops to Functional Style.

  2. Converting Loops with Steps

    Converting Imperative Loops with Steps to Functional Style.

  3. Converting foreach with if

    Converting Imperative Iteration using foreach with if to Functional Style.



Back to Tutorial List