nik*_*kos 1 dictionary scala tuples
我试图找出如何使用map运算符,我可以创建一个元组,其中包含与现有元素不同数量的字段.
也就是说,如果我在形式中有一个元组,(String, Int1, Int2)我想创建一个元组,其形式为2个字段(String, Int1 + Int2),其中第一个字段与原始元组相同,第二个字段将添加第二个字段和原始元组的第3个字段.
使用模式匹配:
tuple match { case (a, b, c) => (a, b + c) }
Run Code Online (Sandbox Code Playgroud)
map不是元组的成员.如果元组是集合中元素的类型,则可以使用它.
collection map { case (a, b, c) => (a, b + c) }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
118 次 |
| 最近记录: |