From f3623b36c6adb9be62b7b2c8fac7fde218f3491a Mon Sep 17 00:00:00 2001 From: Daniel Vigovszky Date: Mon, 6 Jun 2022 09:19:31 +0100 Subject: [PATCH] Remove Left/Right/None/Nil implicit schemas (#279) --- .../scala/zio/schema/DefaultValueSpec.scala | 4 +- .../zio/schema/codec/JsonCodecSpec.scala | 42 ------------------- .../main/scala/zio/schema/DynamicValue.scala | 2 +- .../src/main/scala/zio/schema/Schema.scala | 24 ----------- 4 files changed, 3 insertions(+), 69 deletions(-) diff --git a/tests/shared/src/test/scala/zio/schema/DefaultValueSpec.scala b/tests/shared/src/test/scala/zio/schema/DefaultValueSpec.scala index e11178dd5..b0ed8e646 100644 --- a/tests/shared/src/test/scala/zio/schema/DefaultValueSpec.scala +++ b/tests/shared/src/test/scala/zio/schema/DefaultValueSpec.scala @@ -245,11 +245,11 @@ object DefaultValueSpec extends ZIOSpecDefault { assert(eitherSchema.defaultValue)(isRight(isLeft(equalTo(0)))) }, test("left") { - val leftSchema: Schema[Left[Int, Nothing]] = Schema.left(Schema.primitive(StandardType.IntType)) + val leftSchema = Schema.either(Schema.primitive(StandardType.IntType), Schema.fail("Nothing")) assert(leftSchema.defaultValue)(isRight(isLeft(equalTo(0)))) }, test("right") { - val rightSchema: Schema[Right[Nothing, String]] = Schema.right(Schema.primitive(StandardType.StringType)) + val rightSchema = Schema.either(Schema.fail("Nothing"), Schema.primitive(StandardType.StringType)) assert(rightSchema.defaultValue)(isRight(isRight(equalTo("")))) } ) diff --git a/zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala b/zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala index 56cc0319c..8dac87f96 100644 --- a/zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala +++ b/zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala @@ -268,48 +268,6 @@ object JsonCodecSpec extends ZIOSpecDefault { ) } }, - test("compatible with left/right") { - check( - for { - left <- SchemaGen.anyPrimitiveAndValue - right <- SchemaGen.anyPrimitiveAndValue - } yield ( - Schema.either(left._1, right._1), - Schema.left(left._1), - Schema.right(right._1), - Left(left._2), - Right(right._2) - ) - ) { - case (eitherSchema, leftSchema, rightSchema, leftValue, rightValue) => - for { - a1 <- assertEncodesThenDecodesWithDifferentSchemas[Either[Any, Any], Left[Any, Nothing]]( - eitherSchema.asInstanceOf[Schema[Either[Any, Any]]], - leftSchema.asInstanceOf[Schema[Left[Any, Nothing]]], - leftValue.asInstanceOf[Either[Any, Any]], - (x: Either[Any, Any], y: Left[Any, Nothing]) => x == y - ) - a2 <- assertEncodesThenDecodesWithDifferentSchemas( - eitherSchema.asInstanceOf[Schema[Either[Any, Any]]], - rightSchema.asInstanceOf[Schema[Right[Nothing, Any]]], - rightValue, - (x: Either[Any, Any], y: Right[Nothing, Any]) => x == y - ) - a3 <- assertEncodesThenDecodesWithDifferentSchemas( - leftSchema.asInstanceOf[Schema[Left[Any, Nothing]]], - eitherSchema.asInstanceOf[Schema[Either[Any, Any]]], - leftValue, - (x: Left[Any, Nothing], y: Either[Any, Any]) => x == y - ) - a4 <- assertEncodesThenDecodesWithDifferentSchemas( - rightSchema.asInstanceOf[Schema[Right[Nothing, Any]]], - eitherSchema.asInstanceOf[Schema[Either[Any, Any]]], - rightValue, - (x: Right[Nothing, Any], y: Either[Any, Any]) => x == y - ) - } yield a1 && a2 && a3 && a4 - } - }, test("Map of complex keys and values") { assertEncodes( Schema.map[Key, Value], diff --git a/zio-schema/shared/src/main/scala/zio/schema/DynamicValue.scala b/zio-schema/shared/src/main/scala/zio/schema/DynamicValue.scala index 286f2ff42..d0319945e 100644 --- a/zio-schema/shared/src/main/scala/zio/schema/DynamicValue.scala +++ b/zio-schema/shared/src/main/scala/zio/schema/DynamicValue.scala @@ -1981,7 +1981,7 @@ private[schema] object DynamicValueSchema { self => private val noneValueCase: Schema.Case[DynamicValue.NoneValue.type, DynamicValue] = Schema.Case( "NoneValue", - Schema.none.transform(_ => DynamicValue.NoneValue, _ => None), + Schema.singleton(None).transform(_ => DynamicValue.NoneValue, _ => None), _.asInstanceOf[DynamicValue.NoneValue.type], Chunk("case") ) diff --git a/zio-schema/shared/src/main/scala/zio/schema/Schema.scala b/zio-schema/shared/src/main/scala/zio/schema/Schema.scala index 80ea45d66..3976b4a5c 100644 --- a/zio-schema/shared/src/main/scala/zio/schema/Schema.scala +++ b/zio-schema/shared/src/main/scala/zio/schema/Schema.scala @@ -217,10 +217,6 @@ object Schema extends TupleSchemas with RecordSchemas with EnumSchemas with Sche } ) - implicit val nil: Schema[Nil.type] = singleton(Nil) - - implicit val none: Schema[None.type] = singleton(None) - implicit val dynamicValue: Schema[DynamicValue] = DynamicValueSchema() implicit def chunk[A](implicit schemaA: Schema[A]): Schema[Chunk[A]] = @@ -235,16 +231,6 @@ object Schema extends TupleSchemas with RecordSchemas with EnumSchemas with Sche implicit def either[A, B](implicit left: Schema[A], right: Schema[B]): Schema[Either[A, B]] = EitherSchema(left, right) - implicit def left[A](implicit schemaA: Schema[A]): Schema[Left[A, Nothing]] = - either[A, Nothing](schemaA, Schema.fail[Nothing]("no schema for Right")) - .transformOrFail[Left[A, Nothing]]( - { - case left @ Left(_) => Right(left) - case Right(_) => Left("cannot encode Right") - }, - left => Right(left) - ) - implicit def list[A](implicit schemaA: Schema[A]): Schema[List[A]] = Schema.Sequence[List[A], A, String](schemaA, _.toList, Chunk.fromIterable(_), Chunk.empty, "List") @@ -257,16 +243,6 @@ object Schema extends TupleSchemas with RecordSchemas with EnumSchemas with Sche def semiDynamic[A](defaultValue: Either[String, (A, Schema[A])] = Left("no default value")): Schema[(A, Schema[A])] = Schema.SemiDynamic(defaultValue) - implicit def right[B](implicit schemaB: Schema[B]): Schema[Right[Nothing, B]] = - either[Nothing, B](Schema.fail[Nothing]("no schema for Left"), schemaB) - .transformOrFail[Right[Nothing, B]]( - { - case right @ Right(_) => Right(right) - case Left(_) => Left("cannot encode Left") - }, - right => Right(right) - ) - implicit def vector[A](implicit element: Schema[A]): Schema[Vector[A]] = chunk(element).transform(_.toVector, Chunk.fromIterable(_))