<commit_before>package io.github.hamsters

import scala.concurrent.{ExecutionContext, Future}

case class FutureOption[A](override val wrapped: Future[Option[A]]) extends OptionT[A, Future](wrapped)

class OptionT[A, Box[_]](val wrapped: Box[Option[A]]) {

  /**
    * Returns the result of applying f to this FutureOption if this FutureOption is not empty
    * @param f
    * @param ec
    * @tparam B
    * @return a new FutureOption
    */
  def flatMap[B](f: A => OptionT[B, Box])(implicit ec: ExecutionContext, evidence: Monad[Box]): OptionT[B, Box] = {
    val newBox = evidence.flatMap(wrapped) {
      case Some(a) => f(a).wrapped
      case None => evidence.pure(None: Option[B])
    }
    new OptionT(newBox)
  }

  /**
    * Returns the result of applying f to this FutureOption if this FutureOption is not empty
    * @param f
    * @param ec
    * @tparam B
    * @return a new FutureOption
    */
  def map[B](f: A => B)(implicit ec: ExecutionContext, evidence: Monad[Box]): OptionT[B, Box] = {
    new OptionT(evidence.map(wrapped)((option: Option[A]) => option.map(f)))
  }

  /**
    * Keep only values which satisfy a predicate
    * @param p
    * @param ec
    * @return a new FutureOption
    */
  def filter(p: (A) ⇒ Boolean)(implicit ec: ExecutionContext, evidence: Monad[Box]  ): OptionT[A, Box] = withFilter(p)

  /**
    * Keep only values which satisfy a predicate
    * @param p
    * @param ec
    * @return a new FutureOption
    */
  def withFilter(p: (A) ⇒ Boolean)(implicit ec: ExecutionContext, evidence: Monad[Box]): OptionT[A, Box] = {
    new OptionT(evidence.map(wrapped)(_.filter(p)))<commit_msg>no implicit execution context for OptionT<commit_after>package io.github.hamsters

import scala.concurrent.{ExecutionContext, Future}

case class FutureOption[A](override val wrapped: Future[Option[A]]) extends OptionT[A, Future](wrapped)

class OptionT[A, Box[_]](val wrapped: Box[Option[A]]) {

  /**
    * Returns the result of applying f to this FutureOption if this FutureOption is not empty
    * @param f
    * @param ec
    * @tparam B
    * @return a new FutureOption
    */
  def flatMap[B](f: A => OptionT[B, Box])(implicit evidence: Monad[Box]): OptionT[B, Box] = {
    val newBox = evidence.flatMap(wrapped) {
      case Some(a) => f(a).wrapped
      case None => evidence.pure(None: Option[B])
    }
    new OptionT(newBox)
  }

  /**
    * Returns the result of applying f to this FutureOption if this FutureOption is not empty
    * @param f
    * @param ec
    * @tparam B
    * @return a new FutureOption
    */
  def map[B](f: A => B)(implicit evidence: Monad[Box]): OptionT[B, Box] = {
    new OptionT(evidence.map(wrapped)((option: Option[A]) => option.map(f)))
  }

  /**
    * Keep only values which satisfy a predicate
    * @param p
    * @param ec
    * @return a new FutureOption
    */
  def filter(p: (A) ⇒ Boolean)(implicit evidence: Monad[Box]): OptionT[A, Box] = withFilter(p)

  /**
    * Keep only values which satisfy a predicate
    * @param p
    * @param ec
    * @return a new FutureOption
    */
  def withFilter(p: (A) ⇒ Boolean)(implicit evidence: Monad[Box]): OptionT[A, Box] = {
    new OptionT(evidence.map(wrapped)(_.filter(p)))
{'fraction_non_alphanumeric': 0.13644859813084112, 'fraction_numerical': 0.0, 'mean_word_length': 3.3391891891891894, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '6202110', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1056, 'n_words': 318}