I have the following List
of tuples in Scala:
var a : List[(Int,String)] = List()
a = a:+((1,"bla bla bla"))
a = a:+((2,"la la la"))
a = a:+((3,"bla la bla"))
which looks like that:
print(a)
List((1,bla bla bla), (2,la la la), (3,bla la bla))
What I wish to do is to apply flatMap
function in order to create a new list from the list a
which contains only the strings from the tuple to which it appends the word "appended". The result should therefore be:
List(bla bla blaappended, la la laappended, bla la blaappended)
Could someone help me understand how I could go about it? I am new to Scala and I can't wrap my head around this. Thanks in advance
You don't need flatMap
, simple map
is enough
val result = a.map(t => t._2 + "appended")
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加