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 balance(chars: List[Char]): Boolean = { | |
@scala.annotation.tailrec | |
def balance(chars: List[Char], stack:List[Unit]): Boolean = (chars, stack) match { | |
case (Nil , Nil) => true | |
case (Nil , _ ) => false | |
case (')':: _, Nil) => false | |
case (head::tail, stack) => head match { | |
case '(' => balance(tail, () :: stack) | |
case ')' => balance(tail, stack.tail ) | |
case _ => balance(tail, stack ) |
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
import language.dynamics | |
case class DynamicDuke(prefix:String = "") extends Dynamic { | |
def apply(s:String) = DynamicDuke(prefix + s) | |
def selectDynamic(method:String) = DynamicDuke(prefix + " " + method) | |
def applyDynamic(method:String) = selectDynamic(method) | |
} | |
val duke = DynamicDuke() |
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
import TypeConverter._ | |
import ParserCSV._ | |
import scalaz._ | |
import Scalaz._ | |
val csvReaderAhoy = readCSV("./csv/ahoy.txt") | |
case class Personne(nom:String, prenom:String, age:Option[Int]) | |
csvReaderAhoy(line => ^(line.nom.s,line.prenom.s,line.age.to[Option[Int]])(Personne)) //Iterator | |
csvReaderAhoy(line => ^(line.nom.s,line.prenom.s,line.age.to[Option[Int]])(Personne)).toList //List[ValidationNEL[String,Personne]] |
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
case class ImplicitInject[I,B,C](f: (I,B) => C) { | |
def apply(b:B)(implicit i:I):C = f(i,b) | |
//def i(b:B)(implicit i:I):C = f(i,b) // it could be "explicit" | |
} | |
object ImplicitInject { | |
implicit val a:Int = 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
object GOL extends App { | |
type Cell = (Int,Int) | |
type Step = List[Cell] | |
lazy val motifvoisinage:Step = { | |
val iii = (-1 to 1) | |
iii.flatMap(x => iii.map( _ -> x)).filter(_ != (0,0)).toList | |
} | |
def add(c1:Cell, c2:Cell):Cell = (c1._1 + c2._1, c2._2 + c1._2) |
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
trait Closable[A] { | |
def closable(a:A):Unit | |
} | |
object Ahoy extends App { | |
implicit def closable[A <: {def close:Unit}] = new Closable[A] { | |
def closable(a:A) {a.close} | |
} |
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
"@context": { | |
"@comment": "Generic term for blog in RDF and JSON/LD", | |
"wikia": "http://data.wikia.com/terms#", | |
"xsd": "http://www.w3.org/2001/XMLSchema#", | |
"@vocab": "http://example.org/myblog#", | |
"date": { | |
"@type": "xsd:dateTime" | |
}, | |
"email": { | |
"@type": "xsd:email" |
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
object SomeHelper { | |
implicit def lazyFunc[A,B](f: A=> B): ((=> A) => B) = a => f(a) | |
} | |
object MyApp extends App { | |
import SomeHelper._ | |
val m = new SomeFunctor(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
context.Expr( | |
Apply( | |
Apply( | |
Select(suite.tree, newTermName("testPublic")) | |
, List(testName.tree) | |
) | |
, List(testFun.tree) | |
) | |
) | |
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
;the bot is tron.bots.ahoy/turn-based-strat | |
(ns tron.bots.ahoy | |
(:require [tron.core :as tron])) | |