Say I have a set $\mathcal{X}$ and a partition $A := (A_{1}, \dots, A_{M})$, i.e. subsets such that $\dot{\cup}_{i=1}^M A_{i} = \mathcal{X}$ and the $A_{i}$s are pairwise disjoint. Say further I have a function $f: \mathcal{X} \to \mathcal{Y}$ that is piecewise constant on the cells of $A$, i.e.
$$ f (x) = \begin{cases} f_{1} & x \in A_{1} \\ \dots \\ f_{M} & x \in A_{M} \end{cases} $$
Consider now a random variable $X$ that is evenly distributed on $\mathcal{X}$, i.e. its probability density function is $p(x) = \varphi ~ ,\forall x$.
I am interested in expressing the expectation of $f(x)$ over $\mathcal{X}$ in terms of the function values $f_{1}, \dots, f_{m}$ at the cells of the partition.
Here's what I have so far but I am not sure it's correct. Mostly, I am unsure whether, in the last line, the individual summands should be having a weight factor that corresponds to the sizes of the cells. $$ \begin{align} \mathbb{E}_{X}\left[ f(X) \right] &= \int f(x) \varphi \, dx \\ &= \int_{A_{1}} f_{1} \varphi \, dx ~ ~ + \dots + \int_{A_{M}} f_{M}\varphi \, dx \end{align} $$ Now let $X_{|i}$ be a random variable that has pdf of $X$ in cell $A_{i}$ and $0$ everywhere else. Then $$ \begin{align} \dots &= \mathbb{E}_{X_{|1}}\left[ f_{1} \right] ~ ~ + \dots + \mathbb{E}_{X_{|M}}\left[ f_{M} \right] \end{align} $$ and, since the expectation over a constant is just that constant, we'd have $$ \begin{align} \dots &= f_{1} + \dots + f_{M} \end{align} $$ This seems weird since the expectation $\mathbb{E}_{X}\left[ f(X) \right]$ would then be the sum of the individual values whereas intuitively I'd expect it to be more like a weighted mean.