Scala provides a concept called partially applied functions that spares you from writing several lines of code. Say, you have a function f that accepts 2 arguments. While invoking f you may have to pass both the arguments. In Scala […]
Continuing with the posts on Scala where we implemented Guessing game in imperative style and a in a couple of ways using the functional style, let’s implement it using pattern matching facility. Pattern matching provided in Scala is one of […]
In the previous post, we created the GuessingGame as a functional object that was immutable. It was a little heavy as every operation resulted in a new object. Let’s refactor it a but and see where we land. All that’s […]
In the earlier post on Scala, we created the Guessing Game class using imperative style. Now you’ve the GuessingGame class implemented using functional style. This is the first attempt in doing that. Couple of points to keep in mind here […]
Here’s a simple guessing game program using Scala’s imperative style and not functional style. class GuessingGame{ private var target:Int = (Math.random()*100).asInstanceOf[Int] var attempts:Int = 0 var message:String = "" var gameOver:Boolean = false def play(guess:Int):Unit= { attempts += 1 if(guess […]