All Downloads are FREE. Search and download functionalities are using the official Maven repository.

.circumflex-core.1.0.source-code.util.scala Maven / Gradle / Ivy

package ru.circumflex.core

import collection.mutable.{HashMap, ListBuffer}
import java.io.File
import util.matching.Regex

/**
 * Contains utility stuff.
 */
object CircumflexUtil {

  /**
   * Performs a grouping operation on a collection. The result is a map
   * in which keys are obtained via predicate function `predicateFunc` and
   * values are subcollections, every element of which satisfies the predicate.
   */
  def groupBy[K,V](it: Iterable[V], predicateFunc: V => K): collection.Map[K, Seq[V]] = {
    val result = new HashMap[K, ListBuffer[V]] {
      override def default(a: K) = new ListBuffer[V]
    }
    it.foreach(v => {
      val key = predicateFunc(v)
      val buffer: ListBuffer[V] = result(key)
      buffer += v
      result += (key -> buffer)
    })
    result
  }

  /**
   * Now this thingy is very useful and very light:
   * it translates every `ThisKindOfIdentifiers`
   * into `that_kinds_of_identifiers`.
   */
  def camelCaseToUnderscore(arg: String) = arg.replaceAll("(? String): String =
    regex.replaceAllIn(source, m => replacer(m.group(0)))
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy