Created
June 28, 2011 18:00
-
-
Save 8th-Light-Blog/1051734 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Blog Title: A Functional Refactoring in Scala | |
Author: Colin Jones | |
Date: June 16th, 2009 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def printUpTo(limit: Int): Unit = | |
{ | |
var i = 0 | |
while(i <= limit) | |
{ | |
println("i = " + i) | |
i += 1 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void printUpTo(int limit) | |
{ | |
for(int i = 0; i <= limit, i++) | |
{ | |
System.out.println("i = " + i) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def printUpTo(limit: Int): Unit = { | |
for(i <- (0 to limit)) { | |
println("i = " + i) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def printUpTo(limit: Int): Unit = { | |
(0 to limit).foreach { | |
i => println("i = " + i) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def printUpTo(limit: Int): Unit = { | |
applyUpTo(limit, println) | |
} | |
def applyUpTo(limit: Int, action: String => Unit): Unit = { | |
(0 to limit).foreach { | |
i => action("i = " + i) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def printUpTo(limit: Int): Unit = { | |
buildUpTo(limit).foreach(println) | |
} | |
def buildUpTo(limit: Int): Iterable[String] = { | |
(0 to limit).map("i = " + _) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment