diff --git a/modules/core/src/main/scala/playground/QueryCompilerVisitor.scala b/modules/core/src/main/scala/playground/QueryCompilerVisitor.scala index 7edbdf58..e90f09fd 100644 --- a/modules/core/src/main/scala/playground/QueryCompilerVisitor.scala +++ b/modules/core/src/main/scala/playground/QueryCompilerVisitor.scala @@ -54,7 +54,7 @@ import scala.collection.immutable.ListMap object QueryCompilerVisitor { val full: Schema ~> QueryCompiler = - new TransitiveCompiler(AddDynamicRefinements) andThen QueryCompilerVisitorInternal + Schema.transformTransitivelyK(AddDynamicRefinements) andThen QueryCompilerVisitorInternal } object QueryCompilerVisitorInternal extends SchemaVisitor[QueryCompiler] { diff --git a/modules/core/src/main/scala/playground/smithyutil/AddDynamicRefinements.scala b/modules/core/src/main/scala/playground/smithyutil/AddDynamicRefinements.scala index dd922977..7f4efecf 100644 --- a/modules/core/src/main/scala/playground/smithyutil/AddDynamicRefinements.scala +++ b/modules/core/src/main/scala/playground/smithyutil/AddDynamicRefinements.scala @@ -14,7 +14,7 @@ import smithy4s.~> /** Reifies refinement hints into the schema. * * Notably, this does NOT recurse! In order to traverse an entire schema recursively, this has to - * be wrapped in TransitiveCompiler. This is done for separation of concerns. + * be wrapped in transformTransitivelyK. This is done for separation of concerns. */ object AddDynamicRefinements extends (Schema ~> Schema) { diff --git a/modules/core/src/main/scala/playground/smithyutil/TransitiveCompiler.scala b/modules/core/src/main/scala/playground/smithyutil/TransitiveCompiler.scala deleted file mode 100644 index f61baf0f..00000000 --- a/modules/core/src/main/scala/playground/smithyutil/TransitiveCompiler.scala +++ /dev/null @@ -1,48 +0,0 @@ -package playground.smithyutil - -import smithy4s.schema.Alt -import smithy4s.schema.Field -import smithy4s.schema.Schema -import smithy4s.schema.Schema.BijectionSchema -import smithy4s.schema.Schema.CollectionSchema -import smithy4s.schema.Schema.EnumerationSchema -import smithy4s.schema.Schema.LazySchema -import smithy4s.schema.Schema.MapSchema -import smithy4s.schema.Schema.OptionSchema -import smithy4s.schema.Schema.PrimitiveSchema -import smithy4s.schema.Schema.RefinementSchema -import smithy4s.schema.Schema.StructSchema -import smithy4s.schema.Schema.UnionSchema -import smithy4s.~> - -/** Applies the underlying transformation on each node of the schema. */ -final class TransitiveCompiler( - underlying: Schema ~> Schema -) extends (Schema ~> Schema) { - - def apply[A]( - fa: Schema[A] - ): Schema[A] = - fa match { - case e @ EnumerationSchema(_, _, _, _, _) => underlying(e) - case p @ PrimitiveSchema(_, _, _) => underlying(p) - case u @ UnionSchema(_, _, _, _) => - underlying(u.copy(alternatives = u.alternatives.map(handleAlt(_)))) - case BijectionSchema(s, bijection) => underlying(BijectionSchema(this(s), bijection)) - case LazySchema(suspend) => underlying(LazySchema(suspend.map(this.apply))) - case RefinementSchema(s, refinement) => underlying(RefinementSchema(this(s), refinement)) - case c @ CollectionSchema(_, _, _, _) => underlying(c.copy(member = this(c.member))) - case m @ MapSchema(_, _, _, _) => underlying(m.copy(key = this(m.key), value = this(m.value))) - case s @ StructSchema(_, _, _, _) => underlying(s.copy(fields = s.fields.map(handleField(_)))) - case n @ OptionSchema(_) => underlying(n.copy(underlying = this(n.underlying))) - } - - private def handleField[S, A]( - field: Field[S, A] - ): Field[S, A] = field.copy(schema = this(field.schema)) - - private def handleAlt[S, A]( - alt: Alt[S, A] - ): Alt[S, A] = alt.copy(schema = this(alt.schema)) - -}