Is there a discontinuous function such that it is continuous on each restriction? 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?
 A: 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.)
A: Take an enumeration $q_n$ of $\mathbb{Q}$, and define $A_n:=\{q_1,\cdots, q_n\}$. Define $f:\mathbb{Q} \to \mathbb{R}$ by $f(x)=1$ if $x \neq 0$, and $f(x)=0$ if $x=0$. 
A: Take
$$f(x)=
\begin{cases}
1, &\text{ if }x>0\\
0,  &\text{ if }x\le 0\\
\end{cases}
$$
Then take $A_n=(-\infty,0]\cup (1/n,\infty)$
$A_n\subset A_{n+1}$, $\bigcup_{n=1}^{\infty}A_n=\mathbb R$, $f$ is continuous on $A_n$, but $f$ is not continuous on $\mathbb R$
