Let $(E,\mathcal{E})$ be a measurable space, and let a positive function $f:E \rightarrow \mathbb{R}$ be defined as
\begin{align} f=\sum_{n=1}^{\infty}a_n\mathbb{I}_{A_n} \end{align}
with $(a_n)_{n=1}^{\infty}\subset\mathbb{R}$ and $(A_n)_{n=1}^{\infty}\subset\mathcal{E}$. Is it $\mathcal{E}$-measurable?
My attempt
Probably the statement can be proved differently, but in my book (by Cinlar) this exercise follows right after another one that asks to prove the same result when the $(A_n)_{n=1}^{\infty}$ are disjointed. So I think it would be nice to express $f$ in canonical form and then leverage on the result from the previous exercise. Since $f$ takes on at most countably many distinct values $b_n \in \mathbb{R}$, it is straightforward to define
\begin{align} B_m=\{ x \in E : f(x)=b_m \}, \quad m \geq 1 \end{align}
so that
\begin{align} f=\sum_{n=1}^{\infty}a_n\mathbb{I}_{A_n}=\sum_{m=1}^{\infty}b_m\mathbb{I}_{B_m} \end{align}
Now, once I prove that $(B_m)_{m=1}^{\infty} \subset \mathcal{E}$, I can claim that $f$ is $\mathcal{E}$-measurable because it is constant on each member of a measurable partition of $E$ (I guess this holds even if $(B_m)_{m=1}^{\infty}$ is not a partition of $E$ as it can be enriched with $B_0=E\setminus (\bigcup_{m=1}^{\infty}B_m)$).
The point is: how to prove that $B_m$ is an $\mathcal{E}$-measurable set for each $m \geq 1$?