Created
December 22, 2015 11:23
-
-
Save mcalavera81/cb8fbb134adfefb0bc23 to your computer and use it in GitHub Desktop.
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 Combinable[T]{ | |
def combine(a:T,b:T):T | |
} | |
object Combinable{ | |
def apply[T](implicit c:Combinable[T]) = c | |
trait CombinableOps[T]{ | |
def self:T | |
def combinable: Combinable[T] | |
def combine(other: T) = combinable.combine(self,other) | |
} | |
object ops{ | |
implicit def toCombinableOps[T](t:T)(implicit c:Combinable[T])={ | |
new CombinableOps[T] { | |
override def self: T = t | |
override def combinable: Combinable[T] = c | |
} | |
} | |
} | |
implicit object StringCombinable extends Combinable[String]{ | |
override def combine(a: String, b: String): String = | |
a+b | |
} | |
} | |
Combinable[String].combine("aa","bb") | |
import Combinable.ops._ | |
"aa" combine "bb" combine "cc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment