Proof that the union of connected sets where the intersection of the closure of one with the other is non-empty. The problem says:
Prove that if $(X,d)$ is a metric space and $A, B$ are connected subsets of $ X$, then if $cl(A)\cap B\neq\emptyset$, $A\cup B$ is connected.
To show this, I supposed the contrary, that $A\cup B$ is disconnected and thus, $A\cup B=C\cup D$, with $cl(C)\cap D=\emptyset$ and $cl(D)\cap C=\emptyset$.
Then I can define the function:
$$f:C\cup D\to \{0,1\}$$
$$f(x)=\begin{cases}0 ,& x\in C, \\ 1,& x\in D.\end{cases}$$
Which is continuous and not constant.
If $x\in C$, then $x\in A$ or $x\in B$. WLOG, suppose it's in $A$, then because $f$ is continuous, the image of connected sets is connected and thus, $f(a)=f(x), \forall a\in A$.
Because,$cl(A)\cap B\neq\emptyset$, if $x\in cl(A)\cap B$ there is a sequence $\{x_n\}$ of points in $A$ such that:
$$lim_{n\to\infty}x_n=x$$
And, because $f$ is continuous,
$$lim_{n\to\infty}f(x_n)=f(x)$$
And because each $x_n\in A$, we can conclude that $f(x)=1$. But because $x\in B$, we can alsio conclude that $f(b)=1\forall b\in B$. But then, $f$ is constant, which is a contradiction.
Is this correct, or am I missing something? I feel that when I use the function, I made a leap of logic by regarding $C\cup D$ as a metric space.
 A: It’s correct. In particular, $C\cup D$ is a metric space with the metric that it inherits from $X$. However, the result is true for arbitrary topological spaces, though part of the proof has to be changed slightly. If $x\in B\cap\operatorname{cl}A$, there need not be a sequence in $A$ converging to $x$ if $X$ is not metric, but suppose that $f(x)=0$: then $f^{-1}\left[\left(-\frac12,\frac12\right)\right]$ is an open nbhd of $x$ disjoint from $A$, which is impossible. Thus, $f(x)=1$, and rest of your argument goes through unchanged.
A: The usual topological def'n is that $f:P\to Q$ is continuous iff $f^{-1}E$ is open in $P$ whenever $E$ is open in $Q.$ There are many consequences of continuity that also imply continuity; Any of them can be used as an equivalent def'n. Some of them are better suited to some problems than others. Some equivalents involving closures are
(i). $f:P\to Q$ is continuous iff $f^{-1}E$ is closed in $P$ whenever $E$ is closed in $Q.$
(ii). $f: P\to Q$ is continuous iff $f[Cl_P(A)]\subseteq Cl_Q(f[A])$ whenever $A\subseteq P.$
(ii'). $f:P\to Q$ is continuous iff $f(b)\in Cl_Q(f[A])$ whenever $A\subseteq P$ and $b\in Cl_P(A).$
Number (ii') generalizes the notion that if $(h_n)_n$ is a sequence in $P$ converging to  $h$ then $(f(h_n))_n$ ought to converge to $f(h)$ for continuity of $f.$
To your problem: Let $A\cup B=P$ and $\{0,1\}=Q.$ Let $f:P\to Q$ be continuous. Then each of $f|_A$ and $f|_B$ is continuous, and hence each is constant because $A$ and $B$ are each connected.
And $A$ is not empty because there exists $b\in B\cap Cl_X\subseteq Cl_X(A).$ So WLOG $f[A]=\{1\}.$
Now take  $b\in B\cap Cl_X(A).$ We have $b\in Cl_P(A)$ because $b\in B\cap Cl_X(A)\subseteq (A\cup B)\cap Cl_X(A)=P\cap Cl_X(A)=Cl_P(A).$
So by (ii') we have $f(b)\in Cl_Q(f[A])=f[A]=\{1\}.$ So $f(b)=1,$ with $b\in B,$ and $f$ is constant on $B$.
So $f[B]=\{1\}=f[A].$
