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
const config = { | |
typeDirs: [ | |
{ type: "pdf", directory: "documents" }, | |
{ type: "png", directory: "images" }, | |
{ type: "mp3", directory: "music" }, | |
], | |
}; | |
type Config = typeof config; | |
type TypeDirs = Config["typeDirs"]; |
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
trait Functor[Box[_]] { | |
def map[In, Out](boxA: Box[In])(f: In => Out): Box[Out] | |
} | |
object Functor { | |
implicit val functorOption = new Functor[Option] { | |
override def map[In, Out](boxA: Option[In])(f: In => Out) = boxA.map(f) | |
} | |
implicit val functorList = new Functor[List] { |
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
Infos générales et saines lectures | |
- les 4 articles Strategic Scala Style du blog de lee haoyi | |
http://www.lihaoyi.com/post/StrategicScalaStylePrincipleofLeastPower.html | |
http://www.lihaoyi.com/post/StrategicScalaStyleConcisenessNames.html | |
http://www.lihaoyi.com/post/StrategicScalaStylePracticalTypeSafety.html | |
http://www.lihaoyi.com/post/StrategicScalaStyleDesigningDatatypes.html | |
Et la track de Daniel westheide | |
http://danielwestheide.com/scala/neophytes.html | |
Pour te familiariser avec le langage lui même tu peux pratiquer avec les workshops |
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 org.cakesolutions.spark | |
import org.apache.spark.SparkConf | |
import org.apache.spark.api.java.JavaSparkContext | |
import scala.Tuple2 | |
fun main(args: Array<String>) { | |
val inputFile = args[0] | |
val outputFile = args[1] |
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
function *fibonacci(n) { | |
const infinite = !n && n !== 0; | |
let current = 0; | |
let next = 1; | |
while (infinite || n--) { | |
yield current; | |
[current, next] = [next, current + next]; | |
} | |
} |
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
case class Node(value: Int, next: Option[Node]) | |
def reverse(node: Node, prev: Option[Node] = None): Node = { | |
val reversed = node.copy(next = prev) | |
node.next map {reverse(_, Some(reversed))} getOrElse reversed | |
} | |
/****************************************************************/ | |
val one = Node(1,Some(Node(2,Some(Node(3,None))))) | |
println(s"$one\n${reverse(one)}") |
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
import java.util.regex.Pattern | |
import play.core.Routes | |
import play.api.mvc._ | |
object Router extends Routes { | |
def routes = { | |
// Static paths | |
case Route("GET", p"") => controllers.Application.index | |
case Route("GET", p"/items") => controllers.Items.list |
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
object JournauxRepository { | |
def allWithOperateurs():Seq[(Journal, Operateur, Option[String])] = { | |
DB.withSession { | |
implicit s => | |
val result = for { | |
((journal, operateur), intervenant) <- Journaux leftJoin Operateurs on(_.idOperateur === _.id) leftJoin Intervenants on(_._1.idIntervenant === _.idAgence) | |
} yield (journal,operateur,intervenant.nom.?) | |
result.run | |
} | |
} |
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
/* | |
* The MIT License (MIT) | |
* | |
* Copyright (c) 2013 Association du Paris Java User Group. | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy of | |
* this software and associated documentation files (the "Software"), to deal in | |
* the Software without restriction, including without limitation the rights to | |
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |
* the Software, and to permit persons to whom the Software is furnished to do so, |
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
import scala.slick.lifted.CanBeQueryCondition | |
// optionally filter on a column with a supplied predicate | |
case class MaybeFilter[X, Y](val query: scala.slick.lifted.Query[X, Y]) { | |
def filter[T,R:CanBeQueryCondition](data: Option[T])(f: T => X => R) = { | |
data.map(v => MaybeFilter(query.filter(f(v)))).getOrElse(this) | |
} | |
} | |
// example use case | |
import java.sql.Date |
NewerOlder