Intellij Idea for Scala

I am using IntelliJ more than 5 years now and eventually became a fan of that. I used both Ultimate edition and community edition. The community edition Scala plugin is well established now compared to 2 years back. However, there are a number of important productivity topics to discuss here.

Copy Scala worksheet

For example, I want to copy the Scala worksheet to the text editor sublime. Here the steps you need to follow
1. in the IntelliJ, enable column selection mode by CMD+SHIFT+8
2. Select the text you want to copy (for example first the left side of the split screen where Scala source is available)
3. Paste the copied text sublime new file CMD + N
4. In the Sublime now press the CMD + OPTION + F to search and replace.
5. Enable the regex, and search the $ (end of the line) and replace <space>//<space> and click the replace all.
6. Now back to the IntelliJ Idea and selecting the other side ( right side of the split screen where the results are) after CMD+SHIFT+8.
7. In the Sublime, in the same file find all based on the $ by pressing CMD+f only and CMD+v to paste the contents. Your output will look like the following

def fact(n:Int):Int = if (n <= 0) 1 else n*fact(n-1)        // fact: fact[](val n: Int) => Int                        
fact(3)                                                     // res0: Int = 6                                          
                                                            //                                                        
def sum(n:Int*) = {                                         // sum: sum[](val n: Int*) => Int                         
  var r: Int = 0                                            //                                                        
  for (i <- n){                                             //                                                        
    r += i                                                  //                                                        
  }                                                         //                                                        
  r                                                         //                                                        
}                                                           //                                                        
                                                            //                                                        
sum(1,2,3,4,5)                                              // res1: Int = 15                                         
sum(1 to 5: _*)                                             // res2: Int = 15                                         
                                                            //                                                        
                                                            //                                                        
def isVowel(c:Char) = "aeiou".contains(c)                   // isVowel: isVowel[](val c: Char) => Boolean             
                                                            //                                                        
def vowel(s:String) = for (ch <- s if isVowel(ch)) yield ch // vowel: vowel[](val s: String) => String                
                                                            //                                                        
vowel("Nicaragua")                                          // res3: String = iaaua                                   
                                                            //                                                        
val nums = new Array[Int](10)                               // nums: Array[Int] = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0) 
for (i <- 0 until nums.length ) nums(i) = i                 // res4: Unit = ()                                        
nums                                                        // res5: Array[Int] = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) 

Yet to be more

Comments

Popular posts from this blog

How To: GitHub projects in Spring Tool Suite

Spring 3 Part 7: Spring with Databases

Parse the namespace based XML using Python