Scala : No More Looping
This blog is more targeted to the Scala beginners. Scala is a functional programming language, to be clear it is EXPRESSIONS kind of language while language like Java is more imperative programming language. It is more kind of creating instructions/tasks for a program. Let me explain this concept with example of loops.

Java has a concept of loops.Like for , while . In Scala, creating while loops is considered as a bad practice.

For an example, look at the following code snippet

var a = 42 while(a < 100) {

println("Hey, I am in a loop")

a += 1

}

This way of writing a while loop, is an imperative way (Instructions like in JAVA).

In Scala, we try to think everything functionally. Rather than thinking like, how to loop over a collection, try to think like How you can transform a collection that you are looking for. For example, let me rewrite the above while loop more functional way

(42 until 100).foreach(_ => println("Hey, I am now looping correctly"))

Let me give more example of how to transform a collection in scala

List(1,2,3).map(_ * 2) // List(2,4,6)

List(1,2,3).flatMap(x => List(x, x+1) // List(1,2,2,3,3,4)

List(1,2,3,4).filter( _ % 2 ==0 ) // List(2,4)

In above example, I am transforming my collection to what I want using Higher Order Functions. There are few more functions like fold, sum, reduce, find, count

Conclusion:
['Neel Desai']
['Java', 'Functional Programming', 'Scala', 'Scala Programming']