How to apply flatMap to list of tuples (Int,String) in Scala?

hispaniccoder

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

Andronicus

You don't need flatMap, simple map is enough

val result = a.map(t => t._2 + "appended")

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Scala: How to split a list into tuples in all possible ways

分類Dev

scala: generating tuples from a list

分類Dev

How to unpack tuples in nested list?

分類Dev

How to convert Tuples to Map with Set in Scala

分類Dev

ScalaのFlatMap

分類Dev

How to convert string array to int array in scala

分類Dev

How to make DataFrame from list of tuples

分類Dev

How to convert list of pair tuples in dataframe into columns

分類Dev

How to group list items into sequential tuples in Python?

分類Dev

How to extract tuples from a list of lists in Haskell

分類Dev

How can I printf a list of tuples?

分類Dev

Is there a function in scala or scalaz to apply a function to a list if the list is not empty?

分類Dev

Conditionally apply a function in Scala - How to write this function?

分類Dev

Tuples in Scala not working as expected

分類Dev

Scala groupby Tuples

分類Dev

Scala: Implementation of flatMap using foldRight

分類Dev

Converting list of tuples in a Python Pandas dataframe column into dictionary of lists using apply method

分類Dev

Apply function to one element only in list or array in Scala

分類Dev

ScalaでList [Map [String、Map [String、Int]]]をMap [Int、Int]に変換します

分類Dev

整数のリスト(つまり、List [Int])でscala flatMapメソッドを使用することはできませんか?

分類Dev

scala convert string into a list of longs

分類Dev

Sort a list of tuples where each tuple is one string

分類Dev

How to flatten a List of Futures in Scala

分類Dev

how to pass a scala List to NetLogo

分類Dev

How to post Javascript array to C# list of tuples ?

分類Dev

How to remove duplicate combinations tuples from python list?

分類Dev

How to check if all tuples have a specific value in a python list

分類Dev

How to extract and compare data from a given list of tuples?

分類Dev

F#: Expand a list of tuples of form (string*string list) list using a key

Related 関連記事

  1. 1

    Scala: How to split a list into tuples in all possible ways

  2. 2

    scala: generating tuples from a list

  3. 3

    How to unpack tuples in nested list?

  4. 4

    How to convert Tuples to Map with Set in Scala

  5. 5

    ScalaのFlatMap

  6. 6

    How to convert string array to int array in scala

  7. 7

    How to make DataFrame from list of tuples

  8. 8

    How to convert list of pair tuples in dataframe into columns

  9. 9

    How to group list items into sequential tuples in Python?

  10. 10

    How to extract tuples from a list of lists in Haskell

  11. 11

    How can I printf a list of tuples?

  12. 12

    Is there a function in scala or scalaz to apply a function to a list if the list is not empty?

  13. 13

    Conditionally apply a function in Scala - How to write this function?

  14. 14

    Tuples in Scala not working as expected

  15. 15

    Scala groupby Tuples

  16. 16

    Scala: Implementation of flatMap using foldRight

  17. 17

    Converting list of tuples in a Python Pandas dataframe column into dictionary of lists using apply method

  18. 18

    Apply function to one element only in list or array in Scala

  19. 19

    ScalaでList [Map [String、Map [String、Int]]]をMap [Int、Int]に変換します

  20. 20

    整数のリスト(つまり、List [Int])でscala flatMapメソッドを使用することはできませんか?

  21. 21

    scala convert string into a list of longs

  22. 22

    Sort a list of tuples where each tuple is one string

  23. 23

    How to flatten a List of Futures in Scala

  24. 24

    how to pass a scala List to NetLogo

  25. 25

    How to post Javascript array to C# list of tuples ?

  26. 26

    How to remove duplicate combinations tuples from python list?

  27. 27

    How to check if all tuples have a specific value in a python list

  28. 28

    How to extract and compare data from a given list of tuples?

  29. 29

    F#: Expand a list of tuples of form (string*string list) list using a key

ホットタグ

アーカイブ