# Connected and Compact preserving function is not continuous example?

Before we start, I'm aware the result is true for when the function is a map between Euclidean spaces. In fact, with a minimal amount of extra work we can see that a function between locally-compact, locally-connected topological spaces which preserves connected and compact subsets is in fact continuous.

My question is for an example of a function which preserves compact and connected subsets but is not continuous. I've found a minimal example with the two point space and the identity function where the Sierpinksi space is the domain and the image space has the discrete topology. Now I want something a little more interesting. Can anyone come up with an example where the domain and codomain are Hausdorff?

-
You might want to see: renyi.hu/~soukup/setop/conti/conti.pdf – Zircht Feb 12 '14 at 0:47

If a function $f:X\to Y$, between any topological spaces, has finite image, then it maps any set in $X$ to a compact set in $Y$, and in particular thus it preserves compactness. Further, if $X$ is totally disconnected, so every connected component is a singleton, then the image of $f$ on any connected set in $X$ is a singleton too, and thus connected in $Y$. So, for such $X$, any function preserves connectivity.
So, you now get a huge class of compactness and connectivity preserving functions $f:X\to Y$ which are not continuous. Simply take $X$ to be totally disconnected (e.g., $X=\mathbb Q$ with the usual topology (so in particular, $X$ is Hausdorff)) and take $Y$ to be arbitrary (e.g., $Y=[0,1]$, so it's Hausdorff). Now just let $f:X\to Y$ attain finitely many values, while not being continuous. There are plenty of such functions.
What if $X$ is connected and $f(X)$ is connected and not constant? I $f$ necessarily continuous? – Gary. Aug 22 '15 at 2:08