【发布时间】:2015-10-08 00:30:19
【问题描述】:
我是 scala 编程的新手,想编写一个函数,通过传入的参数返回一个元组实例。这就是我的意思:
def toTuple(strings : String*) = {
//some code to create a tuple, if possible
//the tuple should be consistent with the order the arguments were passed in
}
在scala中可以这样做吗?
【问题讨论】:
-
查看链接的问题,但为了更好的帮助,你到底想实现什么/你背后的想法是什么?
-
@ElmarWeber 背后没有任何想法,我只是在学习 scala 并尝试不同的示例。
-
由于历史原因,很难对 scala 元组进行抽象(这将在即将发布的版本中修复,但可能在未来几年内)。一般来说,如果你想通用地工作,最好使用 shapeless
HLists。