Transforming a list of maps representing bands I have the following code, it takes a list of maps representing bands and transforms the band properties via the pipeline_each method. 

As you can see in the code, I am dealing with a lot of Options being returned when I modify the band data in the map - I am using an immutable map object and therefore need to return a new map each time the function is called.

I am also not happy about the type of the bands data structure being a List[Map[String, Any]] - particularly the Any part because I need to convert the values I get out of the maps to String types in order to modify them. I am stuck with this data structure though.

How can I make this code better, specifically addressing my concerns above?

    object Exercise {

  val bands: List[Map[String, Any]] = List(Map("name" -&gt; "sunset rubdown", "country" -&gt; "UK", "active" -&gt; true),
  Map("name" -&gt; "women", "country" -&gt; "Germany", "active" -&gt; false),
  Map("name" -&gt; "a silver mt. zion", "country" -&gt; "Spain", "active" -&gt; true))


  def set_canada_as_country(band: Map[String, Any]): Map[String, Any] = {
    Map("name" -&gt; band.get("name").get, "country" -&gt; "Canada", "active" -&gt; band.get("active").get )
  }

  def strip_punctuation_from_name(band: Map[String, Any]): Map[String, Any] = {
    Map("name" -&gt; band.get("name").get.toString.replace(".", ""), "country" -&gt; band.get("country").get, "active" -&gt; band.get("active").get )
    //toString above is kinda gross and could cause a class cast exception
    //do I have to handle all the case matching on some/none for all the above calls to get?
  }

  def capitalize_names(band: Map[String, Any]): Map[String, Any] = {
    Map("name" -&gt; band.get("name").get.toString.toUpperCase, "country" -&gt; band.get("country").get, "active" -&gt; band.get("active").get )
    //same again - don't like the toString
  }


  def pipeline_each(data: List[Map[String, Any]], fnList: List[Map[String, Any] =&gt; Map[String, Any]]): List[Map[String, Any]] = {
    fnList.foldLeft(data) {(bandList, currFn) =&gt; bandList.map(currFn)}
  }

}


I execute the above code via the REPL like so:

Exercise.pipeline_each(Exercise.bands,
  List(
    Exercise.set_canada_as_country,
    Exercise.strip_punctuation_from_name,
    Exercise.capitalize_names))
You might consider using map on Option to more cleanly access the values.

  def set_canada_as_country(band: Map[String, Any]): Map[String, Any] = {
    band.get("name").map( name =&gt; band.get("active").map(active =&gt; 
      Map("name" -&gt; name, "country" -&gt; "Canada", "active" -&gt; active))
  }


At this point, you could reasonable change the resulting type to Map[String, String].

Rather than using a list of functions, you might want to compose a new function using andThen:

Exercise.pipeline_each(Exercise.bands, Exercise.set_canada_as_country andThen
  Exercise.strip_punctuation_from_name andThen
  Exercise.capitalize_names)


That way you are only applying a single filtering function.