Functional Re-Write in Scala: Rows of Strings with a Max Width
This is much more "Functional" than my first attempt:

  def combineStrings(strs: List[String], maxLen: Int)
  : List[String] = {
    import scala.collection.mutable.StringBuilder

    strs.map(_.trim).filter(_.nonEmpty)
      .aggregate(List[StringBuilder]())({ (lbs, s) =&gt;
        s.length match {
          case l if (l &gt; maxLen) =&gt;
            new StringBuilder(s) :: lbs
          case l =&gt;
            lbs.find(_.length &lt;= maxLen - (l+2))
              .map { sb =&gt; sb ++= s", $s"; lbs }
              .getOrElse(new StringBuilder(s) :: lbs)
        }
      }, _ ++ _
    ).map(_.toString).reverse
  }


Not sure why I didn't do this the first time around. This solution even provides the desired output, and accounts for the ", " separators in the length calculations.

scala&gt; val rows = combineStrings(List("Short", "This is a particularly long String...", "More", "Small", "Strings"), 35)
rows: List[String] = List(Short, More, Small, Strings, This is a particularly long String...)

scala&gt; rows.foreach(println)
Short, More, Small, Strings
This is a particularly long String...