"""Union of two types.Type `Either[L, R]` represents a value of either typr `L` ("left") or `R` ("right")."""fromtypingimportGeneric,no_type_checkfromguppylang_internals.decoratorimportcustom_function,custom_typefromguppylang_internals.std._internal.compiler.eitherimport(EitherConstructor,EitherTestCompiler,EitherToOptionCompiler,EitherUnwrapCompiler,either_to_hugr,)fromguppylang_internals.tys.paramimportTypeParamfromguppylangimportguppyfromguppylang.std.builtinsimportownedfromguppylang.std.optionimportOptionL=guppy.type_var("L",copyable=False,droppable=False)R=guppy.type_var("R",copyable=False,droppable=False)Droppable=guppy.type_var("Droppable",copyable=False,droppable=True)_params=[TypeParam(0,"L",False,False),TypeParam(1,"L",False,False)]
[docs]@custom_type(either_to_hugr,params=_params)classEither(Generic[L,R]):# type: ignore[misc]"""Represents a union of either a `left` or a `right` value."""
[docs]@custom_function(EitherTestCompiler(0))@no_type_checkdefis_left(self:"Either[L, R]")->bool:"""Returns `True` for a `left` value."""
[docs]@custom_function(EitherTestCompiler(1))@no_type_checkdefis_right(self:"Either[L, R]")->bool:"""Returns `True` for a `right` value."""
[docs]@custom_function(EitherToOptionCompiler(0))@no_type_checkdeftry_into_left(self:"Either[L, Droppable]"@owned)->Option[L]:"""Returns the wrapped value if `self` is a `left` value, or `nothing` otherwise. This operation is only allowed if the `right` variant wraps a droppable type. """
[docs]@custom_function(EitherToOptionCompiler(1))@no_type_checkdeftry_into_right(self:"Either[Droppable, R]"@owned)->Option[R]:"""Returns the wrapped value if `self` is a `right` value, or `nothing` otherwise. This operation is only allowed if the `left` variant wraps a droppable type. """
[docs]@custom_function(EitherUnwrapCompiler(0))@no_type_checkdefunwrap_left(self:"Either[L, R]"@owned)->L:"""Returns the contained `left` value, consuming `self`. Panics if `self` is a `right` value. """
[docs]@custom_function(EitherUnwrapCompiler(1))@no_type_checkdefunwrap_right(self:"Either[L, R]"@owned)->R:"""Returns the contained `right` value, consuming `self`. Panics if `self` is a `left` value. """
[docs]@custom_function(EitherConstructor(0))@no_type_checkdefleft(val:L@owned)->Either[L,R]:"""Constructs a `left` either value."""
[docs]@custom_function(EitherConstructor(1))@no_type_checkdefright(val:R@owned)->Either[L,R]:"""Constructs a `right` either value."""