Skip to content

Commit f3623b3

Browse files
authored
Remove Left/Right/None/Nil implicit schemas (#279)
1 parent b471334 commit f3623b3

File tree

4 files changed

+3
-69
lines changed

4 files changed

+3
-69
lines changed

tests/shared/src/test/scala/zio/schema/DefaultValueSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,11 @@ object DefaultValueSpec extends ZIOSpecDefault {
245245
assert(eitherSchema.defaultValue)(isRight(isLeft(equalTo(0))))
246246
},
247247
test("left") {
248-
val leftSchema: Schema[Left[Int, Nothing]] = Schema.left(Schema.primitive(StandardType.IntType))
248+
val leftSchema = Schema.either(Schema.primitive(StandardType.IntType), Schema.fail("Nothing"))
249249
assert(leftSchema.defaultValue)(isRight(isLeft(equalTo(0))))
250250
},
251251
test("right") {
252-
val rightSchema: Schema[Right[Nothing, String]] = Schema.right(Schema.primitive(StandardType.StringType))
252+
val rightSchema = Schema.either(Schema.fail("Nothing"), Schema.primitive(StandardType.StringType))
253253
assert(rightSchema.defaultValue)(isRight(isRight(equalTo(""))))
254254
}
255255
)

zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -268,48 +268,6 @@ object JsonCodecSpec extends ZIOSpecDefault {
268268
)
269269
}
270270
},
271-
test("compatible with left/right") {
272-
check(
273-
for {
274-
left <- SchemaGen.anyPrimitiveAndValue
275-
right <- SchemaGen.anyPrimitiveAndValue
276-
} yield (
277-
Schema.either(left._1, right._1),
278-
Schema.left(left._1),
279-
Schema.right(right._1),
280-
Left(left._2),
281-
Right(right._2)
282-
)
283-
) {
284-
case (eitherSchema, leftSchema, rightSchema, leftValue, rightValue) =>
285-
for {
286-
a1 <- assertEncodesThenDecodesWithDifferentSchemas[Either[Any, Any], Left[Any, Nothing]](
287-
eitherSchema.asInstanceOf[Schema[Either[Any, Any]]],
288-
leftSchema.asInstanceOf[Schema[Left[Any, Nothing]]],
289-
leftValue.asInstanceOf[Either[Any, Any]],
290-
(x: Either[Any, Any], y: Left[Any, Nothing]) => x == y
291-
)
292-
a2 <- assertEncodesThenDecodesWithDifferentSchemas(
293-
eitherSchema.asInstanceOf[Schema[Either[Any, Any]]],
294-
rightSchema.asInstanceOf[Schema[Right[Nothing, Any]]],
295-
rightValue,
296-
(x: Either[Any, Any], y: Right[Nothing, Any]) => x == y
297-
)
298-
a3 <- assertEncodesThenDecodesWithDifferentSchemas(
299-
leftSchema.asInstanceOf[Schema[Left[Any, Nothing]]],
300-
eitherSchema.asInstanceOf[Schema[Either[Any, Any]]],
301-
leftValue,
302-
(x: Left[Any, Nothing], y: Either[Any, Any]) => x == y
303-
)
304-
a4 <- assertEncodesThenDecodesWithDifferentSchemas(
305-
rightSchema.asInstanceOf[Schema[Right[Nothing, Any]]],
306-
eitherSchema.asInstanceOf[Schema[Either[Any, Any]]],
307-
rightValue,
308-
(x: Right[Nothing, Any], y: Either[Any, Any]) => x == y
309-
)
310-
} yield a1 && a2 && a3 && a4
311-
}
312-
},
313271
test("Map of complex keys and values") {
314272
assertEncodes(
315273
Schema.map[Key, Value],

zio-schema/shared/src/main/scala/zio/schema/DynamicValue.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,7 @@ private[schema] object DynamicValueSchema { self =>
19811981
private val noneValueCase: Schema.Case[DynamicValue.NoneValue.type, DynamicValue] =
19821982
Schema.Case(
19831983
"NoneValue",
1984-
Schema.none.transform(_ => DynamicValue.NoneValue, _ => None),
1984+
Schema.singleton(None).transform(_ => DynamicValue.NoneValue, _ => None),
19851985
_.asInstanceOf[DynamicValue.NoneValue.type],
19861986
Chunk("case")
19871987
)

zio-schema/shared/src/main/scala/zio/schema/Schema.scala

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,6 @@ object Schema extends TupleSchemas with RecordSchemas with EnumSchemas with Sche
217217
}
218218
)
219219

220-
implicit val nil: Schema[Nil.type] = singleton(Nil)
221-
222-
implicit val none: Schema[None.type] = singleton(None)
223-
224220
implicit val dynamicValue: Schema[DynamicValue] = DynamicValueSchema()
225221

226222
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
235231
implicit def either[A, B](implicit left: Schema[A], right: Schema[B]): Schema[Either[A, B]] =
236232
EitherSchema(left, right)
237233

238-
implicit def left[A](implicit schemaA: Schema[A]): Schema[Left[A, Nothing]] =
239-
either[A, Nothing](schemaA, Schema.fail[Nothing]("no schema for Right"))
240-
.transformOrFail[Left[A, Nothing]](
241-
{
242-
case left @ Left(_) => Right(left)
243-
case Right(_) => Left("cannot encode Right")
244-
},
245-
left => Right(left)
246-
)
247-
248234
implicit def list[A](implicit schemaA: Schema[A]): Schema[List[A]] =
249235
Schema.Sequence[List[A], A, String](schemaA, _.toList, Chunk.fromIterable(_), Chunk.empty, "List")
250236

@@ -257,16 +243,6 @@ object Schema extends TupleSchemas with RecordSchemas with EnumSchemas with Sche
257243
def semiDynamic[A](defaultValue: Either[String, (A, Schema[A])] = Left("no default value")): Schema[(A, Schema[A])] =
258244
Schema.SemiDynamic(defaultValue)
259245

260-
implicit def right[B](implicit schemaB: Schema[B]): Schema[Right[Nothing, B]] =
261-
either[Nothing, B](Schema.fail[Nothing]("no schema for Left"), schemaB)
262-
.transformOrFail[Right[Nothing, B]](
263-
{
264-
case right @ Right(_) => Right(right)
265-
case Left(_) => Left("cannot encode Left")
266-
},
267-
right => Right(right)
268-
)
269-
270246
implicit def vector[A](implicit element: Schema[A]): Schema[Vector[A]] =
271247
chunk(element).transform(_.toVector, Chunk.fromIterable(_))
272248

0 commit comments

Comments
 (0)