Tuple Unpacking in Map Operations

后端 未结 6 1543
慢半拍i
慢半拍i 2020-12-07 15:46

I frequently find myself working with Lists, Seqs, and Iterators of Tuples and would like to do something like the following,

val arrayOfTuples = List((1, \"         


        
6条回答
  •  -上瘾入骨i
    2020-12-07 15:57

    Why don't you use

    arrayOfTuples.map {t => t._1.toString + t._2 }
    

    If you need the parameters multiple time, or different order, or in a nested structure, where _ doesn't work,

    arrayOfTuples map {case (i, s) => i.toString + s} 
    

    seems to be a short, but readable form.

提交回复
热议问题