TITLE: Is there a discontinuous function such that it is continuous on each restriction?
QUESTION [12 upvotes]: Let $X$ be a topological space such that $X=\bigcup_{n\ge 1}A_n$ with $A_n\subset A_{n+1}$ for each $n\ge 1$. 
Is there a discontinuous function $f:X\to Y$ (where $Y$ is another topological space) such that $\left.f\right|_{A_n}$ is continuous for each $n\ge 1$?
Intuitively I believe this is impossible, but my intuition is always on "nice" spaces. So, if the above is true, I will probably need to work with weird spaces. Can you help me think of some?

REPLY [8 votes]: Take a countable topological space $A=(B,\tau)$ whose finite subspaces are discrete but which is not itself discrete, e.g. $\mathbb{Q}$ with its usual topology. Take an enumeration of $B$, call it $b_n$, and set $B_n=\{ b_1,\dots,b_n \}$. Then any function from $A$ into any topological space is continuous on each $B_n$. But since $A$ is not discrete, there is a topological space $C$ and a function $f : A \to C$ such that $f$ is not continuous. (Concretely, one may take $C$ to be the Sierpinski space and $f$ to be the indicator function of a singleton which is not open.)