<commit_before>package recursion

import org.scalatest.FunSuite

import scala.annotation.tailrec

case class Heading(weight: Int, text: String) {
  def indent: String = {
    val newLine = "\n"
    val tabs = "\t" * weight
    s"$newLine$tabs$text"
  }
}

case class Node(heading: Heading, children: List[Node]) {
  def toOutline: String = {
    @tailrec
    def loop(node: Node, acc: String): String = node match {
      case Node(h, c) if c.isEmpty => acc + h.indent
      case Node(h, t) => loop(t.head, acc + h.indent)
    }
    loop(this, "")
  }
}

class NodeRecursionTest extends FunSuite {
  test("node to outline") {
    val node = Node(Heading(0, "1. All about Birds"),
      List(Node(Heading(1, "1. Kinds of Birds"),
        List(Node(Heading(2, "1. The Finch"),
          List(Node(Heading(2, "2. The Swan"),
            List(Node(Heading(1, "2. Habitats"),
              List(Node(Heading(2, "1. Wetlands"),
                List.empty[Node])))))))))))
    val outline = node.toOutline
    assert(outline.nonEmpty)
    println(outline)
  }
}<commit_msg>renamed loop acc to outline<commit_after>package recursion

import org.scalatest.FunSuite

import scala.annotation.tailrec

case class Heading(weight: Int, text: String) {
  def indent: String = {
    val newLine = "\n"
    val tabs = "\t" * weight
    s"$newLine$tabs$text"
  }
}

case class Node(heading: Heading, children: List[Node]) {
  def toOutline: String = {
    @tailrec
    def loop(node: Node, outline: String): String = node match {
      case Node(h, c) if c.isEmpty => outline + h.indent
      case Node(h, t) => loop(t.head, outline + h.indent)
    }
    loop(this, "")
  }
}

class NodeRecursionTest extends FunSuite {
  test("node to outline") {
    val node = Node(Heading(0, "1. All about Birds"),
      List(Node(Heading(1, "1. Kinds of Birds"),
        List(Node(Heading(2, "1. The Finch"),
          List(Node(Heading(2, "2. The Swan"),
            List(Node(Heading(1, "2. Habitats"),
              List(Node(Heading(2, "1. Wetlands"),
                List.empty[Node])))))))))))
    val outline = node.toOutline
    assert(outline.nonEmpty)
    println(outline)
  }
}
{'fraction_non_alphanumeric': 0.15013901760889714, 'fraction_numerical': 0.011121408711770158, 'mean_word_length': 2.8484848484848486, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '668790', 'n_tokens_mistral': 762, 'n_tokens_neox': 744, 'n_words': 192}