Functional programming, which means using functions to derive results.

Imperative (Non-functional): Tells you how to got the answer from A to B.

If you need to use the sum functionality again, you probably have reused the code somewhere else.

Declarative (Functional): We don’t care about whole process but the result

  • Ensures no mutability or no change in state when used, no explicit state management
  • Modularity
  • Fever lines of code

We are going to understand what goes under the hood of filter function.


Imperative way to find even numbers in array:

Declarative way to find even number in array: (with built-in method)

We will try to create filter function:

But, it doesn’t make sense to create a distinct function just for Int only. Let us utilize the Swift generics.

Purest form of filter:

Software engineer @huawei , musician

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store