SmartPy has the ability to limit any simple type's values to a finite subset. The type of bounded values is
sp.TBounded(cases, t=None, final=True)
Introduce a finite subset of a simple type whose cases are
cases (they must be of the same simple type), whose optional type is
t (otherwise, it is inferred). The optional boolean parameter
final determines whether the type acts as a constraint that can be extended (
final=False) or not.
Introduce a bounded value where
x is supposed to be a literal of a simple type.
Forget the bounded structure of a
sp.TBounded(_, t) and return an expression of type
For example, the type
sp.TBounded(["red", "green", "blue"]) has exactly three values:
sp.unbounded expects a bounded value and returns its unbounded equivalent, e.g. it goes from
sp.bounded("red") to just "red" (of type sp.TString).
Note that bounded types can be based on any simple type, e.g.
sp.TBounded([1,2,3]) possible as well.
There is no cost associated to bounded types and values when compiling to Michelson.