Continuity and partition of domain Suppose $f:X\to Y$ is a mapping from topological space $X$ to topological space $Y$.
Suppose $P$ is a partition of $X$. Do $f$ continuous over each element of $P$ and $f$ continuous over $X$ imply each other? Do we need $f$ to be continuous over the closure of each element of $P$, instead of just over each element of $P$?
Following is a sketch of the proof:
$f$ continuous over $X$ implies $f$ continuous over each element of $P$, because continuity over a set and continuity at each element of the set are equivalent.
For the same reason, For $f$ continuous over $X$ to imply $f$ continuous over (the closure of) each element of $P$, does it suffice to check if $f$ is continuous at each point at the boundaries of each element of $P$? 
If one doesn't imply the other, what extra conditions are needed for the implication to hold?
Thanks and regards!
 A: Requiring that $f$ be continuous on each element of the partition does not suffice - for example, consider the partition
$$\mathbb{R}=(-\infty,0]\cup (0,\infty)$$
and the function $f:\mathbb{R}\to\mathbb{R}$ defined by 
$$f(x)=\begin{cases}0\text{ if }x\leq 0\\ 1\text{ if }x>0\end{cases}$$
which is continuous on each element of the partition, but not continuous overall.
Nor does requiring that $f$ be continuous on the closure of each element of the partition suffice - for example, 
$$\mathbb{R}=\bigcup_{a\in\mathbb{R}}P_a$$
where $P_a=\{a\}$ is a partition of $\mathbb{R}$, and for every $a\in\mathbb{R}$, $P_a=\overline{P_a}$. Any function $\mathbb{R}\to Y$ is continuous on each $P_a$, but there are many discontinuous functions with $\mathbb{R}$ as domain.

However, it is true that if 
$$X=\bigcup_{\alpha\in A}P_\alpha$$
is an open cover of $X$, i.e. each $P_\alpha$ is an open subset of $X$, then $f:X\to Y$ is continuous if and only if each restriction $f|_{P_\alpha}:P_\alpha\to Y$ is continuous. This is easy to see: suppose that $U\subseteq Y$ is an open subset. If each $f|_{P_\alpha}$ is continuous, then 
$$f|_{P_\alpha}^{-1}(U)=\{x\in P_\alpha\mid f(x)\in U\}=f^{-1}(U)\cap P_\alpha$$ is open in $P_\alpha$ (which has the subspace topology from $X$). Because each $P_\alpha$ is open in $X$, a subset of $P_\alpha$ is open in the subspace topology if and only if it is open as a subset of $X$. Thus, each $f|_{P_\alpha}^{-1}(U)$ is open as a subset of $X$, and hence
$$f^{-1}(U)=f^{-1}(U)\cap X= f^{-1}(U)\cap\left(\bigcup_{\alpha\in A} P_\alpha \right)= \bigcup_{\alpha\in A}f|_{P_\alpha}^{-1}(U)$$
is an open subset of $X$. Thus, $f$ is continuous.
However, it is often the case that an open cover cannot also be a partition. A space is called connected when the only open cover that is also a partition is the trivial open cover, i.e. $\{X\}$. Intuitively, connected means exactly what you'd think - there aren't two "separate pieces". For example, $\mathbb{R}^n$, $\mathbb{S}^n$, and $\mathbb{T}^n$ are all connected, while $(0,1)\cup (2,3)$ is disconnected.
A: Let $f:\mathbb{R}\to\mathbb{R}$ be continuous. Consider any partition of $\mathbb{R}$ and let $P$ be a cell of the partition. Then the function that equals $f+1$ on $P$ and $f$ on every other cell shows tha no partition is sufficient.
The space $\mathbb{R}^2$ partitioned into the lines $\mathbb{R}\times{x}$ for some $x\in\mathbb{R}$, shows that one can even partition a well-behaved space into perfect sets and get a counterexample.
Here is a rather weak positive result: 
Let X be a metric space and consider a partition of $X$ such that each point has a neighborhood that meets only finitely many cells. Let $f$ be a function with values in a metric space that is continuous on the closure of each cell. Then $f$ is continuous.
Proof: Let $(x_n)$ be a sequence converging to a point $x$. Since a neighborhood of $x$ meets only finitely many cells, there is a cell that contains a subsequence of $(x_n)$ and its closure contains $x$. Since $f$ is continuous on the closure of this cell $f(x_n)\to f(x)$. 
