<commit_before>package doodle

import cats.{Comonad,Monad}
import cats.free.Free
import scala.util.{Random => Rng}
import scala.annotation.tailrec

object random {
  type Random[A] = Free[RandomOp,A]

  sealed abstract class RandomOp[A]
  object RandomOp {
    final case class Always[A](get: A) extends RandomOp[A]
    final case class Discrete[A](elements: Seq[(A, Double)]) extends RandomOp[A]
    final case object RInt extends RandomOp[Int]
    final case class Natural(upperLimit: Int) extends RandomOp[Int]
    final case object RDouble extends RandomOp[Double]
    final case object Normal extends RandomOp[Double]
  }

  implicit val randomInstance: Monad[Random] = Free.freeMonad

  implicit def randomInstances(implicit rng: Rng = scala.util.Random): Comonad[RandomOp] =
    new Comonad[RandomOp] {
      import RandomOp._

      @tailrec
      def pick[A](total: Double, weight: Double, events: Seq[(A, Double)]): A =
        events match {
          case (a, p) :: rest =>
            if(total < weight && weight < (total + p))
              a
            else
              pick(total + p, weight, rest)
          case Nil =>
            throw new Exception("Could not sample---ran out of events!")
        }

      override def coflatMap[A, B](fa: RandomOp[A])(f: (RandomOp[A]) ⇒ B): RandomOp[B] =
        Always(f(fa))
      override def extract[A](x: RandomOp[A]): A =
        x match {
          case Always(a) => a<commit_msg>Update random to work with latest Cats<commit_after>package doodle

import cats.Comonad
import cats.free.Free
import scala.util.{Random => Rng}
import scala.annotation.tailrec

object random {
  type Random[A] = Free[RandomOp,A]

  sealed abstract class RandomOp[A]
  object RandomOp {
    final case class Always[A](get: A) extends RandomOp[A]
    final case class Discrete[A](elements: Seq[(A, Double)]) extends RandomOp[A]
    final case object RInt extends RandomOp[Int]
    final case class Natural(upperLimit: Int) extends RandomOp[Int]
    final case object RDouble extends RandomOp[Double]
    final case object Normal extends RandomOp[Double]
  }

  implicit def randomInstances(implicit rng: Rng = scala.util.Random): Comonad[RandomOp] =
    new Comonad[RandomOp] {
      import RandomOp._

      @tailrec
      def pick[A](total: Double, weight: Double, events: Seq[(A, Double)]): A =
        events match {
          case (a, p) :: rest =>
            if(total < weight && weight < (total + p))
              a
            else
              pick(total + p, weight, rest)
          case Nil =>
            throw new Exception("Could not sample---ran out of events!")
        }

      override def coflatMap[A, B](fa: RandomOp[A])(f: (RandomOp[A]) ⇒ B): RandomOp[B] =
        Always(f(fa))
      override def extract[A](x: RandomOp[A]): A =
        x match {
          case Always(a) => a
{'fraction_non_alphanumeric': 0.11322081575246132, 'fraction_numerical': 0.0, 'mean_word_length': 2.8085676037483265, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3857879', 'n_tokens_mistral': 882, 'n_tokens_neox': 875, 'n_words': 270}