<commit_before>package busymachines.effects

import busymachines.core.Anomaly
import busymachines.duration, duration.FiniteDuration

import scala.util._
import scala.util.control.NonFatal

/**
  *
  * @author <NAME>, <EMAIL>, <EMAIL>
  * @since 27 Jan 2018
  *
  */
trait TaskEffectsSyntaxImplicits {

  implicit def bmCommonsTaskEffectsOpsSyntax[T](task: Task[T]): TaskEffectsOpsSyntax[T] =
    new TaskEffectsOpsSyntax(task)

  implicit def bmCommonsBooleanAsTaskOps(b: Boolean): BooleanAsTaskOps =
    new BooleanAsTaskOps(b)

  implicit def bmCommonsTaskBooleanAsTaskOps(task: Task[Boolean]): TaskBooleanAsTaskOps =
    new TaskBooleanAsTaskOps(task)

  implicit def bmCommonsTaskOptionAsTaskOps[T](topt: Task[Option[T]]): TaskOptionAsTaskOps[T] =
    new TaskOptionAsTaskOps(topt)

  implicit def bmCommonsTaskResultAsTaskOps[T](tr: Task[Result[T]]): TaskResultAsTaskOps[T] =
    new TaskResultAsTaskOps(tr)

  implicit def bmCommonsTaskCompanionOps(task: Task.type): TaskCompanionOps =
    new TaskCompanionOps(task)

}

/**
  *
  */
final class TaskCompanionOps(val io: Task.type) {
  def fail[T](a: Anomaly): Task[T] = TaskEffectsUtil.fail(a)

  def fromResult[T](r: Result[T]) = TaskEffectsUtil.fromResult(r)

  def fromResultSuspend[T](r: => Result[T]) = TaskEffectsUtil.fromResultSuspend(r)

  def fromTry[T](t: Try[T]): Task[T] = TaskEffectsUtil.fromTry(t)

  def fromTrySuspend[T](t: => Try[T]): Task[T] = TaskEffectsUtil.fromTrySuspend(t)

  def fromOption[T](opt: Option[T], ifNone: => Anomaly): Task[T] = TaskEffectsUtil.fromOption(opt, ifNone)

  def fromOptionWeak[T](opt: Option[T], ifNone: => Throwable): Task[T] = TaskEffectsUtil.fromOptionWeak(opt, ifNone)

  def fromPureFuture[T](f: Future[T]): Task[T] = TaskEffectsUtil.fromPureFuture(f)

  def fromFutureSuspend[T](f: => Future[T]): Task[T] =
    TaskEffectsUtil.fromFutureSuspend(f)

  def fromIO[T](io: IO[T]): Task[T] = TaskEffectsUtil.fromIO(io)

  def cond[T](test: Boolean, correct: => T, anomaly: => Anomaly): Task[T] = TaskEffectsUtil.cond(test, correct, anomaly)

  def condWith[T](test: Boolean, correct: => Task[T], anomaly: => Anomaly): Task[T] =
    TaskEffectsUtil.condWith(test, correct, anomaly)

  def failOnTrue(test: Boolean, anomaly: => Anomaly): Task[Unit] = TaskEffectsUtil.failOnTrue(test, anomaly)

  def failOnFalse(test: Boolean, anomaly: => Anomaly): Task[Unit] = TaskEffectsUtil.failOnFalse(test, anomaly)

  def flatCond[T](test: Task[Boolean], correct: => T, anomaly: => Anomaly): Task[T] =
    TaskEffectsUtil.flatCond(test, correct, anomaly)

  def flatCondWith[T](test: Task[Boolean], correct: => Task[T], anomaly: => Anomaly): Task[T] =
    TaskEffectsUtil.flatCondWith(test, correct, anomaly)

  def flatFailOnTrue(test: Task[Boolean], anomaly: => Anomaly): Task[Unit] =
    TaskEffectsUtil.flatFailOnTrue(test, anomaly)

  def flatFailOnFalse(test: Task[Boolean], anomaly: => Anomaly): Task[Unit] =
    TaskEffectsUtil.flatFailOnFalse(test, anomaly)

  def effectOnTrue[T](test: Boolean, eff: => Task[T]): Task[Unit] = TaskEffectsUtil.effectOnTrue(test, eff)

  def effectOnFalse[T](test: Boolean, eff: => Task[T]): Task[Unit] = TaskEffectsUtil.effectOnFalse(test, eff)

  def flatEffectOnTrue[T](test: Task[Boolean], eff: => Task[T]): Task[Unit] =
    TaskEffectsUtil.flatEffectOnTrue(test, eff)

  def flatEffectOnFalse[T](test: Task[Boolean], eff: => Task[T]): Task[Unit] =
    TaskEffectsUtil.flatEffectOnFalse(test, eff)

  def discardContent[T](f: Task[T]) = TaskEffectsUtil.discardContent(f)

  def optionFlatten[T](fopt: Task[Option[T]], ifNone: => Anomaly): Task[T] =
    TaskEffectsUtil.flattenOption(fopt, ifNone)

  def optionFlattenWeak[T](fopt: Task[Option[T]], ifNone: => Throwable): Task[T] =
    TaskEffectsUtil.flattenOptionWeak(fopt, ifNone)

  def flattenResult[T](fr: Task[Result[T]]): Task[T] =
    TaskEffectsUtil.flattenResult(fr)

  def asIO[T](io: Task[T])(implicit s: Scheduler): IO[T] = TaskEffectsUtil.asIO(io)

  /**
    * !!! USE WITH CARE !!!
    *
    * Using this is highly discouraged!
    *
    * Only for testing and legacy code interop
    */
  def asFuture[T](io: Task[T])(implicit s: Scheduler): Future[T] = TaskEffectsUtil.asFuture(io)

  /**
    * Similar to [[Task#attempt]], but gives you a result instead of an Either
    */
  def asResult[T](io: Task[T]): Task[Result[T]] = TaskEffectsUtil.asResult(io)

  /**
    * !!! USE WITH CARE !!!
    *
    * Only for testing
    */
  def syncUnsafeAsResult[T](io: Task[T])(implicit s: Scheduler): Result[T] = TaskEffectsUtil.syncUnsafeAsResult(io)

  /**
    * !!! USE WITH CARE !!!
    *
    * Using this is highly discouraged!
    *
    * Only for testing
    */
  def syncUnsafeGet[T](io: Task[T], timeout: FiniteDuration = duration.minutes(1))(implicit s: Scheduler): T =
    TaskEffectsUtil.syncUnsafeGet(io)

  //===========================================================================
  //============================== Transformers ===============================
  //===========================================================================

  def bimap[T, R](io: Task[T], good: T => R, bad: Throwable => Anomaly): Task[R] =<commit_msg>Fix unused parameter #62<commit_after>package busymachines.effects

import busymachines.core.Anomaly
import busymachines.duration, duration.FiniteDuration

import scala.util._
import scala.util.control.NonFatal

/**
  *
  * @author <NAME>, <EMAIL>, <EMAIL>
  * @since 27 Jan 2018
  *
  */
trait TaskEffectsSyntaxImplicits {

  implicit def bmCommonsTaskEffectsOpsSyntax[T](task: Task[T]): TaskEffectsOpsSyntax[T] =
    new TaskEffectsOpsSyntax(task)

  implicit def bmCommonsBooleanAsTaskOps(b: Boolean): BooleanAsTaskOps =
    new BooleanAsTaskOps(b)

  implicit def bmCommonsTaskBooleanAsTaskOps(task: Task[Boolean]): TaskBooleanAsTaskOps =
    new TaskBooleanAsTaskOps(task)

  implicit def bmCommonsTaskOptionAsTaskOps[T](topt: Task[Option[T]]): TaskOptionAsTaskOps[T] =
    new TaskOptionAsTaskOps(topt)

  implicit def bmCommonsTaskResultAsTaskOps[T](tr: Task[Result[T]]): TaskResultAsTaskOps[T] =
    new TaskResultAsTaskOps(tr)

  implicit def bmCommonsTaskCompanionOps(task: Task.type): TaskCompanionOps =
    new TaskCompanionOps(task)

}

/**
  *
  */
final class TaskCompanionOps(val io: Task.type) {
  def fail[T](a: Anomaly): Task[T] = TaskEffectsUtil.fail(a)

  def fromResult[T](r: Result[T]) = TaskEffectsUtil.fromResult(r)

  def fromResultSuspend[T](r: => Result[T]) = TaskEffectsUtil.fromResultSuspend(r)

  def fromTry[T](t: Try[T]): Task[T] = TaskEffectsUtil.fromTry(t)

  def fromTrySuspend[T](t: => Try[T]): Task[T] = TaskEffectsUtil.fromTrySuspend(t)

  def fromOption[T](opt: Option[T], ifNone: => Anomaly): Task[T] = TaskEffectsUtil.fromOption(opt, ifNone)

  def fromOptionWeak[T](opt: Option[T], ifNone: => Throwable): Task[T] = TaskEffectsUtil.fromOptionWeak(opt, ifNone)

  def fromPureFuture[T](f: Future[T]): Task[T] = TaskEffectsUtil.fromPureFuture(f)

  def fromFutureSuspend[T](f: => Future[T]): Task[T] =
    TaskEffectsUtil.fromFutureSuspend(f)

  def fromIO[T](io: IO[T]): Task[T] = TaskEffectsUtil.fromIO(io)

  def cond[T](test: Boolean, correct: => T, anomaly: => Anomaly): Task[T] = TaskEffectsUtil.cond(test, correct, anomaly)

  def condWith[T](test: Boolean, correct: => Task[T], anomaly: => Anomaly): Task[T] =
    TaskEffectsUtil.condWith(test, correct, anomaly)

  def failOnTrue(test: Boolean, anomaly: => Anomaly): Task[Unit] = TaskEffectsUtil.failOnTrue(test, anomaly)

  def failOnFalse(test: Boolean, anomaly: => Anomaly): Task[Unit] = TaskEffectsUtil.failOnFalse(test, anomaly)

  def flatCond[T](test: Task[Boolean], correct: => T, anomaly: => Anomaly): Task[T] =
    TaskEffectsUtil.flatCond(test, correct, anomaly)

  def flatCondWith[T](test: Task[Boolean], correct: => Task[T], anomaly: => Anomaly): Task[T] =
    TaskEffectsUtil.flatCondWith(test, correct, anomaly)

  def flatFailOnTrue(test: Task[Boolean], anomaly: => Anomaly): Task[Unit] =
    TaskEffectsUtil.flatFailOnTrue(test, anomaly)

  def flatFailOnFalse(test: Task[Boolean], anomaly: => Anomaly): Task[Unit] =
    TaskEffectsUtil.flatFailOnFalse(test, anomaly)

  def effectOnTrue[T](test: Boolean, eff: => Task[T]): Task[Unit] = TaskEffectsUtil.effectOnTrue(test, eff)

  def effectOnFalse[T](test: Boolean, eff: => Task[T]): Task[Unit] = TaskEffectsUtil.effectOnFalse(test, eff)

  def flatEffectOnTrue[T](test: Task[Boolean], eff: => Task[T]): Task[Unit] =
    TaskEffectsUtil.flatEffectOnTrue(test, eff)

  def flatEffectOnFalse[T](test: Task[Boolean], eff: => Task[T]): Task[Unit] =
    TaskEffectsUtil.flatEffectOnFalse(test, eff)

  def discardContent[T](f: Task[T]) = TaskEffectsUtil.discardContent(f)

  def optionFlatten[T](fopt: Task[Option[T]], ifNone: => Anomaly): Task[T] =
    TaskEffectsUtil.flattenOption(fopt, ifNone)

  def optionFlattenWeak[T](fopt: Task[Option[T]], ifNone: => Throwable): Task[T] =
    TaskEffectsUtil.flattenOptionWeak(fopt, ifNone)

  def flattenResult[T](fr: Task[Result[T]]): Task[T] =
    TaskEffectsUtil.flattenResult(fr)

  def asIO[T](io: Task[T])(implicit s: Scheduler): IO[T] = TaskEffectsUtil.asIO(io)

  /**
    * !!! USE WITH CARE !!!
    *
    * Using this is highly discouraged!
    *
    * Only for testing and legacy code interop
    */
  def asFuture[T](io: Task[T])(implicit s: Scheduler): Future[T] = TaskEffectsUtil.asFuture(io)

  /**
    * Similar to [[Task#attempt]], but gives you a result instead of an Either
    */
  def asResult[T](io: Task[T]): Task[Result[T]] = TaskEffectsUtil.asResult(io)

  /**
    * !!! USE WITH CARE !!!
    *
    * Only for testing
    */
  def syncUnsafeAsResult[T](io: Task[T])(implicit s: Scheduler): Result[T] = TaskEffectsUtil.syncUnsafeAsResult(io)

  /**
    * !!! USE WITH CARE !!!
    *
    * Using this is highly discouraged!
    *
    * Only for testing
    */
  def syncUnsafeGet[T](io: Task[T], timeout: FiniteDuration = duration.minutes(1))(implicit s: Scheduler): T =
    TaskEffectsUtil.syncUnsafeGet(io, timeout)

  //===========================================================================
  //============================== Transformers ===============================
  //===========================================================================

  def bimap[T, R](io: Task[T], good: T => R, bad: Throwable => Anomaly): Task[R] =
{'fraction_non_alphanumeric': 0.18527131782945735, 'fraction_numerical': 0.0015503875968992248, 'mean_word_length': 5.374922791846819, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 59, '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': '4440609', 'n_tokens_mistral': 3634, 'n_tokens_neox': 3426, 'n_words': 698}