Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jdegoes authored Mar 19, 2024
2 parents 56eec2d + df41083 commit eee5d3d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions zio-schema/shared/src/main/scala-3/zio/schema/package.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
package zio

import scala.reflect.ClassTag

package object schema {
type Singleton = scala.Singleton

extension [A: ClassTag, B: ClassTag] (s: Schema.Fallback[A, B])
def merge: Schema[A | B] =
s.transform(_.merge, {
case left: A => Fallback.Left(left.asInstanceOf[A])
case right: B => Fallback.Right(right.asInstanceOf[B])
})

extension [A: ClassTag] (s: Schema[A])
def orElse[B: ClassTag](s0: Schema[B]): Schema[A | B] =
Schema.Fallback(s, s0).merge

extension [A: ClassTag, B: ClassTag] (fallback: Fallback[A, B])
def merge: A | B =
fallback match {
case Fallback.Left(left) => left
case Fallback.Right(right) => right
case Fallback.Both(left, _) => left
}

}

0 comments on commit eee5d3d

Please sign in to comment.