I hope to write a Scala method that takes a tuple of any size and type along with the index and returns the element in the tuple at that index. I know how to do everything except save type. I have not figured out a way to make the return value of the dynamic type of a tuple element.
Here is the function that I have so far:
def subscript_get(tup: Product, index:Int): Any={ return tup.productElement(index) }
For example, usage would be:
subscript_get((0,1,2,3),0) --> Int = 0
subscript_get((0,1,"asdf",3),2) --> java.lang.String = asdf
I know that I can return the result back to what I am looking for, but this does not work for me, because I can not always know what type I should be attached to.
Is something like this possible? Thanks!
Peter source share