title: fold left to convert a List of List into a string
body: <p>I want convert a list of list to string with a deliminator using fold left</p>
  
  <p>I am trying to create a String but it has extra deliminator </p>
  
  <pre><code> trait Msg {
  
      def toCustString(flag:Boolean): String
    }
  
    trait Ele[T] extends Msg {
  
      val value: T
  
      override def toCustString(flag:Boolean): String = s"${value}"
  
    }
  
    trait Grp extends Msg {
  
      val list: Seq[Msg]
  
      override def toCustString(flag: Boolean = false): String = {
  
        val sep = if (flag) "\n" else "!"
        test((builder: StringBuilder, elem: Msg) =&gt; builder.append(s"$sep${elem.toCustString(false)}$sep"))
  
      }
  
      def test(acc: (StringBuilder, Msg) =&gt; StringBuilder): String = {
        list.foldLeft(StringBuilder.newBuilder)(acc).toString()
      }
  
  
    }
  
  case class MyMessage(list:Seq[Msg]) extends Grp
  case class TypeA(value: Int) extends Ele[Int]
  case class TypeB(value: String) extends Ele[String]
  case class TypeC(value: Float) extends Ele[Float]
  case class MyGrp (list:Seq[Msg]) extends Grp
  
  object Demo extends App{
    val grp1 = MyGrp(Seq(TypeA(2)))
    val grp2 = MyGrp(Seq(TypeB("ABC"), TypeC(20)))
    val s=MyGrp(Seq(grp1,grp2))
    val m = MyMessage(Seq(TypeA(2),s)).toCustString(false)
    print(m)
  
  }
  </code></pre>
  
  <p><strong>Updated</strong></p>
  
  <p><strong>My output</strong> is !2!!!!2!!!!ABC!!20.0!!!</p>
  
  <p><strong>Expected</strong> 2!2!ABC!20.0!</p>