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
// https://blog.stackmob.com/2013/01/resources-for-getting-started-with-functional-programming-and-scala/ | |
import scala._ | |
println | |
println( "https://blog.stackmob.com/2013/01/resources-for-getting-started-with-functional-programming-and-scala/" ) | |
println | |
println( "First Class Functions" ) | |
println( "This means that functions are basic types and can be passed around just like integers or strings." ) |
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
//Reads only sector with sequence of industries | |
implicit val secteurReads: Reads[Secteur] = ( | |
( __ \ "name" ).read[String] ~ | |
( __ \ "industry" ).lazyRead( play.api.libs.json.Reads.seq[Industrie] ) | |
)( Secteur ) | |
//Reads sector with sequence of industries or an only object industry | |
implicit val secteurReads: Reads[Secteur] = ( |
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
def total2Chunks: Iteratee[Int, Int] = { | |
// `step` est la fonction qui consomme et qui reçoit le contexte précédent (idx, total) ainsi que le chunk courant | |
// context : (idx, total) idx est l'index pour compter les itérations | |
def step(idx: Int, total: Int)(i: Input[Int]): Iteratee[Int, Int] = i match { | |
// chunk vaut EOF ou Empty => on stoppe l'itération en déclenchant l'état Done avec le total courant | |
case Input.EOF | Input.Empty => Done(total, Input.EOF) | |
// un chunck a été trouvé | |
case Input.El(e) => | |
// si c'est le 1er ou 2ème chunk, appeler `step` à nouveau en incrémentant idx et en calculant le nouveau total | |
if(idx < 2) Cont[Int, Int](i => step(idx+1, total + e)(i)) |
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
public boolean checkInteger(String testInteger) { | |
/* | |
* The function must check that a given string is | |
* | |
* an integer | |
* not the empty string or null | |
* an integer greater than 10 | |
* an integer between 2 and 100000 inclusive | |
* That the first digit is 3. | |
*/ |
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
package master.util; | |
import java.lang.management.*; | |
public class Benchmark { | |
private static final ThreadMXBean tmbean = | |
ManagementFactory.getThreadMXBean(); | |
private static final long CONVERSION = 1000 * 1000; | |
private long cpuTime; |
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
/conf/secteurs.json | |
{ | |
"query": | |
{ | |
"count":9, | |
"created":"2013-06-03T12:35:25Z", | |
"lang":"en-US", | |
"results": | |
{ | |
"sector":[ |
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
def sortList(list: List[Int]): List[Int] = list match { | |
case Nil => Nil | |
case head :: tail => sortList(tail.filter(_ < head)) ::: head :: sortList(tail.filter(_ >= head)) | |
} |
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
package extraction.mapping | |
import scala.io.Source | |
/** | |
* . | |
* Realizes the mapping between fields in double lateral way | |
* example : toto => totototo | |
* User: Francois | |
*/ |
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
/** | |
* . | |
* Trying to parse a double | |
* @param s string to parse | |
* @return the double | |
*/ | |
def parseDouble(s: String): Option[Double] = { | |
try { | |
Some(s.replaceAll("[^0-9]", "").toDouble) | |
} catch { |
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
What is the result of executing the following code? | |
List(1, 2).map { i => i + 1 } | |
List(1, 2).map { _ + 1 } | |
List(1, 2).map { i => println("Hi"); i + 1 } | |
List(1, 2).map { println("Hi"); _ + 1 } | |