In this question it was proved that, if $f:X \to \mathbb{R}$ and $\partial f(x)\neq \emptyset$ for all $x \in X$, then $f$ is convex.
But in the proof we used the fact, that $x = \lambda x_1 + (1 - \lambda) x_2$ exists for all $\lambda \in [0,1]$, that means, set $X$ is also convex.
So my question: let's say that $X$ is not convex, $f:X \to \mathbb{R}$ and $\partial f(x)\neq \emptyset$ for all $x \in X$. Does function $f$ exist? Can you give an example of such a function?
Thank you!