【问题标题】:Concatenation by nth index in Gatling/ScalaGatling / Scala中的第n个索引连接
【发布时间】:2016-03-28 17:48:10
【问题描述】:

如果我有Vector("1", "2", "3", "4", "5", "6", "7", "8", "9") 的向量myVector,我知道我可以通过以下方式设置"1,2,3,4,5,6,7,8,9" 的会话变量字符串:

.exec(session =>
        // Concatenate session variable
        session.set("myVectorConcat", session("myVector").as[Seq[String]].mkString(",")))

但我想得到一个会话变量,它是一个字符串向量,每 5 个项目(剩余项目在最后一个索引中)分割,这样myVectorConcat 将是一个向量:

("1,2,3,4,5", "6,7,8,9")

我是 Gatling/Scala 的新手,所以我想知道这在 Gatling 中是否可行?

【问题讨论】:

    标签: scala gatling


    【解决方案1】:

    我想这就是你想要的:

    scala> Vector("1", "2", "3", "4", "5", "6", "7", "8", "9")
      .grouped(5).map(_.mkString(",")).toVector
    
    res0: Vector[String] = Vector(1,2,3,4,5, 6,7,8,9)
    

    这是 scala repl 的输出,但实际上看起来像这样

    Vector("1,2,3,4,5", "6,7,8,9")
    

    【讨论】:

    • 感谢您提供的超清晰答案,我开始真正爱上 Scala。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-10
    • 1970-01-01
    • 1970-01-01
    • 2017-05-06
    • 1970-01-01
    相关资源
    最近更新 更多