Skip to content

Instantly share code, notes, and snippets.

@granthenke
Created June 11, 2015 17:58
Show Gist options
  • Save granthenke/b61ad03de0c35995cf5a to your computer and use it in GitHub Desktop.
Save granthenke/b61ad03de0c35995cf5a to your computer and use it in GitHub Desktop.
Script to generate join function for Scala Futures
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