Created
June 15, 2011 14:25
-
-
Save guillaumebort/1027217 to your computer and use it in GitHub Desktop.
Yop
This file contains hidden or 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
// prime number generator | |
for (i <- 2 to 1000) | |
if((2 to i).find( j=> (i % j == 0 && i != j) ) == None) | |
println(i) | |
// function currying example | |
def matcher(haystack: List[Char])(needle: String) = { | |
haystack contains needle.charAt(0) | |
} | |
def isInitialUpperCase = matcher(List('A','B','C','D','E','F','G','H','I','L','M','N','O','P','Q','R','S','T','U','V','Z')) _ | |
isInitialUpperCase("Fe") | |
val upperCased = { | |
if (isInitialUpperCase("fe")) "fe" | |
else "Fe" | |
} | |
List("Federico","federico","Andrea").filter(isInitialUpperCase) | |
// immutability | |
val x = 2 | |
var mutableX = 3 | |
mutableX = 4; // yes | |
val m = Map("1" -> "one") | |
m("1") = "ONE"; // it does work, but it's not assigning, it's returning a new Map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment