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}$. 



A question about "nice" functions
Just a quick counterexample to your last question:


Let $C \subset \mathbb{R}$ be a fat Cantor set that is symmetric w.r.t. $0$ and define
$f(x) = \begin{cases}x,& \text{if }x \in C\\\ -x,& \text{if }x \notin C \end{cases}.$


(More trivial counterexample would be $f(x) = \begin{cases}x,& \text{if }x \notin \mathbb{Q}\\\ 0,& \text{if }x \in \mathbb{Q} \end{cases}$, but changing things in a set of measure zero is not that satisfying.)


**Edit**: Perhaps even more satisfying example would be something like
$f(\sum\_{i=0}^\infty x\_i2^{-i}) = \sum\_{k=0}^\infty (1-x\_{2k})2^{-2k}+\sum\_{k=0}^\infty x\_{2k+1}2^{-2k-1}$ with $x\_i \in \{0,1\}$, i.e. switch every other digit in the binary representation (does not matter what you do at the endpoints of intervals).


