If we have a function $$f(x)=\max_yg(x,y)$$
Then we can find the derivative $d/dx \ f(x)$ by realizing that $$(1): \quad \frac {\partial }{\partial y}g(x,y^*)=0$$ because of the first order condition for maximization.
We can use this by recognizing that $$\frac d {dx}f(x)=\frac d {dx}g(x,y^*(x))=\frac \partial {\partial x}g(x,y^*)+\frac \partial {\partial y}g(x,y^*)\frac {dy^*(x)} {dx}=\frac \partial {\partial x}g(x,y^*)$$ Where the last equality follows because of result $(1)$.
However, my question is, what if $y$ can only take a discrete number of values? such as $0$ or $1$? We can of course say:
$$f'(x)=\begin{cases} g_x(x,0) \quad \text { if } g(x,0) > g(x,1)\\ g_x(x,1) \quad \text { if } g(x,0) < g(x,1) \end{cases}$$
However, I am wondering if there is a kind of "envelope theorem for discrete choice sets", that would allow us to simplify this (especially if the choice set is discrete but large).