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 Ok { | |
trait Foo[A] | |
case class Bar(x: Int) | |
object Bar { | |
implicit class BarOps(bar: Foo[Bar]) { | |
val ok = "ok" | |
} | |
} | |
def usage(bar: Foo[Bar]) = bar.ok // Ok, the implicit conversion is found in the Bar companion object |
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
/** | |
* data (f :+: g) a = Inl (f a) | Inr (g a) | |
*/ | |
sealed trait Coproduct[F[+_], G[+_], A] | |
case class Inl[F[+_], G[+_], A](a: F[A]) extends Coproduct[F, G, A] | |
case class Inr[F[+_], G[+_], A](a: G[A]) extends Coproduct[F, G, A] | |
trait :+:[F[+_], G[+_]] { | |
type Apply[A] = Coproduct[F, G, A] | |
} |
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 Functor[F[_]] { | |
def fmap[A, B](f: A => B): F[A] => F[B] | |
} |
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 Contact(name: String, email: String) |
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
// --- Definition of a query string binder for type A using a Mapping[A] | |
object Binders { | |
implicit def mappingBinder[A](implicit mapping: Mapping[A]) = new QueryStringBindable[A] { | |
override def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, A]] = { | |
val data = for { | |
(k, ps) <- params | |
if k startsWith key | |
p <- ps.headOption | |
} yield (k.drop(key.length + 1), p) |
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
scala> trait Foo[+A] | |
defined trait Foo | |
scala> implicit object intFoo extends Foo[Int] | |
defined module intFoo | |
scala> implicit def traversableFoo[F[_], A](implicit bf: collection.generic.CanBuildFrom[F[_], A, F[A]], aFoo: Foo[A]) = new Foo[F[A]] {} | |
traversableFoo: [F[_], A](implicit bf: scala.collection.generic.CanBuildFrom[F[_],A,F[A]], implicit aFoo: Foo[A])java.lang.Object with Foo[F[A]] | |
scala> implicitly[Foo[List[Int]]] |
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 Application extends Controller with PathLang { | |
def index = Ok(html.index()) | |
} |
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 show(article: Article) = Action { | |
Ok(views.html.article(article)) | |
} |
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 Application extends Controller { | |
val index = Action { implicit request => | |
Ok(views.html.index()) | |
} | |
val show = Action { implicit request => | |
Ok(views.html.show("42")) | |
} | |
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
-- Un type qui sera une instance de Monad. Il s'agit d'un simple | |
-- conteneur pour les fonctions d'un environnement vers un résultat. | |
newtype Reader env res = Reader (env -> res) | |
-- Une fonction qui prend un Reader et un environnement, et qui | |
-- renvoit le résultat | |
runReader :: Reader env res -> env -> res | |
runReader (Reader f) e = f e | |
-- La fameuse instance de Monad. return ignore son environnement, |