Pluto
Pluto

Reputation: 37

Scala: add prefix to each element in list

I have a list of some partitions, like:

[1, 2, 3, 4]

and also I have main path, like:

"books/style/type="

I want to get a list of full path, like this:

[books/style/type=1/, books/style/type=2, books/style/type=3, books/style/type=4]

I understand I should use map method, something like this:

val full_path = partsList.map(x => base_path + x)

but I do not have enough experience and knowledge to bring it to the right form

full code:

val partsList = ConfigFactory.load().getStringList("part_list")

val base_path = ConfigFactory.load().getString("path")
  
  import spark.implicits._

val fullPathList = partsList.map(x => base_path+x)

in application conf:

part_list = ["1", "2", "3", "4"]

path = "books/style/type="

Upvotes: 0

Views: 515

Answers (1)

Dima
Dima

Reputation: 40500

Assuming ConfigFactory is from type safe config, getStringList returns a java list, not a scala collection, you need to convert it to scala:

import scala.collection.JavaConverters._
val partsList = ConfigFactory.load().getStringList("part_list").asScala
...

Upvotes: 2

Related Questions