Skip to content

Commit

Permalink
Remove Left/Right/None/Nil implicit schemas (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
vigoo authored Jun 6, 2022
1 parent b471334 commit f3623b3
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 69 deletions.
4 changes: 2 additions & 2 deletions tests/shared/src/test/scala/zio/schema/DefaultValueSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(""))))
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Expand Down
24 changes: 0 additions & 24 deletions zio-schema/shared/src/main/scala/zio/schema/Schema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]] =
Expand All @@ -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")

Expand All @@ -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(_))

Expand Down

0 comments on commit f3623b3

Please sign in to comment.