<commit_before>package com.socrata.datacoordinator.primary

import scalaz._
import scalaz.effect._
import Scalaz._
import com.socrata.soql.brita.AsciiIdentifierFilter

import com.socrata.datacoordinator.truth.metadata.ColumnInfo
import com.socrata.datacoordinator.truth.MonadicDatasetMutator

class ColumnAdder[CT, CV](mutator: MonadicDatasetMutator[CV], nameForType: CT => String, physicalColumnBaseLimit: Int) extends ExistingDatasetMutator {
  import mutator._

  def addToSchema(dataset: String, columns: Map[String, CT], username: String): IO[Map[String, ColumnInfo]] = {
    val columnCreations = columns.iterator.map { case (columnName, columnType) =>
      val baseName = AsciiIdentifierFilter(List("u", columnName)).take(physicalColumnBaseLimit).replaceAll("_+$","").toLowerCase
      addColumn(columnName, nameForType(columnType), baseName)
    }.toStream

    mutator.withDataset(as = username)(dataset) {
      columnCreations.sequence.map { _.foldLeft(Map.empty[String, ColumnInfo]) { (acc, ci) => acc + (ci.logicalName -> ci) } }
    }.flatMap(finish(dataset))
  }
}<commit_msg>Slight ColumnAdder refactor for added readability<commit_after>package com.socrata.datacoordinator.primary

import scalaz._
import scalaz.effect._
import Scalaz._
import com.socrata.soql.brita.AsciiIdentifierFilter

import com.socrata.datacoordinator.truth.metadata.ColumnInfo
import com.socrata.datacoordinator.truth.MonadicDatasetMutator

class ColumnAdder[CT, CV](mutator: MonadicDatasetMutator[CV], nameForType: CT => String, physicalColumnBaseLimit: Int) extends ExistingDatasetMutator {
  import mutator._

  def addToSchema(dataset: String, columns: Map[String, CT], username: String): IO[Map[String, ColumnInfo]] = {
    val columnCreations = columns.iterator.map { case (columnName, columnType) =>
      val baseName = AsciiIdentifierFilter(List("u", columnName)).take(physicalColumnBaseLimit).replaceAll("_+$","").toLowerCase
      addColumn(columnName, nameForType(columnType), baseName)
    }.toList.sequence

    mutator.withDataset(as = username)(dataset) {
      for {
        newColumns <- columnCreations
      } yield newColumns.foldLeft(Map.empty[String, ColumnInfo]) {
        (acc, ci) => acc + (ci.logicalName -> ci)
      }
    }.flatMap(finish(dataset))
  }
}
{'fraction_non_alphanumeric': 0.11912087912087913, 'fraction_numerical': 0.0, 'mean_word_length': 5.35754189944134, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 11, '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': '833194', 'n_tokens_mistral': 715, 'n_tokens_neox': 698, 'n_words': 132}