Skip to content

Commit

Permalink
correct implementation of empty for Sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
juliano committed Sep 17, 2024
1 parent 3abbd4e commit 64050bd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1054,15 +1054,15 @@ object JsonCodecSpec extends ZIOSpecDefault {
suite("Missing collection fields")(
test("map") {
assertDecodes(
Schema[ListAndMap],
ListAndMap(Nil, Map.empty),
Schema[ListAndMapAndOption],
ListAndMapAndOption(Nil, Map.empty, None),
charSequenceToByteChunk("""{"list":[]}""")
)
},
test("list") {
assertDecodes(
Schema[ListAndMap],
ListAndMap(Nil, Map.empty),
Schema[ListAndMapAndOption],
ListAndMapAndOption(Nil, Map.empty, None),
charSequenceToByteChunk("""{"map":{}}""")
)
},
Expand All @@ -1072,6 +1072,20 @@ object JsonCodecSpec extends ZIOSpecDefault {
SetWrapper(Set.empty),
charSequenceToByteChunk("""{}""")
)
},
test("vector") {
assertDecodes(
Schema[VectorWrapper],
VectorWrapper(Vector.empty),
charSequenceToByteChunk("""{}""")
)
},
test("chunck") {
assertDecodes(
Schema[ChunckWrapper],
ChunckWrapper(Chunk.empty),
charSequenceToByteChunk("""{}""")
)
}
),
suite("zio.json.ast.Json decoding")(
Expand Down Expand Up @@ -2201,6 +2215,18 @@ object JsonCodecSpec extends ZIOSpecDefault {
implicit lazy val schema: Schema[SetWrapper] = DeriveSchema.gen[SetWrapper]
}

final case class VectorWrapper(sequence: Vector[String])

object VectorWrapper {
implicit lazy val schema: Schema[VectorWrapper] = DeriveSchema.gen[VectorWrapper]
}

final case class ChunckWrapper(chunk: Chunk[String])

object ChunckWrapper {
implicit lazy val schema: Schema[ChunckWrapper] = DeriveSchema.gen[ChunckWrapper]
}

final case class KeyWrapper(key: String)

object KeyWrapper {
Expand Down
2 changes: 1 addition & 1 deletion zio-schema/shared/src/main/scala/zio/schema/Schema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ object Schema extends SchemaPlatformSpecific with SchemaEquality {

override def toString: String = s"Sequence($elementSchema, $identity)"

override def empty: Col = Seq.empty[Elem].asInstanceOf[Col]
override def empty: Col = fromChunk(Chunk.empty[Elem])
}

final case class Transform[A, B, I](
Expand Down

0 comments on commit 64050bd

Please sign in to comment.