title: Group Strings In List By Maximum
body: <p>Have been trying to tackle this problem in scala, but can't quite get it figured out. </p>
  
  <p>I have a <code>List[String]</code>, and want to group the different Strings together so that no group exceeds a maximum size, keeping a note of their index in the list.</p>
  
  <p>Here is some sample data as an example:</p>
  
  <pre><code>val sample: List[String] = List[String](
      "{\"test\":\"testfield\"}", // 20 length
      "{\"test2\":\"testfield2\"}", // 22 length
      "{\"test3\":\"testfield3\"}") // 22 length
  
  val maxLength = 48 // collect into groups where total .length is less than this
  
  val output: List[List[Int]] =
      List(
          List(0,1),
          List(2)
      )
  </code></pre>
  
  <p>I have managed to simulate the same thing in Java, but trying to replicate this in Scala style code without for loops is trumping me. I have current been trying using <code>scanLeft</code>.</p>
  
  <p>Any pointers in the right direction would be greatly appreciated!</p>