Created
November 2, 2015 00:19
-
-
Save dbousamra/cefd8bd52aa293adebcc to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Replaceable[A] { | |
| def replace[A, B](src: A)(in: A, out: B): B | |
| } | |
| trait StringExample extends Replaceable[String] { | |
| def replace(src: String)(in: String, out: String): String = { | |
| src.replace(in, out) | |
| } | |
| } | |
| trait ListExample[A, B] extends Replaceable[List[A]] { | |
| private def replacer(x: A, y: B) = (i: A) => if (i == x) y else i | |
| def replace(src: List[A])(in: A, out: B): List[B] = { | |
| src map(item => replacer(in, out)(item)) | |
| } | |
| } | |
| trait FutureExample[A, B] extends Replaceable[Future[A]] { | |
| private def replacer(x: A, y: B) = (i: A) => if (i == x) y else i | |
| def replace(src: Future[A])(in: A, out: B): List[B] = { | |
| src map(item => replacer(in, out)(item)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment