Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.01 KB | None | 0 0
  1.   trait Functor[F[_]] {
  2.     def map[A, B](a: F[A])(f: A => B): F[B]
  3.   }
  4.  
  5.   type Id[T] = T
  6.  
  7.   implicit object IdFunctor extends Functor[Id] {
  8.     override def map[A, B](a: Id[A])(f: A => B): Id[B] = f(a)
  9.   }
  10.  
  11.   implicit object OptionFunctor extends Functor[Option] {
  12.     override def map[A, B](a: Option[A])(f: A => B): Option[B] = a.map(f)
  13.   }
  14.  
  15.   class GenericRelationPimp[F[_]](column: String)(implicit functor: Functor[F]) {
  16.     def equal(term: F[Type[_]]): F[Relation.Single] =
  17.       functor.map(term) { term =>
  18.         Relation.Single(column, Operation.Equal, term)
  19.       }
  20.  
  21.     def `===`(term: F[Type[_]]): F[Relation.Single] =
  22.       equal(term)
  23.   }
  24.  
  25.   implicit def toIdRelationPimp(column: String): GenericRelationPimp[Id] =
  26.     new GenericRelationPimp[Id](column)
  27.   implicit def toOptionRelationPimp(column: String): GenericRelationPimp[Option] =
  28.     new GenericRelationPimp[Option](column)
  29.  
  30.   val x: Id[Relation.Single] = "" === str("")
  31.   val y: Option[Relation.Single] = "" === Some(str(""))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement