Skip to content

Commit

Permalink
Update formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszKubuszok committed Jul 24, 2023
1 parent e9c8e48 commit 97951f0
Show file tree
Hide file tree
Showing 45 changed files with 209 additions and 247 deletions.
6 changes: 4 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ fileOverride {

align.preset = some

rewrite.rules = [Imports, SortModifiers]
rewrite.rules = [Imports, RedundantBraces, SortModifiers]
rewrite.imports.sort = scalastyle
rewrite.redundantBraces.stringInterpolation = true

rewrite.scala3.convertToNewSyntax = true
rewrite.scala3.removeOptionalBraces = false

docstrings.style = keep
docstrings.blankFirstLine = no
docstrings.style = SpaceAsterisk
docstrings.wrap = no

newlines.sometimesBeforeColonInMethodReturnType = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import language.implicitConversions
trait CatsPartialTransformerImplicits extends CatsPartialTransformerLowPriorityImplicits1 {

/** @since 0.7.0 */
implicit final val semigroupPartialResultErrors: Semigroup[partial.Result.Errors] = {
implicit final val semigroupPartialResultErrors: Semigroup[partial.Result.Errors] =
Semigroup.instance(partial.Result.Errors.merge)
}

/** @since 0.7.0 */
implicit final val applicativePartialResult: Applicative[partial.Result] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,23 @@ object ValidatedUtils {

implicit class OptionOps[T](private val opt: Option[T]) extends AnyVal {

def toValidated[EE[_]: InvariantMonoidal](err: => String): Validated[EE[String], T] = {
def toValidated[EE[_]: InvariantMonoidal](err: => String): Validated[EE[String], T] =
opt match {
case Some(value) => Validated.Valid(value)
case None => Validated.Invalid(InvariantMonoidal[EE].point(err))
}
}

def toValidatedNec(err: => String): ValidatedNec[String, T] =
toValidated[NonEmptyChain](err)(implicitly)

def toValidatedNel(err: => String): ValidatedNel[String, T] =
toValidated[NonEmptyList](err)(implicitly)

def toIor[EE[_]: InvariantMonoidal](err: => String): Ior[EE[String], T] = {
def toIor[EE[_]: InvariantMonoidal](err: => String): Ior[EE[String], T] =
opt match {
case Some(value) => Ior.Right(value)
case None => Ior.Left(InvariantMonoidal[EE].point(err))
}
}

def toIorNec(err: => String): IorNec[String, T] =
toIor[NonEmptyChain](err)(implicitly)
Expand All @@ -53,8 +51,7 @@ object ValidatedUtils {

implicit class ValidatedOps[+E, +A](private val validated: Validated[E, A]) extends AnyVal {

def getValid: A = {
def getValid: A =
validated.valueOr(_ => throw new NoSuchElementException)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private[compiletime] trait ExprsPlatform extends Exprs { this: DefinitionsPlatfo

object Array extends ArrayModule {
def apply[A: Type](args: Expr[A]*): Expr[Array[A]] =
c.Expr[Array[A]](q"_root_.scala.Array[${Type[A]}](..${args})")
c.Expr[Array[A]](q"_root_.scala.Array[${Type[A]}](..$args)")

def map[A: Type, B: Type](array: Expr[Array[A]])(fExpr: Expr[A => B]): Expr[Array[B]] =
if (isScala212)
Expand Down Expand Up @@ -128,7 +128,7 @@ private[compiletime] trait ExprsPlatform extends Exprs { this: DefinitionsPlatfo

def eq[A: Type, B: Type](a: Expr[A], b: Expr[B]): Expr[Boolean] = c.Expr[Boolean](q"$a == $b")

def asInstanceOf[A: Type, B: Type](expr: Expr[A]): Expr[B] = c.Expr[B](q"${expr}.asInstanceOf[${Type[B]}]")
def asInstanceOf[A: Type, B: Type](expr: Expr[A]): Expr[B] = c.Expr[B](q"$expr.asInstanceOf[${Type[B]}]")

def upcast[A: Type, B: Type](expr: Expr[A]): Expr[B] = {
val wideningChecked = expr.widenExpr[B]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ private[compiletime] trait TypesPlatform extends Types { this: DefinitionsPlatfo
// unknown
case out =>
assertionFailed(
s"Constructor of ${Type.prettyPrint(fromUntyped[Any](tpe))} has unrecognized/unsupported format of type: ${out}"
s"Constructor of ${Type.prettyPrint(fromUntyped[Any](tpe))} has unrecognized/unsupported format of type: $out"
)
}

/** Applies type arguments from supertype to subtype if there are any */
def subtypeTypeOf[A: Type](subtype: Symbol): ?<[A] = {
def subtypeTypeOf[A: Type](subtype: Symbol): ?<[A] =
subtype.primaryConstructor.paramSymss match {
// subtype takes type parameters
case typeParamSymbols :: _ if typeParamSymbols.exists(_.isType) =>
Expand All @@ -75,7 +75,6 @@ private[compiletime] trait TypesPlatform extends Types { this: DefinitionsPlatfo
case _ =>
fromUntyped[A](subtype.typeRef).as_?<[A]
}
}
}

val Nothing: Type[Nothing] = quoted.Type.of[Nothing]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package io.scalaland.chimney.internal.compiletime
private[compiletime] trait Existentials { this: Types with Exprs =>

/** Represents value with some existential type and Type using the same existential.
*
* Since Scala 3 removed a lot of cases for existential types we cannot just use Type[?] in shared code.
* Additionally, we might need to have something to prove that our Type[?] is has the same ? as some Value[?].
* For that, this utility would be useful.
*/
*
* Since Scala 3 removed a lot of cases for existential types we cannot just use Type[?] in shared code.
* Additionally, we might need to have something to prove that our Type[?] is has the same ? as some Value[?].
* For that, this utility would be useful.
*/
final protected type Existential[F[_]] = Existential.Bounded[Nothing, Any, F]
protected object Existential {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ private[compiletime] trait ExprPromises { this: Definitions =>
protected type ExprPromiseName

/** Allow us to use `Expr[A]` before we would either: know how we would initiate it, or: what the final shape of
* a whole expression would be.
*
* In situations like `'{ val a = sth; ${ useA('{ a }) } } ` you know both how `a` would be created as well as
* the shape of the final tree. In cases when you would e.g. use expression in some context-dependent derivation
* which could return `Either[Expr[B], Expr[F[B]]`, ExprPromise allows you to calculate that result and THEN decide
* how to turn it into final Expr value.
*
* @tparam From type of the promised expression
* @tparam A type of the current result we created using Expr[From]
*/
* a whole expression would be.
*
* In situations like `'{ val a = sth; ${ useA('{ a }) } } ` you know both how `a` would be created as well as
* the shape of the final tree. In cases when you would e.g. use expression in some context-dependent derivation
* which could return `Either[Expr[B], Expr[F[B]]`, ExprPromise allows you to calculate that result and THEN decide
* how to turn it into final Expr value.
*
* @tparam From type of the promised expression
* @tparam A type of the current result we created using Expr[From]
*/
final protected class ExprPromise[From: Type, A](private val usage: A, private val fromName: ExprPromiseName) {

def map[B](f: A => B): ExprPromise[From, B] = new ExprPromise(f(usage), fromName)
Expand Down Expand Up @@ -80,12 +80,12 @@ private[compiletime] trait ExprPromises { this: Definitions =>
protected trait ExprPromiseModule { this: ExprPromise.type =>

/** Creates the expression promise.
*
* @param nameGenerationStrategy to avoid accidental name clashing, we are using fresh name generator which
* assures us that the name would be unique, we are only choosing the prefix
* @param usageHint if we'll fulfil promise as val/lazy val/var it let us decide as which
* @tparam From type of promised expression
*/
*
* @param nameGenerationStrategy to avoid accidental name clashing, we are using fresh name generator which
* assures us that the name would be unique, we are only choosing the prefix
* @param usageHint if we'll fulfil promise as val/lazy val/var it let us decide as which
* @tparam From type of promised expression
*/
final def promise[From: Type](
nameGenerationStrategy: NameGenerationStrategy,
usageHint: UsageHint = UsageHint.None
Expand Down Expand Up @@ -135,9 +135,9 @@ private[compiletime] trait ExprPromises { this: Definitions =>
}

/** When we decide that promised expression would be used as val/lazy val/var/def, we receive this wrapper around
* the results, which would ensure that: initialization of a definition would happen before its use, you can only use
* the definition inside its scope.
*/
* the results, which would ensure that: initialization of a definition would happen before its use, you can only use
* the definition inside its scope.
*/
final protected class PrependDefinitionsTo[A](
private val usage: A,
private val defns: Vector[(ExprPromiseName, ExistentialExpr, PrependDefinitionsTo.DefnType)]
Expand Down Expand Up @@ -212,9 +212,9 @@ private[compiletime] trait ExprPromises { this: Definitions =>
}

/** When we decide that expression would be crated in patter-match binding, we would receive this wrapper around
* the results, which would ensure that definition is only used inside the scope and allow combining several cases
* into a single pattern matching.
*/
* the results, which would ensure that definition is only used inside the scope and allow combining several cases
* into a single pattern matching.
*/
final protected class PatternMatchCase[To](
val someFrom: ??,
val usage: Expr[To],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ trait ProductTypes { this: Definitions =>
final type Arguments = Map[String, ExistentialExpr]

/** Let us obtain a list of primary constructor's parameters as well as setter parameters, as well as a method
* of taking all computed arguments and turning it into constructed value. */
* of taking all computed arguments and turning it into constructed value.
*/
final case class Constructor[To](parameters: Parameters, constructor: Arguments => Expr[To])
object Constructor {
def unapply[To](To: Type[To]): Option[(Parameters, Arguments => Expr[To])] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import scala.language.experimental.macros
private[chimney] trait PartialTransformerCompanionPlatform { this: PartialTransformer.type =>

/** Provides [[io.scalaland.chimney.PartialTransformer]] derived with the default settings.
*
* When transformation can't be derived, it results with compilation error.
*
* @tparam From type of input value
* @tparam To type of output value
* @return [[io.scalaland.chimney.PartialTransformer]] type class definition
* @since 0.7.0
*/
*
* When transformation can't be derived, it results with compilation error.
*
* @tparam From type of input value
* @tparam To type of output value
* @return [[io.scalaland.chimney.PartialTransformer]] type class definition
* @since 0.7.0
*/
def derive[From, To]: PartialTransformer[From, To] =
macro TransformerMacros.derivePartialTransformerWithDefaults[From, To]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import scala.language.experimental.macros
private[chimney] trait PatcherCompanionPlatform { this: Patcher.type =>

/** Provides implicit [[io.scalaland.chimney.Patcher]] instance
* for arbitrary types.
*
* @tparam A type of object to apply patch to
* @tparam Patch type of patch object
* @return [[io.scalaland.chimney.Patcher]] type class instance
* @since 0.2.0
*/
* for arbitrary types.
*
* @tparam A type of object to apply patch to
* @tparam Patch type of patch object
* @return [[io.scalaland.chimney.Patcher]] type class instance
* @since 0.2.0
*/
implicit def derive[A, Patch]: Patcher[A, Patch] =
macro PatcherMacros.derivePatcherImpl[A, Patch]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import scala.language.experimental.macros
private[chimney] trait TransformerCompanionPlatform { this: Transformer.type =>

/** Provides [[io.scalaland.chimney.Transformer]] derived with the default settings.
*
* When transformation can't be derived, it results with compilation error.
*
* @tparam From type of input value
* @tparam To type of output value
* @return [[io.scalaland.chimney.Transformer]] type class instance
* @since 0.2.0
*/
*
* When transformation can't be derived, it results with compilation error.
*
* @tparam From type of input value
* @tparam To type of output value
* @return [[io.scalaland.chimney.Transformer]] type class instance
* @since 0.2.0
*/
def derive[From, To]: Transformer[From, To] =
macro TransformerMacros.deriveTotalTransformerWithDefaults[From, To]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class PartialTransformerDefinition[From, To, Cfg <: TransformerCfg, Flags
* @param selector target field in `To`, defined like `_.name`
* @param value constant value to use for the target field
* @return [[io.scalaland.chimney.dsl.PartialTransformerDefinition]]
*
*
* @since 0.7.0
*/
def withFieldConst[T, U](selector: To => T, value: U)(implicit
Expand All @@ -54,7 +54,7 @@ final class PartialTransformerDefinition[From, To, Cfg <: TransformerCfg, Flags
* @param selector target field in `To`, defined like `_.name`
* @param value constant value to use for the target field
* @return [[io.scalaland.chimney.dsl.PartialTransformerDefinition]]
*
*
* @since 0.7.0
*/
def withFieldConstPartial[T, U](selector: To => T, value: partial.Result[U])(implicit
Expand All @@ -73,7 +73,7 @@ final class PartialTransformerDefinition[From, To, Cfg <: TransformerCfg, Flags
* @param selector target field in `To`, defined like `_.name`
* @param f function used to compute value of the target field
* @return [[io.scalaland.chimney.dsl.PartialTransformerDefinition]]
*
*
* @since 0.7.0
*/
def withFieldComputed[T, U](selector: To => T, f: From => U)(implicit
Expand All @@ -92,7 +92,7 @@ final class PartialTransformerDefinition[From, To, Cfg <: TransformerCfg, Flags
* @param selector target field in `To`, defined like `_.name`
* @param f function used to compute value of the target field
* @return [[io.scalaland.chimney.dsl.PartialTransformerDefinition]]
*
*
* @since 0.7.0
*/
def withFieldComputedPartial[T, U](
Expand All @@ -112,7 +112,7 @@ final class PartialTransformerDefinition[From, To, Cfg <: TransformerCfg, Flags
* @param selectorFrom source field in `From`, defined like `_.originalName`
* @param selectorTo target field in `To`, defined like `_.newName`
* @return [[io.scalaland.chimney.dsl.PartialTransformerDefinition]]
*
*
* @since 0.7.0
*/
def withFieldRenamed[T, U](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final class TransformerDefinition[From, To, Cfg <: TransformerCfg, Flags <: Tran
* @param selector target field in `To`, defined like `_.name`
* @param value constant value to use for the target field
* @return [[io.scalaland.chimney.dsl.TransformerDefinition]]
*
*
* @since 0.4.0
*/
def withFieldConst[T, U](selector: To => T, value: U)(implicit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import io.scalaland.chimney.internal.compiletime.derivation.transformer.Transfor
private[chimney] trait PartialTransformerCompanionPlatform { this: PartialTransformer.type =>

/** Provides [[io.scalaland.chimney.PartialTransformer]] derived with the default settings.
*
* When transformation can't be derived, it results with compilation error.
*
* @tparam From type of input value
* @tparam To type of output value
* @return [[io.scalaland.chimney.PartialTransformer]] type class definition
* @since 0.8.0
*/
*
* When transformation can't be derived, it results with compilation error.
*
* @tparam From type of input value
* @tparam To type of output value
* @return [[io.scalaland.chimney.PartialTransformer]] type class definition
* @since 0.8.0
*/
inline def derive[From, To]: PartialTransformer[From, To] =
${ TransformerMacros.derivePartialTransformerWithDefaults[From, To] }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import io.scalaland.chimney.internal.compiletime.derivation.patcher.PatcherMacro
private[chimney] trait PatcherCompanionPlatform { this: Patcher.type =>

/** Provides implicit [[io.scalaland.chimney.Patcher]] instance
* for arbitrary types.
*
* @tparam A type of object to apply patch to
* @tparam Patch type of patch object
* @return [[io.scalaland.chimney.Patcher]] type class instance
* @since 0.8.0
*/
* for arbitrary types.
*
* @tparam A type of object to apply patch to
* @tparam Patch type of patch object
* @return [[io.scalaland.chimney.Patcher]] type class instance
* @since 0.8.0
*/
implicit inline def derive[A, Patch]: Patcher[A, Patch] = ${ PatcherMacros.derivePatcher[A, Patch] }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import io.scalaland.chimney.internal.compiletime.derivation.transformer.Transfor
private[chimney] trait TransformerCompanionPlatform { this: Transformer.type =>

/** Provides [[io.scalaland.chimney.Transformer]] derived with the default settings.
*
* When transformation can't be derived, it results with compilation error.
*
* @tparam From type of input value
* @tparam To type of output value
* @return [[io.scalaland.chimney.Transformer]] type class instance
* @since 0.8.0
*/
*
* When transformation can't be derived, it results with compilation error.
*
* @tparam From type of input value
* @tparam To type of output value
* @return [[io.scalaland.chimney.Transformer]] type class instance
* @since 0.8.0
*/
inline def derive[From, To]: Transformer[From, To] =
${ TransformerMacros.deriveTotalTransformerWithDefaults[From, To] }

Expand Down
Loading

0 comments on commit 97951f0

Please sign in to comment.