Let $f:\mathbb R \rightarrow \mathbb R$ be a function such that $\lambda(I)=\lambda(f(I))$ for each interval $I \subseteq \mathbb R$. ($\lambda$ is Lebesgue measure here.) Let us call such functions ''nice'' functions.

Can we characterize nice functions?

For example;

$f(x)=x$ is a nice function.

$f(x)=2x$ is not a nice function. More generally if $m \in \mathbb R\setminus\{-1,1\}$ then $f(x)=mx$ is not a nice function.

Every translation is a nice function.

$$f(x)= \begin{cases} x+1; & x \in [-1,0) \newline x-1; & x \in [0,1) \newline x; & \text{elsewhere} \end{cases}$$ is a nice function.

Further, let $\mathcal A$ be the family of nice functions. Is the following conclusion true?

$f \in \mathcal A$ iff there exists a partition $I_{\alpha}$ of $\mathbb R$ into pairwise disjoint intervals such that $f=ax+b_{\alpha}$ on $I_{\alpha}$ for $a=-1$ or $1$ and for suitable $b_{\alpha}$.