<commit_before>package provingground

import scala.language.higherKinds

import cats._

//import cats.data.Prod

import cats.implicits._

trait Equiv[X[_], Y[_]] {
  def map[A]: X[A] => Y[A]

  def inv[A]: Y[A] => X[A]
}

object Functors {
  // type T = List[?]

  def liftMap[A, B, F[_]: Functor](fa: F[A], f: A => B) = {
    implicitly[Functor[F]].map(fa)(f)
  }

  implicit def composeFunctors[X[_]: Functor, Y[_]: Functor] =
    new Functor[({ type Z[A] = X[Y[A]] })#Z] {
      def map[A, B](fa: X[Y[A]])(f: A => B) = {
        val inner = (y: Y[A]) => implicitly[Functor[Y]].map(y)(f)
        implicitly[Functor[X]].map(fa)(inner)
      }
    }

  implicit def constantFunctor[Cn] =
    new Functor[({ type Z[A] = Cn })#Z] {
      def map[A, B](fa: Cn)(f: A => B) = fa
    }
//    new ConstFunc[C].Func

  implicit def augmentedFunctor[Cn, X[_]: Functor] =
    new Functor[({ type Z[A] = (Cn, X[A]) })#Z] {
      def map[A, B](fa: (Cn, X[A]))(f: A => B) =
        (fa._1, implicitly[Functor[X]].map(fa._2)(f))
    }

  type Named[A] = (String, Id[A])

  implicit def t2[X[_]: Functor, Y[_]: Functor] =
    new Functor[({ type Z[A] = (X[A], Y[A]) })#Z] {
      def map[A, B](fa: (X[A], Y[A]))(f: A => B) =
        (implicitly[Functor[X]].map(fa._1)(f),
         implicitly[Functor[Y]].map(fa._2)(f))
    }

  type LL[A] = (List[A], List[A]);

  type IL[A] = (Id[A], List[A]);

  type II[A] = (Id[A], Id[A]);

  implicit def traversePair[X[_]: Traverse, Y[_]: Traverse]
    : Traverse[({ type Z[A] = (X[A], Y[A]) })#Z] =
    new Traverse[({ type Z[A] = (X[A], Y[A]) })#Z] {
      val XT = implicitly[Traverse[X]]
      val YT = implicitly[Traverse[Y]]

      type F[A] = (X[A], Y[A])
      def traverse[G[_]: Applicative, A, B](fa: F[A])(
          f: A => G[B]): G[(X[B], Y[B])] = {
        val GA = implicitly[Applicative[G]]
        val gy = YT.traverse(fa._2)(f)
        val gx = XT.traverse(fa._1)(f)
        val gf = gy.map((y: Y[B]) => ((x: X[B]) => (x, y)))
        GA.ap(gf)(gx)
      }
      def foldLeft[A, B](fa: (X[A], Y[A]), b: B)(f: (B, A) => B): B = {
        val fy = YT.foldLeft(fa._2, b)(f)
        XT.foldLeft(fa._1, fy)(f)
      }
      def foldRight[A, B](fa: (X[A], Y[A]), lb: cats.Eval[B])(
          f: (A, cats.Eval[B]) => cats.Eval[B]): cats.Eval[B] = {
        val fxe = XT.foldRight(fa._1, lb)(f)
        YT.foldRight(fa._2, fxe)(f)
      }
    }

  implicit def traverseCompose[X[_]: Traverse, Y[_]: Traverse]
    : Traverse[({ type Z[A] = X[Y[A]] })#Z] =
    new Traverse[({ type Z[A] = X[Y[A]] })#Z] {
      type F[A] = X[Y[A]]

      val ty = implicitly[Traverse[Y]]

      val tx = implicitly[Traverse[X]]

      def traverse[G[_]: Applicative, A, B](fa: F[A])(f: A => G[B]): G[F[B]] = {
        def g(y: Y[A]) = ty.traverse(y)(f)
        tx.traverse(fa)(g)
      }

      def foldLeft[A, B](fa: X[Y[A]], b: B)(f: (B, A) => B): B = {
        val g: (B, Y[A]) => B = { case (b, ya) => ty.foldLeft(ya, b)(f) }
        tx.foldLeft(fa, b)(g)
      }

      def foldRight[A, B](fa: X[Y[A]], lb: cats.Eval[B])(
          f: (A, cats.Eval[B]) => cats.Eval[B]): cats.Eval[B] = {
        val g: (Y[A], Eval[B]) => Eval[B] = {
          case (ya, b) => ty.foldRight(ya, b)(f)<commit_msg>shapeless HList traverse, ready for use in place of (_,_)<commit_after>package provingground

import scala.language.higherKinds

import cats._

//import cats.data.Prod

import cats.implicits._

trait Equiv[X[_], Y[_]] {
  def map[A]: X[A] => Y[A]

  def inv[A]: Y[A] => X[A]
}

object Functors {
  // type T = List[?]

  def liftMap[A, B, F[_]: Functor](fa: F[A], f: A => B) = {
    implicitly[Functor[F]].map(fa)(f)
  }

  implicit def composeFunctors[X[_]: Functor, Y[_]: Functor] =
    new Functor[({ type Z[A] = X[Y[A]] })#Z] {
      def map[A, B](fa: X[Y[A]])(f: A => B) = {
        val inner = (y: Y[A]) => implicitly[Functor[Y]].map(y)(f)
        implicitly[Functor[X]].map(fa)(inner)
      }
    }

  implicit def constantFunctor[Cn] =
    new Functor[({ type Z[A] = Cn })#Z] {
      def map[A, B](fa: Cn)(f: A => B) = fa
    }
//    new ConstFunc[C].Func

  implicit def augmentedFunctor[Cn, X[_]: Functor] =
    new Functor[({ type Z[A] = (Cn, X[A]) })#Z] {
      def map[A, B](fa: (Cn, X[A]))(f: A => B) =
        (fa._1, implicitly[Functor[X]].map(fa._2)(f))
    }

  type Named[A] = (String, Id[A])

  implicit def t2[X[_]: Functor, Y[_]: Functor] =
    new Functor[({ type Z[A] = (X[A], Y[A]) })#Z] {
      def map[A, B](fa: (X[A], Y[A]))(f: A => B) =
        (implicitly[Functor[X]].map(fa._1)(f),
         implicitly[Functor[Y]].map(fa._2)(f))
    }

  type LL[A] = (List[A], List[A]);

  type IL[A] = (Id[A], List[A]);

  type II[A] = (Id[A], Id[A]);

  implicit def traversePair[X[_]: Traverse, Y[_]: Traverse]
    : Traverse[({ type Z[A] = (X[A], Y[A]) })#Z] =
    new Traverse[({ type Z[A] = (X[A], Y[A]) })#Z] {
      val XT = implicitly[Traverse[X]]
      val YT = implicitly[Traverse[Y]]

      type F[A] = (X[A], Y[A])
      def traverse[G[_]: Applicative, A, B](fa: F[A])(
          f: A => G[B]): G[(X[B], Y[B])] = {
        val GA = implicitly[Applicative[G]]
        val gy = YT.traverse(fa._2)(f)
        val gx = XT.traverse(fa._1)(f)
        val gf = gy.map((y: Y[B]) => ((x: X[B]) => (x, y)))
        GA.ap(gf)(gx)
      }
      def foldLeft[A, B](fa: (X[A], Y[A]), b: B)(f: (B, A) => B): B = {
        val fy = YT.foldLeft(fa._2, b)(f)
        XT.foldLeft(fa._1, fy)(f)
      }
      def foldRight[A, B](fa: (X[A], Y[A]), lb: cats.Eval[B])(
          f: (A, cats.Eval[B]) => cats.Eval[B]): cats.Eval[B] = {
        val fxe = XT.foldRight(fa._1, lb)(f)
        YT.foldRight(fa._2, fxe)(f)
      }
    }

  import shapeless._
  import HList._

  implicit def traverseHCons[X[_]: Traverse, Y[_] <: HList : Traverse]: Traverse[({ type Z[A] = X[A] :: Y[A] })#Z] =
    new Traverse[({ type Z[A] = X[A] :: Y[A] })#Z] {
      val XT = implicitly[Traverse[X]]
      val YT = implicitly[Traverse[Y]]

      type F[A] = X[A] :: Y[A]
      def traverse[G[_]: Applicative, A, B](fa: F[A])(
          f: A => G[B]): G[X[B] :: Y[B]] = {
        val GA = implicitly[Applicative[G]]
        val gy = YT.traverse(fa.tail)(f)
        val gx = XT.traverse(fa.head)(f)
        val gf = gy.map((y: Y[B]) => ((x: X[B]) => x :: y))
        GA.ap(gf)(gx)
      }
      def foldLeft[A, B](fa: X[A] :: Y[A], b: B)(f: (B, A) => B): B = {
        val fy = YT.foldLeft(fa.tail, b)(f)
        XT.foldLeft(fa.head, fy)(f)
      }
      def foldRight[A, B](fa: X[A] :: Y[A], lb: cats.Eval[B])(
          f: (A, cats.Eval[B]) => cats.Eval[B]): cats.Eval[B] = {
        val fxe = XT.foldRight(fa.head, lb)(f)
        YT.foldRight(fa.tail, fxe)(f)
      }
    }

  implicit def traverseCompose[X[_]: Traverse, Y[_]: Traverse]
    : Traverse[({ type Z[A] = X[Y[A]] })#Z] =
    new Traverse[({ type Z[A] = X[Y[A]] })#Z] {
      type F[A] = X[Y[A]]

      val ty = implicitly[Traverse[Y]]

      val tx = implicitly[Traverse[X]]

      def traverse[G[_]: Applicative, A, B](fa: F[A])(f: A => G[B]): G[F[B]] = {
        def g(y: Y[A]) = ty.traverse(y)(f)
        tx.traverse(fa)(g)
      }

      def foldLeft[A, B](fa: X[Y[A]], b: B)(f: (B, A) => B): B = {
        val g: (B, Y[A]) => B = { case (b, ya) => ty.foldLeft(ya, b)(f) }
        tx.foldLeft(fa, b)(g)
      }

      def foldRight[A, B](fa: X[Y[A]], lb: cats.Eval[B])(
          f: (A, cats.Eval[B]) => cats.Eval[B]): cats.Eval[B] = {
        val g: (Y[A], Eval[B]) => Eval[B] = {
          case (ya, b) => ty.foldRight(ya, b)(f)
{'fraction_non_alphanumeric': 0.24506403415154748, 'fraction_numerical': 0.002934898612593383, 'mean_word_length': 2.513120899718838, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 48, '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': '5099653', 'n_tokens_mistral': 3402, 'n_tokens_neox': 3323, 'n_words': 732}