Skip to content

Instantly share code, notes, and snippets.

@guillaumebort
Created June 15, 2011 14:25
Show Gist options
  • Save guillaumebort/1027217 to your computer and use it in GitHub Desktop.
Save guillaumebort/1027217 to your computer and use it in GitHub Desktop.
Yop
// 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