Created
June 11, 2015 17:58
-
-
Save granthenke/b61ad03de0c35995cf5a to your computer and use it in GitHub Desktop.
Script to generate join function for Scala Futures
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
val types = { | |
for { | |
end <- 'B' to 'V' // v = 22 | |
types = 'A' to end | |
} yield types | |
} | |
types.foreach { types => | |
def typeToArgument(T: Char) = s"f${T.toLower}: Future[$T]" | |
def typeToForArgument(T: Char) = s"$T <- f$T".toLowerCase | |
val typeParameter = types.mkString(", ") | |
val arguments = types.map(typeToArgument).mkString(", ") | |
val forList = types.map(typeToForArgument).mkString("; ") | |
val yieldList = types.mkString(", ").toLowerCase | |
val function = s"def join[$typeParameter]($arguments)(implicit executor: ExecutionContext): Future[($typeParameter)] = for($forList) yield ($yieldList)" | |
println(function) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment