0

I have an scala List like this:

List((List("android..", "android.webkit.*", "android.webkit.WebView"),List("void setInt (int), 20", "boolean deleteCache (android.content.Context), 20")))

From the above List I need something like the following (Nested Mapping):

List(
    Map(
      "name" -> "android.*.*",
      "children" -> List(
          Map(
            "name" -> "android.webkit.*",
            "children" -> List(
              Map(
              "name" -> "android.webkit.WebView",
              "children" -> List(
                Map("name" -> "void setInt (int)", "value" -> 20),
                Map("name" -> "boolean deleteCache (android.content.Context)", "value" -> 20)
                )
              )
            )
          )
      )
    )
  )

I have tried with List "head" and "tail" along with a recursive approach. However, I didn't get the best out of it.

Any kinds of hints will be a great help for me. Thanks in advance.

jwvh
  • 50,871
  • 7
  • 38
  • 64
Yasir Arefin
  • 351
  • 1
  • 9
  • 23
  • 2
    Where do the "values" of `20` come from? – jwvh Sep 21 '18 at 20:42
  • 3
    Are you opposed to editing your structure? `case class Package(name: String, children: List[Package])` is much easier to read than your `Map`, and ensures static type checking works. – Ethan Sep 21 '18 at 21:03
  • hi @jwvh, I forgot to add it. Now, I added it to the List. – Yasir Arefin Sep 22 '18 at 04:48
  • @Ethan, I want the nested Map like this. So that, I can generate some intended JSON object from this using the json4s library. – Yasir Arefin Sep 22 '18 at 04:50
  • Your problem has some structure but without explanation it is just Lists with Strings. Can you describe how you get from input list to output map? Why something becomes `value` and other `children`? Why 2 separate lists become 1 nested map? – Nazarii Bardiuk Sep 22 '18 at 12:19

0 Answers0