<commit_before>package org.atnos.eff

import scala.util.control.NonFatal
import cats.data._
import Xor._
import Eff._
import Interpret._

import scala.concurrent._
import duration._

/**
 * Effect for Future computations
 */
trait FutureEffect extends
  FutureCreation with
  FutureInterpretation

object FutureEffect extends FutureEffect

trait FutureCreation {
  def sync[R, A](a: A)(implicit m: Member[Future, R]): Eff[R, A] =
    pure(a)

  def async[R, A](a: =>A)(implicit m: Member[Future, R], ec: ExecutionContext): Eff[R, A] =
    send(Future(a))
}

trait FutureInterpretation {

//  def awaitFuture[R <: Effects, U <: Effects, A](r: Eff[R, A])(atMost: FiniteDuration)
//    (implicit m: Member.Aux[Future, R, U], ec: ExecutionContext): Eff[U, Throwable Xor A] = {
//
//    r match {
//      case Pure(a) => Eff.pure(Xor.Right(a))
//      case Impure(u, c) =>
//        m.project(u) match {
//          case Xor.Left(u1) => Impure(u1, Arrs.singleton((x: u.X) => awaitFuture(c(x))(atMost)))
//          case Xor.Right(fv) =>
//            try { awaitFuture(c(Await.result(fv, atMost)))(atMost) }
//            catch { case NonFatal(t) => Eff.pure(Left(t)) }
//
//        }
//
//      case ImpureAp(u, c) =>
//        m.project(u) match {
//          case Xor.Left(u1) => Impure(u1, Arrs.singleton((x: u.X) => awaitFuture(c(x))(atMost)))
//          case Xor.Right(fv) =>
//            try Await.result(fv.map(v => awaitFuture(c(v))(atMost)), atMost)
//            catch { case NonFatal(t) => Eff.pure(Left(t)) }
//        }
//    }
//  }

  def awaitFuture[R <: Effects, U <: Effects, A](r: Eff[R, A])(atMost: FiniteDuration)
      (implicit m: Member.Aux[Future, R, U], ec: ExecutionContext): Eff[U, Throwable Xor A] = {
    val recurse = new Recurse[Future, U, Throwable Xor A] {
      def apply[X](m: Future[X]) =
        try { Left(Await.result(m, atMost)) }
        catch { case NonFatal(t) => Right(Eff.pure(Left(t))) }
    }

    interpret1((a: A) => Right(a): Throwable Xor A)(recurse)(r)
  }

}

object FutureInterpretation extends FutureInterpretation

<commit_msg>remove commented-out code for future<commit_after>package org.atnos.eff

import scala.util.control.NonFatal
import cats.data._
import Xor._
import Eff._
import Interpret._

import scala.concurrent._
import duration._

/**
 * Effect for Future computations
 */
trait FutureEffect extends
  FutureCreation with
  FutureInterpretation

object FutureEffect extends FutureEffect

trait FutureCreation {
  def sync[R, A](a: A)(implicit m: Member[Future, R]): Eff[R, A] =
    pure(a)

  def async[R, A](a: =>A)(implicit m: Member[Future, R], ec: ExecutionContext): Eff[R, A] =
    send(Future(a))
}

trait FutureInterpretation {

  def awaitFuture[R <: Effects, U <: Effects, A](r: Eff[R, A])(atMost: FiniteDuration)
      (implicit m: Member.Aux[Future, R, U], ec: ExecutionContext): Eff[U, Throwable Xor A] = {
    val recurse = new Recurse[Future, U, Throwable Xor A] {
      def apply[X](m: Future[X]) =
        try { Left(Await.result(m, atMost)) }
        catch { case NonFatal(t) => Right(Eff.pure(Left(t))) }
    }

    interpret1((a: A) => Right(a): Throwable Xor A)(recurse)(r)
  }

}

object FutureInterpretation extends FutureInterpretation


{'fraction_non_alphanumeric': 0.16289873025704552, 'fraction_numerical': 0.0018581604211830288, 'mean_word_length': 3.2332896461336826, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, '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': '6739440', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1153, 'n_words': 278}