接受数组参数并返回变异数组的Scala函数

时间:2019-03-06 17:34:08

标签: arrays scala list string-interpolation

我想找出最实用的方式来接受数组(或列表)并追加到数据结构中。然后最后返回新的数据结构。

类似这样的东西:

 def template(array: Array[String]): Array[Nothing] = {
  val staging_path = "s3//clone-staging/"
  var path_list = Array()
  //iterate through each of the items in the array and append to the new string.
  for(outputString <- array){
    var new_path = staging_path.toString + outputString
    println(new_path)
    //path_list I thought would add these new staging_path to the array
    path_list +: new_path

  }
 path_list(4)
 }

但是,通过调用数据结构的单个索引作为检查存在性的手段,path_list(4)返回“超出界限”。

谢谢。

1 个答案:

答案 0 :(得分:1)

我认为您只想在此处使用=IF(ISBLANK(E1),F1,E1)

map

在函数式编程领域,您通常试图避免发生突变。而是将其视为将您的输入数组转换为新数组。