Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait Functor[F[_]] {
- def map[A, B](a: F[A])(f: A => B): F[B]
- }
- type Id[T] = T
- implicit object IdFunctor extends Functor[Id] {
- override def map[A, B](a: Id[A])(f: A => B): Id[B] = f(a)
- }
- implicit object OptionFunctor extends Functor[Option] {
- override def map[A, B](a: Option[A])(f: A => B): Option[B] = a.map(f)
- }
- class GenericRelationPimp[F[_]](column: String)(implicit functor: Functor[F]) {
- def equal(term: F[Type[_]]): F[Relation.Single] =
- functor.map(term) { term =>
- Relation.Single(column, Operation.Equal, term)
- }
- def `===`(term: F[Type[_]]): F[Relation.Single] =
- equal(term)
- }
- implicit def toIdRelationPimp(column: String): GenericRelationPimp[Id] =
- new GenericRelationPimp[Id](column)
- implicit def toOptionRelationPimp(column: String): GenericRelationPimp[Option] =
- new GenericRelationPimp[Option](column)
- val x: Id[Relation.Single] = "" === str("")
- val y: Option[Relation.Single] = "" === Some(str(""))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement