Created
April 2, 2015 21:49
-
-
Save ianoc/4785645d8c586aae1eb7 to your computer and use it in GitHub Desktop.
Accessing nested type
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 mappedName = "com.blah.X.y.MyType" | |
val splitName = mappedName.split('.') | |
val exceptLast = splitName.dropRight(1) | |
val terms = exceptLast.map(newTermName(_)) | |
val (first, second) = (terms(0), terms(1)) | |
val accessorSelect = terms.drop(2).foldLeft(Select(Ident(first), second)) { | |
case (existing, next) => | |
Select(existing, next) | |
} | |
val finalType = Select(accessorSelect, newTypeName(splitName.last)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment