<commit_before>package org.scanamo.ops

import akka.stream.alpakka.dynamodb.AwsOp
import akka.stream.alpakka.dynamodb.scaladsl.DynamoClient
import cats.syntax.either._
import cats.~>
import com.amazonaws.services.dynamodbv2.model._
import org.scanamo.ops.retrypolicy.DefaultRetryPolicy
import org.scanamo.ops.retrypolicy.RetryPolicy
import org.scanamo.ops.retrypolicy.RetryUtility

import scala.concurrent.{ ExecutionContext, Future }

object AlpakkaInterpreter {

  def future(client: DynamoClient, retryPolicy: RetryPolicy)(implicit executor: ExecutionContext): ScanamoOpsA ~> Future =
    new (ScanamoOpsA ~> Future) {
      import akka.stream.alpakka.dynamodb.scaladsl.DynamoImplicits._

      override def apply[A](ops: ScanamoOpsA[A]) =
        ops match {
          case Put(req)        => executeSingleRequest(client, JavaRequests.put(req), retryPolicy)
          case Get(req)        => executeSingleRequest(client, req, retryPolicy)
          case Delete(req)     => executeSingleRequest(client, JavaRequests.delete(req), retryPolicy)
          case Scan(req)       => executeSingleRequest(client, JavaRequests.scan(req), retryPolicy)
          case Query(req)      => executeSingleRequest(client, JavaRequests.query(req), retryPolicy)
          case Update(req)     => executeSingleRequest(client, JavaRequests.update(req), retryPolicy)
          case BatchWrite(req) => executeSingleRequest(client, req, retryPolicy)
          case BatchGet(req)   => executeSingleRequest(client, req, retryPolicy)
          case ConditionalDelete(req) =>
            executeSingleRequest(client, JavaRequests.delete(req), retryPolicy)
              .map(Either.right[ConditionalCheckFailedException, DeleteItemResult])
              .recover {
                case e: ConditionalCheckFailedException => Either.left(e)
              }
          case ConditionalPut(req) =>
            executeSingleRequest(client, JavaRequests.put(req), retryPolicy)
              .map(Either.right[ConditionalCheckFailedException, PutItemResult])
              .recover {
                case e: ConditionalCheckFailedException => Either.left(e)
              }
          case ConditionalUpdate(req) =>
            executeSingleRequest(client, JavaRequests.update(req), retryPolicy)
              .map(Either.right[ConditionalCheckFailedException, UpdateItemResult])
              .recover {
                case e: ConditionalCheckFailedException => Either.left(e)
              }
        }
    }

  def executeSingleRequest(client: DynamoClient, op: AwsOp, retryPolicy: RetryPolicy)(implicit executor: ExecutionContext) = {
    def future() = client.single(op)
    val exponentialRetryPolicy = DefaultRetryPolicy.getPolicy(retryPolicy)
    RetryUtility.retryWithBackOff(future(), exponentialRetryPolicy)
  }
}
<commit_msg>formatted Alpakka Interpretor<commit_after>package org.scanamo.ops

import akka.stream.alpakka.dynamodb.AwsOp
import akka.stream.alpakka.dynamodb.scaladsl.DynamoClient
import cats.syntax.either._
import cats.~>
import com.amazonaws.services.dynamodbv2.model._
import org.scanamo.ops.retrypolicy._

import scala.concurrent.{ExecutionContext, Future}

object AlpakkaInterpreter {

  def future(client: DynamoClient,
             retryPolicy: RetryPolicy)(implicit executor: ExecutionContext): ScanamoOpsA ~> Future =
    new (ScanamoOpsA ~> Future) {
      import akka.stream.alpakka.dynamodb.scaladsl.DynamoImplicits._

      override def apply[A](ops: ScanamoOpsA[A]) =
        ops match {
          case Put(req)        => executeSingleRequest(client, JavaRequests.put(req), retryPolicy)
          case Get(req)        => executeSingleRequest(client, req, retryPolicy)
          case Delete(req)     => executeSingleRequest(client, JavaRequests.delete(req), retryPolicy)
          case Scan(req)       => executeSingleRequest(client, JavaRequests.scan(req), retryPolicy)
          case Query(req)      => executeSingleRequest(client, JavaRequests.query(req), retryPolicy)
          case Update(req)     => executeSingleRequest(client, JavaRequests.update(req), retryPolicy)
          case BatchWrite(req) => executeSingleRequest(client, req, retryPolicy)
          case BatchGet(req)   => executeSingleRequest(client, req, retryPolicy)
          case ConditionalDelete(req) =>
            executeSingleRequest(client, JavaRequests.delete(req), retryPolicy)
              .map(Either.right[ConditionalCheckFailedException, DeleteItemResult])
              .recover {
                case e: ConditionalCheckFailedException => Either.left(e)
              }
          case ConditionalPut(req) =>
            executeSingleRequest(client, JavaRequests.put(req), retryPolicy)
              .map(Either.right[ConditionalCheckFailedException, PutItemResult])
              .recover {
                case e: ConditionalCheckFailedException => Either.left(e)
              }
          case ConditionalUpdate(req) =>
            executeSingleRequest(client, JavaRequests.update(req), retryPolicy)
              .map(Either.right[ConditionalCheckFailedException, UpdateItemResult])
              .recover {
                case e: ConditionalCheckFailedException => Either.left(e)
              }
        }
    }

  def executeSingleRequest(client: DynamoClient,
                           op: AwsOp,
                           retryPolicy: RetryPolicy)(implicit executor: ExecutionContext): Future[AwsOp#B] = {
    def future() = client.single(op)
    val exponentialRetryPolicy = DefaultRetryPolicy.getPolicy(retryPolicy)
    RetryUtility.retryWithBackOff(future(), exponentialRetryPolicy)
  }
}

{'fraction_non_alphanumeric': 0.09477825464949928, 'fraction_numerical': 0.000357653791130186, 'mean_word_length': 3.1155261221486388, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, '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': '4554416', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1549, 'n_words': 272}