<commit_before>package org.specs2.springexample

import org.specs2.spring.BeanTables
import java.util.Date
import org.specs2.mutable.Specification
import scalaz._
import Scalaz._
import collection.immutable.HashMap

/**
 * @author janmachacek
 */
class BeanTableSpec extends Specification with BeanTables {

  /**
   * Trivial demonstration of BeanTables |> method
   */
  "Simple test" in {
    "age" | "name" | "teamName" |
      32 ! "Jan" ! "Wheelers" |
      30 ! "Ani" ! "Team GB" |> {
      r: Rider => r.getAge must be_>(29)
    }
  }

  /**
   * Demonstration of the |< (return-left) method that gives back a List of the appropriately constructed beans
   */
  "Simple list" in {
    val riders =
      "age" | "name" | "teamName" |
        32 ! "Jan" ! "Wheelers" |
        30 ! "Ani" ! "Team GB" |< (classOf[Rider])

    riders.size must be_==(2)
  }

  /*
  clusterBy :: Ord b => (a -> b) -> [a] -> [[a]]
  clusterBy f = M.elems . M.map reverse . M.fromListWith (++) . map (f &&& return)

   i.e. clusterBy(List("a", "bb", "cc"))(_.length) == List(List("a"), List("bb", "cc"))

   http://etorreborre.blogspot.com/2009/02/exercise-with-arrows-in-scala.html
   */
  def clusterBy[A, B](l: List[A])(f: A => B) = {
    val identity = (x: Any) => x
    groupByFirst(l ∘ { e => (f(e), e)})

    //    val identity = (x: A) => x
    //    identity.first apply(7, "abc")
  }

  def groupByFirst[A, B](l: List[(A, B)]) =
    l.foldLeft[Map[A, List[B]]](new HashMap[A, List[B]])(
      (res, cur) => res + ((cur._1, cur._2 :: res.getOrElse(cur._1, Nil)))).toList

  "foo" in {
    val cluster = clusterBy(List("one", "two", "three"))(_.length)
    println(cluster)
    success
  }<commit_msg>Updates<commit_after>package org.specs2.springexample

import org.specs2.spring.BeanTables
import java.util.Date
import org.specs2.mutable.Specification
import scalaz._
import Scalaz._
import collection.immutable.HashMap

/**
 * @author janmachacek
 */
class BeanTableSpec extends Specification with BeanTables {

  /**
   * Trivial demonstration of BeanTables |> method
   */
  "Simple test" in {
    "age" | "name" | "teamName" |
      32 ! "Jan" ! "Wheelers" |
      30 ! "Ani" ! "Team GB" |> {
      r: Rider => r.getAge must be_>(29)
    }
  }

  /**
   * Demonstration of the |< (return-left) method that gives back a List of the appropriately constructed beans
   */
  "Simple list" in {
    val riders =
      "age" | "name" | "teamName" |
        32 ! "Jan" ! "Wheelers" |
        30 ! "Ani" ! "Team GB" |< (classOf[Rider])

    riders.size must be_==(2)
  }

  /*
  clusterBy :: Ord b => (a -> b) -> [a] -> [[a]]
  clusterBy f = M.elems . M.map reverse . M.fromListWith (++) . map (f &&& return)

   i.e. clusterBy(List("a", "bb", "cc"))(_.length) == List(List("a"), List("bb", "cc"))

   http://etorreborre.blogspot.com/2009/02/exercise-with-arrows-in-scala.html
   */
  def clusterBy[A, B](l: List[A])(f: A => B) = {
    val identity = (x: Any) => x
    groupByFirst(l ∘ { e => (f(e), e)}) 

    //    val identity = (x: A) => x
    //    identity.first apply(7, "abc")
  }

  def groupByFirst[A, B](l: List[(A, B)]) =
    l.foldLeft[Map[A, List[B]]](new HashMap[A, List[B]])(
      (res, cur) => res + ((cur._1, cur._2 :: res.getOrElse(cur._1, Nil)))).toList

  "foo" in {
    val cluster = clusterBy(List("one", "two", "three"))(_.length)
    println(cluster)
    success
  }
{'fraction_non_alphanumeric': 0.19213715637008572, 'fraction_numerical': 0.01418859000886787, 'mean_word_length': 2.7937219730941703, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, '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': '2375826', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1270, 'n_words': 304}