Skip to content

Instantly share code, notes, and snippets.

import com.github.nscala_time.time.StaticInterval
import com.twitter.algebird.Monoid
import shapeless._, record._, syntax.singleton._
import shapeless.ops.record.SelectAll
/** Represents a path component generator, basically a function keysTemplate.type -> Set[Seq[String]]
*
*/
trait PathPattern {
import com.github.nscala_time.time.StaticInterval
import com.twitter.algebird.Monoid
import shapeless._, record._, syntax.singleton._
import shapeless.ops.record.SelectAll
/** Represents a path component generator, basically a function keysTemplate.type -> Set[Seq[String]]
*
*/
trait PathPattern {
// Would love to use the following, sadly TypedPipe is not really monadic:
// * a bind/flatMap operator is missing:
// Indeed flatMap currently has the following signature:
// def flatMap[U](f: (T) ⇒ TraversableOnce[U]): TypedPipe[U]
// whereas a monadic bind would look like this
// def flatMap[U](f: (T) ⇒ TypedPipe[U]): TypedPipe[U]
// * return/unit can be implemented in such way:
// return[A]: A => TypedPipe[A] = a => TypedPipe.from(List(a))
for {
trait Monoid {
fn zero() -> Self;
fn append(this: Self, that: Self) -> Self;
}
impl Monoid for int {
fn zero() -> int { 0 }
fn append (this: int, that: int) -> int { this + that }
}
module GameSkeleton where
import Window
import Keyboard
import Random
{-- Part 1: Model the user input ----------------------------------------------
What information do you need to represent all relevant user input?
'use strict';
angular.module('firebase', []).value('Firebase', Firebase);
// Implicit syncing. angularFire binds a model to $scope and keeps the dat
// synchronized with a Firebase location both ways.
// TODO: Optimize to use child events instead of whole 'value'.
angular.module('firebase').factory('angularFire', ['$q', function($q) {
return function(url, scope, name, ret) {
var af = new AngularFire($q, url);
import scala.reflect.runtime.universe._
import scala.reflect._
object testtypetag {
class ReqTT[T : TypeTag]
case class Dummy
new ReqTT[Dummy] // Compiler : No TypeTag available for Dummy, thus no implicit evidence
}
/*
Par exemple, dans le pseudo-code suivant, tous les appels sont asynchrones mais séquentiels
les uns par rapport aux autres.
Si l'un d'entre eux échoue, la chaine d'appels s'arrete et 'pictures' est lui-meme considéré
comme un echec et contient l'erreur/exception du point d'abandon.
*/
//'pictures' est ici une composition des différents appels différés (Future)
val pictures: Future[List[Picture]] = for {
trait ModelService[T] {
val selectAll = Queryable[T] // Compiler error : No TypeTag for T, plus issues with "evidences"
val selectById = (id:Int) => selectAll.filter(_.id == id)
def all: Try[Option[Vector[T]]]
def get (id:Int): Try[Option[T]]
def add (obj: T): Try[Option[Int]]
def update (id:Int, obj:T): Try[Option[Int]]
def delete (id:Int):Try[Option[Int]]